Class: Dry::Logic::Builder::Context Private
- Inherits:
-
Object
- Object
- Dry::Logic::Builder::Context
- Defined in:
- lib/dry/logic/builder/context_predicate_name.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
-
#initialize ⇒ Context
constructor
private
Defines methods for operations and predicates.
-
#predicate(name, context = nil, &block) ⇒ Object
private
Defines custom predicate.
Constructor Details
#initialize ⇒ Context
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defines methods for operations and predicates
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dry/logic/builder/context_predicate_name.rb', line 23 def initialize Operations.constants(false).each do |name| next if Dry::Logic::Builder::IGNORED_OPERATIONS.include?(name) operation = Operations.const_get(name) define_singleton_method(name.downcase) do |*args, **kwargs, &block| operation.new(*call(&block), *args, **kwargs) end end Predicates::Methods.instance_methods(false).each do |name| predicate(name, Predicates[name]) unless Dry::Logic::Builder::IGNORED_PREDICATES.include?(name) end end |
Instance Method Details
#predicate(name, context = nil, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defines custom predicate
12 13 14 15 16 17 18 19 20 |
# File 'lib/dry/logic/builder/context_predicate_name.rb', line 12 def predicate(name, context = nil, &block) singleton_class.undef_method(name) if singleton_class.method_defined?(name) predicate = Rule::Predicate.new(context || block) define_singleton_method(name) do |*args| predicate.curry(*args) end end |