Class: Rollout::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/rollout/feature.rb

Constant Summary collapse

RAND_BASE =
(2**32 - 1) / 100.0

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/rollout/feature.rb', line 8

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/rollout/feature.rb', line 8

def name
  @name
end

#percentageObject

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

Returns:

  • (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_errorObject



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_requestObject



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

#errorsObject



46
47
48
# File 'lib/rollout/feature.rb', line 46

def errors
  @data[:errors] || 0
end

#requestsObject



42
43
44
# File 'lib/rollout/feature.rb', line 42

def requests
  @data[:requests] || 0
end

#to_hObject



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