Class: Flop::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/flop/feature.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, repo = Flop.repo) ⇒ Feature



5
6
7
8
# File 'lib/flop/feature.rb', line 5

def initialize(name, repo = Flop.repo)
  self.name = name.to_sym
  self.repo = repo
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/flop/feature.rb', line 3

def name
  @name
end

#repoObject

Returns the value of attribute repo.



3
4
5
# File 'lib/flop/feature.rb', line 3

def repo
  @repo
end

Instance Method Details

#activateObject



23
24
25
# File 'lib/flop/feature.rb', line 23

def activate
  set true
end

#active?Boolean



10
11
12
# File 'lib/flop/feature.rb', line 10

def active?
  repo.get(name)
end

#deactivateObject



27
28
29
# File 'lib/flop/feature.rb', line 27

def deactivate
  set false
end

#inactive?Boolean



14
15
16
# File 'lib/flop/feature.rb', line 14

def inactive?
  !active?
end

#set(value) ⇒ Object



18
19
20
21
# File 'lib/flop/feature.rb', line 18

def set(value)
  repo.set(name, value)
  value
end

#toggleObject



31
32
33
# File 'lib/flop/feature.rb', line 31

def toggle
  set !active?
end

#with {|block| ... } ⇒ Object

Yields:

  • (block)


35
36
37
# File 'lib/flop/feature.rb', line 35

def with(&block)
  yield block if active?
end

#without {|block| ... } ⇒ Object

Yields:

  • (block)


39
40
41
# File 'lib/flop/feature.rb', line 39

def without(&block)
  yield block if inactive?
end