Sha256: 89800bb1f6e6fdbe80484c9119c7158d4a76c1cfc11f03c0d8b9e41051fc4274

Contents?: true

Size: 928 Bytes

Versions: 3

Compression:

Stored size: 928 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)
        !Typecast.to_set(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 protects?(thing)
        thing.is_a?(Types::Group)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flipper-0.7.0.beta5 lib/flipper/gates/group.rb
flipper-0.7.0.beta4 lib/flipper/gates/group.rb
flipper-0.7.0.beta3 lib/flipper/gates/group.rb