Class: Flag::Feature

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Feature

Returns a new instance of Feature.



82
83
84
85
# File 'lib/flag.rb', line 82

def initialize(name)
  @name = name
  @members = Members.new(name)
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



79
80
81
# File 'lib/flag.rb', line 79

def active
  @active
end

#nameObject (readonly)

Returns the value of attribute name.



80
81
82
# File 'lib/flag.rb', line 80

def name
  @name
end

Instance Method Details

#activatedObject



95
96
97
# File 'lib/flag.rb', line 95

def activated
  @members.activated
end

#keyObject



91
92
93
# File 'lib/flag.rb', line 91

def key
  @members.key
end

#off!Object



115
116
117
# File 'lib/flag.rb', line 115

def off!
  @members << "0%"
end

#off?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/flag.rb', line 99

def off?
  !active?
end

#on!(what = "100%") ⇒ Object



119
120
121
# File 'lib/flag.rb', line 119

def on!(what = "100%")
  @members << what
end

#on?(what = false) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
107
108
109
110
111
112
113
# File 'lib/flag.rb', line 103

def on?(what = false)
  return active? if !what
  return true    if @members.include?(what)

  case what
  when Integer, Fixnum, String
    @members.groups.any? { |g| Flag.group[g].call(what) }
  else
    false
  end
end

#resetObject



87
88
89
# File 'lib/flag.rb', line 87

def reset
  @members.reset
end