Class: Flipper::Types::Group
- Inherits:
-
Flipper::Type
- Object
- Flipper::Type
- Flipper::Types::Group
- Defined in:
- lib/flipper/types/group.rb
Constant Summary collapse
- NO_PARAMS_IN_RUBY_3 =
[[:req], [:rest]]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Flipper::Type
Class Method Summary collapse
Instance Method Summary collapse
- #call_with_no_context?(block) ⇒ Boolean
-
#initialize(name, &block) ⇒ Group
constructor
A new instance of Group.
- #match?(actor, context) ⇒ Boolean
Methods inherited from Flipper::Type
Constructor Details
#initialize(name, &block) ⇒ Group
Returns a new instance of Group.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/flipper/types/group.rb', line 11 def initialize(name, &block) @name = name.to_sym @value = @name if block_given? @block = block @single_argument = call_with_no_context?(@block) else @block = ->(actor, context) { false } @single_argument = false end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/flipper/types/group.rb', line 9 def name @name end |
Class Method Details
Instance Method Details
#call_with_no_context?(block) ⇒ Boolean
33 34 35 36 37 |
# File 'lib/flipper/types/group.rb', line 33 def call_with_no_context?(block) return true if block.parameters == NO_PARAMS_IN_RUBY_3 block.arity.abs == 1 end |
#match?(actor, context) ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/flipper/types/group.rb', line 24 def match?(actor, context) if @single_argument @block.call(actor) else @block.call(actor, context) end end |