Sha256: 8efadcf70c6337b9c51cc3fb43f64ad8ec0d48f970cd743e0c3241b2a54523fc

Contents?: true

Size: 1000 Bytes

Versions: 5

Compression:

Stored size: 1000 Bytes

Contents

module Flipper
  module Gates
    class Group < Gate
      # Internal: The name of the gate. Used for instrumentation, etc.
      def name
        :group
      end

      # Internal: Name converted to value safe for adapter.
      def key
        :groups
      end

      def data_type
        :set
      end

      def enabled?(value)
        !value.empty?
      end

      # Internal: Checks if the gate is open for a thing.
      #
      # Returns true if gate open for thing, false if not.
      def open?(thing, value, options = {})
        if thing.nil?
          false
        else
          value.any? { |name|
            begin
              group = Flipper.group(name)
              group.match?(thing)
            rescue GroupNotRegistered
              false
            end
          }
        end
      end

      def wrap(thing)
        Types::Group.wrap(thing)
      end

      def protects?(thing)
        thing.is_a?(Types::Group) || thing.is_a?(Symbol)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flipper-0.9.2 lib/flipper/gates/group.rb
flipper-0.9.1 lib/flipper/gates/group.rb
flipper-0.9.0 lib/flipper/gates/group.rb
flipper-0.9.0.beta1 lib/flipper/gates/group.rb
flipper-0.8.0 lib/flipper/gates/group.rb