Skip to content

Commit

Permalink
Adding disabled? method
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-bodnaruk committed Dec 27, 2022
1 parent c4f6b49 commit e2a2d6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/unleash/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ def is_enabled?(feature, context = nil, default_value_param = false, &fallback_b
toggle.is_enabled?(context)
end

def is_disabled?(feature, context = nil, default_value_param = false, &fallback_blk)
!is_enabled?(feature, context, default_value_param, &fallback_blk)
end

# enabled? is a more ruby idiomatic method name than is_enabled?
alias enabled? is_enabled?
alias disabled? is_disabled?

# execute a code block (passed as a parameter), if is_enabled? is true.
def if_enabled(feature, context = nil, default_value = false, &blk)
Expand Down
3 changes: 3 additions & 0 deletions spec/unleash/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@
expect(
unleash_client.is_enabled?('toggleName', {}, true)
).to eq(true)
expect(
unleash_client.is_disabled?('toggleName', {}, true)
).to eq(false)

expect(WebMock).not_to have_requested(:get, 'http://test-url/')
expect(WebMock).to have_requested(:post, 'http://test-url/client/register')
Expand Down

0 comments on commit e2a2d6f

Please sign in to comment.