Class: Rollout::Feature
- Inherits:
-
Object
- Object
- Rollout::Feature
- Defined in:
- lib/rollout/feature.rb
Constant Summary collapse
- RAND_BASE =
(2**32 - 1) / 100.0
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#percentage ⇒ Object
Returns the value of attribute percentage.
Instance Method Summary collapse
- #active?(determinator = nil) ⇒ Boolean
- #add_error ⇒ Object
- #add_request ⇒ Object
- #errors ⇒ Object
-
#initialize(name, data = {}) ⇒ Feature
constructor
A new instance of Feature.
- #requests ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name, data = {}) ⇒ Feature
Returns a new instance of Feature.
12 13 14 15 16 |
# File 'lib/rollout/feature.rb', line 12 def initialize(name, data={}) @name = name @data = data @percentage = @data[:percentage] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/rollout/feature.rb', line 8 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/rollout/feature.rb', line 8 def name @name end |
#percentage ⇒ Object
Returns the value of attribute percentage.
7 8 9 |
# File 'lib/rollout/feature.rb', line 7 def percentage @percentage end |
Instance Method Details
#active?(determinator = nil) ⇒ Boolean
18 19 20 21 22 23 24 |
# File 'lib/rollout/feature.rb', line 18 def active?(determinator=nil) if determinator determinator_in_percentage?(determinator) else @percentage == 100 end end |
#add_error ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rollout/feature.rb', line 34 def add_error if @data[:errors] @data[:errors] = @data[:errors] + 1 else @data[:errors] = 1 end end |
#add_request ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/rollout/feature.rb', line 26 def add_request if @data[:requests] @data[:requests] = @data[:requests] + 1 else @data[:requests] = 1 end end |
#errors ⇒ Object
46 47 48 |
# File 'lib/rollout/feature.rb', line 46 def errors @data[:errors] || 0 end |
#requests ⇒ Object
42 43 44 |
# File 'lib/rollout/feature.rb', line 42 def requests @data[:requests] || 0 end |
#to_h ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rollout/feature.rb', line 50 def to_h { name: @name, percentage: @percentage, data: { requests: requests, errors: errors } } end |