File: gate_values.rb

package info (click to toggle)
ruby-flipper 0.13.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,824 kB
  • sloc: ruby: 13,183; sh: 54; makefile: 14
file content (45 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'set'

module Flipper
  class GateValues
    # Private: Array of instance variables that are readable through the []
    # instance method.
    LegitIvars = {
      'boolean' => '@boolean',
      'actors' => '@actors',
      'groups' => '@groups',
      'percentage_of_time' => '@percentage_of_time',
      'percentage_of_actors' => '@percentage_of_actors',
    }.freeze

    attr_reader :boolean
    attr_reader :actors
    attr_reader :groups
    attr_reader :percentage_of_actors
    attr_reader :percentage_of_time

    def initialize(adapter_values)
      @boolean = Typecast.to_boolean(adapter_values[:boolean])
      @actors = Typecast.to_set(adapter_values[:actors])
      @groups = Typecast.to_set(adapter_values[:groups])
      @percentage_of_actors = Typecast.to_percentage(adapter_values[:percentage_of_actors])
      @percentage_of_time = Typecast.to_percentage(adapter_values[:percentage_of_time])
    end

    def [](key)
      if ivar = LegitIvars[key.to_s]
        instance_variable_get(ivar)
      end
    end

    def eql?(other)
      self.class.eql?(other.class) &&
        boolean == other.boolean &&
        actors == other.actors &&
        groups == other.groups &&
        percentage_of_actors == other.percentage_of_actors &&
        percentage_of_time == other.percentage_of_time
    end
    alias_method :==, :eql?
  end
end