Class: Rollout::Feature
- Inherits:
-
Object
- Object
- Rollout::Feature
- Defined in:
- lib/rollout.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?(rollout, user) ⇒ Boolean
- #add_group(group) ⇒ Object
- #add_user(user) ⇒ Object
- #clear ⇒ Object
-
#initialize(name, string = nil, opts = {}) ⇒ Feature
constructor
A new instance of Feature.
- #remove_group(group) ⇒ Object
- #remove_user(user) ⇒ Object
- #serialize ⇒ Object
- #to_hash ⇒ Object
- #user_in_active_users?(user) ⇒ Boolean
Constructor Details
#initialize(name, string = nil, opts = {}) ⇒ Feature
Returns a new instance of Feature.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rollout.rb', line 15 def initialize(name, string = nil, opts = {}) = opts @name = name if string raw_percentage, raw_users, raw_groups, raw_data = string.split('|', 4) @percentage = raw_percentage.to_f @users = users_from_string(raw_users) @groups = groups_from_string(raw_groups) @data = raw_data.nil? || raw_data.strip.empty? ? {} : JSON.parse(raw_data) else clear end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
12 13 14 |
# File 'lib/rollout.rb', line 12 def data @data end |
#groups ⇒ Object
Returns the value of attribute groups.
12 13 14 |
# File 'lib/rollout.rb', line 12 def groups @groups end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/rollout.rb', line 13 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/rollout.rb', line 13 def end |
#percentage ⇒ Object
Returns the value of attribute percentage.
12 13 14 |
# File 'lib/rollout.rb', line 12 def percentage @percentage end |
#users ⇒ Object
Returns the value of attribute users.
12 13 14 |
# File 'lib/rollout.rb', line 12 def users @users end |
Instance Method Details
#active?(rollout, user) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rollout.rb', line 58 def active?(rollout, user) if user id = user_id(user) user_in_percentage?(id) || user_in_active_users?(id) || user_in_active_group?(user, rollout) else @percentage == 100 end end |
#add_group(group) ⇒ Object
43 44 45 |
# File 'lib/rollout.rb', line 43 def add_group(group) @groups << group.to_sym unless @groups.include?(group.to_sym) end |
#add_user(user) ⇒ Object
34 35 36 37 |
# File 'lib/rollout.rb', line 34 def add_user(user) id = user_id(user) @users << id unless @users.include?(id) end |
#clear ⇒ Object
51 52 53 54 55 56 |
# File 'lib/rollout.rb', line 51 def clear @groups = groups_from_string('') @users = users_from_string('') @percentage = 0 @data = {} end |
#remove_group(group) ⇒ Object
47 48 49 |
# File 'lib/rollout.rb', line 47 def remove_group(group) @groups.delete(group.to_sym) end |
#remove_user(user) ⇒ Object
39 40 41 |
# File 'lib/rollout.rb', line 39 def remove_user(user) @users.delete(user_id(user)) end |
#serialize ⇒ Object
30 31 32 |
# File 'lib/rollout.rb', line 30 def serialize "#{@percentage}|#{@users.to_a.join(',')}|#{@groups.to_a.join(',')}|#{serialize_data}" end |
#to_hash ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/rollout.rb', line 73 def to_hash { percentage: @percentage, groups: @groups, users: @users } end |
#user_in_active_users?(user) ⇒ Boolean
69 70 71 |
# File 'lib/rollout.rb', line 69 def user_in_active_users?(user) @users.include?(user_id(user)) end |