Sha256: 95fb1b55bd2a282645f58e6d20c70b56b52c13826ad0d080a6b89d2387c61434

Contents?: true

Size: 707 Bytes

Versions: 3

Compression:

Stored size: 707 Bytes

Contents

module Flipper
  module Types
    class Group < Type
      def self.wrap(group_or_name)
        return group_or_name if group_or_name.is_a?(self)
        Flipper.group(group_or_name)
      end

      attr_reader :name

      def initialize(name, &block)
        @name = name.to_sym
        @value = @name

        if block_given?
          @block = block
          @single_argument = @block.arity == 1
        else
          @block = lambda { |thing, context| false }
          @single_argument = false
        end
      end

      def match?(thing, context)
        if @single_argument
          @block.call(thing)
        else
          @block.call(thing, context)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flipper-0.10.2 lib/flipper/types/group.rb
flipper-0.10.1 lib/flipper/types/group.rb
flipper-0.10.0 lib/flipper/types/group.rb