Sha256: dff851b1282c54b50145a8f7e58c7b120ec33c2fc77d3366cbaa58f17018c7f9

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

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_integer(adapter_values[:percentage_of_actors])
      @percentage_of_time = Typecast.to_integer(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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
flipper-0.10.2 lib/flipper/gate_values.rb
flipper-0.10.1 lib/flipper/gate_values.rb
flipper-0.10.0 lib/flipper/gate_values.rb
flipper-0.9.2 lib/flipper/gate_values.rb
flipper-0.9.1 lib/flipper/gate_values.rb
flipper-0.9.0 lib/flipper/gate_values.rb
flipper-0.9.0.beta1 lib/flipper/gate_values.rb