Class: Togls::Toggler

Inherits:
Object
  • Object
show all
Defined in:
lib/togls/toggler.rb

Instance Method Summary collapse

Constructor Details

#initialize(toggle_repository, toggle) ⇒ Toggler

Returns a new instance of Toggler.



3
4
5
6
# File 'lib/togls/toggler.rb', line 3

def initialize(toggle_repository, toggle)
  @toggle_repository = toggle_repository
  @toggle = toggle
end

Instance Method Details

#offObject



17
18
19
20
21
22
# File 'lib/togls/toggler.rb', line 17

def off
  rule = Togls::Rules::Boolean.new(false)
  @toggle.rule = rule
  @toggle_repository.store(@toggle)
  @toggle
end

#on(rule = nil) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/togls/toggler.rb', line 8

def on(rule = nil)
  if rule.nil?
    rule = Togls::Rules::Boolean.new(true)
  end
  @toggle.rule = rule
  @toggle_repository.store(@toggle)
  @toggle
end