Class: Rollout::Feature
- Inherits:
-
Object
- Object
- Rollout::Feature
- Defined in:
- lib/rollout/feature.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#percentage ⇒ Object
Returns the value of attribute percentage.
-
#users ⇒ Object
Returns the value of attribute users.
Instance Method Summary collapse
- #active?(user) ⇒ Boolean
- #add_group(group) ⇒ Object
- #add_user(user) ⇒ Object
- #clear ⇒ Object
- #deep_clone ⇒ Object
-
#initialize(state:, rollout:, options: {}, name: nil) ⇒ Feature
constructor
A new instance of Feature.
- #remove_group(group) ⇒ Object
- #remove_user(user) ⇒ Object
- #to_feature_state ⇒ Object
- #to_hash ⇒ Object
- #user_in_active_users?(user) ⇒ Boolean
Constructor Details
#initialize(state:, rollout:, options: {}, name: nil) ⇒ Feature
Returns a new instance of Feature.
10 11 12 13 14 15 |
# File 'lib/rollout/feature.rb', line 10 def initialize(state:, rollout:, options: {}, name: nil) @rollout = rollout = @name = name.nil? ? state.name.to_sym : name assign_state(state) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/rollout/feature.rb', line 7 def data @data end |
#groups ⇒ Object
Returns the value of attribute groups.
7 8 9 |
# File 'lib/rollout/feature.rb', line 7 def groups @groups end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/rollout/feature.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/rollout/feature.rb', line 8 def end |
#percentage ⇒ Object
Returns the value of attribute percentage.
7 8 9 |
# File 'lib/rollout/feature.rb', line 7 def percentage @percentage end |
#users ⇒ Object
Returns the value of attribute users.
7 8 9 |
# File 'lib/rollout/feature.rb', line 7 def users @users end |
Instance Method Details
#active?(user) ⇒ Boolean
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rollout/feature.rb', line 48 def active?(user) if user id = user_id(user) user_in_percentage?(id) || user_in_active_users?(id) || user_in_active_group?(user) else @percentage == 100 end end |
#add_group(group) ⇒ Object
36 37 38 |
# File 'lib/rollout/feature.rb', line 36 def add_group(group) @groups << group.to_sym unless @groups.include?(group.to_sym) end |
#add_user(user) ⇒ Object
27 28 29 30 |
# File 'lib/rollout/feature.rb', line 27 def add_user(user) id = user_id(user) @users << id unless @users.include?(id) end |
#clear ⇒ Object
44 45 46 |
# File 'lib/rollout/feature.rb', line 44 def clear assign_state(FeatureState.new(name: @name, percentage: 0)) end |
#deep_clone ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/rollout/feature.rb', line 72 def deep_clone c = self.clone c.instance_variable_set('@rollout', nil) c = Marshal.load(Marshal.dump(c)) c.instance_variable_set('@rollout', @rollout) c end |
#remove_group(group) ⇒ Object
40 41 42 |
# File 'lib/rollout/feature.rb', line 40 def remove_group(group) @groups.delete(group.to_sym) end |
#remove_user(user) ⇒ Object
32 33 34 |
# File 'lib/rollout/feature.rb', line 32 def remove_user(user) @users.delete(user_id(user)) end |
#to_feature_state ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/rollout/feature.rb', line 17 def to_feature_state FeatureState.new( name: @name, percentage: @percentage, users: Array(@users), groups: Array(@groups), data: @data, ) end |
#to_hash ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/rollout/feature.rb', line 63 def to_hash { percentage: @percentage, groups: @groups, users: @users, data: @data, } end |
#user_in_active_users?(user) ⇒ Boolean
59 60 61 |
# File 'lib/rollout/feature.rb', line 59 def user_in_active_users?(user) @users.include?(user_id(user)) end |