Class: Sapling::Feature
- Inherits:
-
Object
- Object
- Sapling::Feature
- Defined in:
- lib/sapling/feature.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#percentage ⇒ Object
Returns the value of attribute percentage.
-
#users ⇒ Object
Returns the value of attribute users.
Instance Method Summary collapse
- #activate_percentage(percentage) ⇒ Object
- #activate_user(user) ⇒ Object
-
#active?(options = {}) ⇒ Boolean
see Sapling::API::Client.
- #deactivate_percentage ⇒ Object
- #deactivate_user(user) ⇒ Object
- #individually_active?(user) ⇒ Boolean
-
#initialize(name = nil, options = {}) ⇒ Feature
constructor
options :users => array or hash users can be an array of user-ids or hash of user_ids mapped to true :percentage =>.
- #percentage_active?(options = {}) ⇒ Boolean
-
#to_s ⇒ Object
the Feature reports its name with “to_s”.
Constructor Details
#initialize(name = nil, options = {}) ⇒ Feature
options
:users => array or hash
users can be an array of user-ids or hash of user_ids mapped to true
:percentage =>
18 19 20 21 22 23 |
# File 'lib/sapling/feature.rb', line 18 def initialize(name=nil,={}) @name = name @users = [:users] || {} normalize_users self.percentage = [:percentage] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/sapling/feature.rb', line 3 def name @name end |
#percentage ⇒ Object
Returns the value of attribute percentage.
3 4 5 |
# File 'lib/sapling/feature.rb', line 3 def percentage @percentage end |
#users ⇒ Object
Returns the value of attribute users.
3 4 5 |
# File 'lib/sapling/feature.rb', line 3 def users @users end |
Instance Method Details
#activate_percentage(percentage) ⇒ Object
50 51 52 |
# File 'lib/sapling/feature.rb', line 50 def activate_percentage(percentage) @percentage=percentage end |
#activate_user(user) ⇒ Object
42 43 44 |
# File 'lib/sapling/feature.rb', line 42 def activate_user(user) users[user.id]=true end |
#active?(options = {}) ⇒ Boolean
see Sapling::API::Client
29 30 31 32 |
# File 'lib/sapling/feature.rb', line 29 def active?(={}) = Util.() individually_active?([:user]) || percentage_active?() end |
#deactivate_percentage ⇒ Object
54 55 56 |
# File 'lib/sapling/feature.rb', line 54 def deactivate_percentage @percentage=0 end |
#deactivate_user(user) ⇒ Object
46 47 48 |
# File 'lib/sapling/feature.rb', line 46 def deactivate_user(user) users.delete(user.id) end |
#individually_active?(user) ⇒ Boolean
38 39 40 |
# File 'lib/sapling/feature.rb', line 38 def individually_active?(user) user && users[user.id] end |
#percentage_active?(options = {}) ⇒ Boolean
34 35 36 |
# File 'lib/sapling/feature.rb', line 34 def percentage_active?(={}) percentage && (Util.modded_context_id()) < percentage end |
#to_s ⇒ Object
the Feature reports its name with “to_s”
26 |
# File 'lib/sapling/feature.rb', line 26 def to_s; name.to_s; end |