Sha256: f192489710be9d6f0b7de9ab1b1d9a497b621e3d47ffb1088d14ae20551dfaef

Contents?: true

Size: 1.28 KB

Versions: 17

Compression:

Stored size: 1.28 KB

Contents

module Shamu
  module Features

    # A selector used to match conditions against environment configuration.
    class Selector

      # ============================================================================
      # @!group Attributes
      #

      # @!attribute
      # @return [Array<Condition>] conditions that must match for the selector
      #     to match.
        attr_reader :conditions

      # @!attribute
      # @return [Boolean] true if the feature should not be enabled when the
      #     selector matches.
        attr_reader :reject

      # @!attribute
      # @return [Toggle] that owns the selector.
        attr_reader :toggle

      #
      # @!endgroup Attributes

      def initialize( toggle, config )
        @conditions = []

        config.each do |name, condition_config|
          if name == "reject"
            @reject = condition_config.to_bool
          else
            @conditions << Conditions::Condition.create( name, condition_config, toggle )
          end
        end

        @conditions.freeze
      end

      # @param [Context] context the feature evaluation context.
      # @return [Boolean] true if the selector matches the given environment.
      def match?( context )
        conditions.all? { |c| c.match?( context ) }
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
shamu-0.0.24 lib/shamu/features/selector.rb
shamu-0.0.21 lib/shamu/features/selector.rb
shamu-0.0.20 lib/shamu/features/selector.rb
shamu-0.0.19 lib/shamu/features/selector.rb
shamu-0.0.18 lib/shamu/features/selector.rb
shamu-0.0.17 lib/shamu/features/selector.rb
shamu-0.0.15 lib/shamu/features/selector.rb
shamu-0.0.14 lib/shamu/features/selector.rb
shamu-0.0.13 lib/shamu/features/selector.rb
shamu-0.0.11 lib/shamu/features/selector.rb
shamu-0.0.9 lib/shamu/features/selector.rb
shamu-0.0.8 lib/shamu/features/selector.rb
shamu-0.0.7 lib/shamu/features/selector.rb
shamu-0.0.5 lib/shamu/features/selector.rb
shamu-0.0.4 lib/shamu/features/selector.rb
shamu-0.0.3 lib/shamu/features/selector.rb
shamu-0.0.2 lib/shamu/features/selector.rb