Sha256: 0eef5292d9b909ee95278f82648e4b16d29f3da922cd7c6c4fe605f56da54ca4

Contents?: true

Size: 905 Bytes

Versions: 14

Compression:

Stored size: 905 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 = call_with_no_context?(@block)
        else
          @block = ->(_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

      NO_PARAMS_IN_RUBY_3 = [[:req], [:rest]]
      def call_with_no_context?(block)
        return true if block.parameters == NO_PARAMS_IN_RUBY_3

        block.arity.abs == 1
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
flipper-0.27.1 lib/flipper/types/group.rb
flipper-0.27.0 lib/flipper/types/group.rb
flipper-0.26.2 lib/flipper/types/group.rb
flipper-0.26.1 lib/flipper/types/group.rb
flipper-0.26.0 lib/flipper/types/group.rb
flipper-0.26.0.rc2 lib/flipper/types/group.rb
flipper-0.26.0.rc1 lib/flipper/types/group.rb
flipper-0.25.4 lib/flipper/types/group.rb
flipper-0.25.3 lib/flipper/types/group.rb
flipper-0.25.2 lib/flipper/types/group.rb
flipper-0.25.1 lib/flipper/types/group.rb
flipper-0.25.0 lib/flipper/types/group.rb
flipper-0.24.1 lib/flipper/types/group.rb
flipper-0.24.0 lib/flipper/types/group.rb