Class: Rollout::Feature
- Inherits:
-
Object
- Object
- Rollout::Feature
- Defined in:
- lib/rollout.rb
Instance Attribute Summary collapse
-
#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
Constructor Details
#initialize(name, string = nil, opts = {}) ⇒ Feature
Returns a new instance of Feature.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rollout.rb', line 10 def initialize(name, string = nil, opts = {}) @options = opts @name = name if string raw_percentage,raw_users,raw_groups = string.split("|") @percentage = raw_percentage.to_i @users = (raw_users || "").split(",").map(&:to_s) @groups = (raw_groups || "").split(",").map(&:to_sym) else clear end end |
Instance Attribute Details
#groups ⇒ Object
Returns the value of attribute groups.
7 8 9 |
# File 'lib/rollout.rb', line 7 def groups @groups end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/rollout.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/rollout.rb', line 8 def @options end |
#percentage ⇒ Object
Returns the value of attribute percentage.
7 8 9 |
# File 'lib/rollout.rb', line 7 def percentage @percentage end |
#users ⇒ Object
Returns the value of attribute users.
7 8 9 |
# File 'lib/rollout.rb', line 7 def users @users end |
Instance Method Details
#active?(rollout, user) ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rollout.rb', line 51 def active?(rollout, user) if user.nil? @percentage == 100 else id = user_id(user) user_in_percentage?(id) || user_in_active_users?(id) || user_in_active_group?(user, rollout) end end |
#add_group(group) ⇒ Object
37 38 39 |
# File 'lib/rollout.rb', line 37 def add_group(group) @groups << group.to_sym unless @groups.include?(group.to_sym) end |
#add_user(user) ⇒ Object
28 29 30 31 |
# File 'lib/rollout.rb', line 28 def add_user(user) id = user_id(user) @users << id unless @users.include?(id) end |
#clear ⇒ Object
45 46 47 48 49 |
# File 'lib/rollout.rb', line 45 def clear @groups = [] @users = [] @percentage = 0 end |
#remove_group(group) ⇒ Object
41 42 43 |
# File 'lib/rollout.rb', line 41 def remove_group(group) @groups.delete(group.to_sym) end |
#remove_user(user) ⇒ Object
33 34 35 |
# File 'lib/rollout.rb', line 33 def remove_user(user) @users.delete(user_id(user)) end |
#serialize ⇒ Object
24 25 26 |
# File 'lib/rollout.rb', line 24 def serialize "#{@percentage}|#{@users.join(",")}|#{@groups.join(",")}" end |
#to_hash ⇒ Object
62 63 64 65 66 |
# File 'lib/rollout.rb', line 62 def to_hash {:percentage => @percentage, :groups => @groups, :users => @users} end |