Class: Hanami::Mailer::DSL::PluckyProc Private
- Inherits:
-
Object
- Object
- Hanami::Mailer::DSL::PluckyProc
- Defined in:
- lib/hanami/mailer/dsl/plucky_proc.rb
Overview
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.
A plucky proc that evaluates with automatic keyword argument extraction from input.
This class encapsulates the logic for calling procs/methods in a mailer context, handling both positional and keyword arguments intelligently based on the proc’s signature.
Instance Attribute Summary collapse
- #context ⇒ Object readonly private
- #proc ⇒ Object readonly private
Class Method Summary collapse
-
.from_name(proc, name, context) ⇒ PluckyProc?
private
Create a PluckyProc from either a proc or a method name on the context.
Instance Method Summary collapse
-
#call(input, *args) ⇒ Object
private
Evaluate the proc with input and optional positional arguments.
-
#callable? ⇒ Boolean
private
Check if this evaluator has a proc to call.
-
#dependency_names ⇒ Array<Symbol>
private
Get dependency parameter names (positional args: :req, :opt).
-
#initialize(proc, context:) ⇒ PluckyProc
constructor
private
Create a new plucky proc.
-
#keyword_names ⇒ Array<Symbol>
private
Get keyword parameter names (:key, :keyreq).
Constructor Details
#initialize(proc, context:) ⇒ PluckyProc
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.
Create a new plucky proc
20 21 22 23 |
# File 'lib/hanami/mailer/dsl/plucky_proc.rb', line 20 def initialize(proc, context:) @proc = proc @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
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.
14 15 16 |
# File 'lib/hanami/mailer/dsl/plucky_proc.rb', line 14 def context @context end |
#proc ⇒ Object (readonly)
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.
14 15 16 |
# File 'lib/hanami/mailer/dsl/plucky_proc.rb', line 14 def proc @proc end |
Class Method Details
.from_name(proc, name, context) ⇒ PluckyProc?
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.
Create a PluckyProc from either a proc or a method name on the context
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hanami/mailer/dsl/plucky_proc.rb', line 32 def self.from_name(proc, name, context) resolved_proc = if proc proc elsif context.respond_to?(name, _include_private = true) context.method(name) end new(resolved_proc, context: context) if resolved_proc end |
Instance Method Details
#call(input, *args) ⇒ 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.
Evaluate the proc with input and optional positional arguments
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/hanami/mailer/dsl/plucky_proc.rb', line 49 def call(input, *args) return nil unless proc keywords = extract_keywords(input) if keywords.empty? call_without_keywords(*args) else call_with_keywords(keywords, *args) end end |
#callable? ⇒ Boolean
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.
Check if this evaluator has a proc to call
64 65 66 |
# File 'lib/hanami/mailer/dsl/plucky_proc.rb', line 64 def callable? !proc.nil? end |
#dependency_names ⇒ Array<Symbol>
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.
Get dependency parameter names (positional args: :req, :opt)
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hanami/mailer/dsl/plucky_proc.rb', line 71 def dependency_names @dependency_names ||= if proc proc.parameters.each_with_object([]) { |(type, name), names| names << name if %i[req opt].include?(type) } else [] end end |
#keyword_names ⇒ Array<Symbol>
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.
Get keyword parameter names (:key, :keyreq)
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/hanami/mailer/dsl/plucky_proc.rb', line 85 def keyword_names @keyword_names ||= if proc proc.parameters.each_with_object([]) { |(type, name), keys| keys << name if %i[key keyreq].include?(type) } else [] end end |