Class: Hanami::Mailer::DSL::Exposures Private
- Inherits:
-
Object
- Object
- Hanami::Mailer::DSL::Exposures
- Includes:
- TSort
- Defined in:
- lib/hanami/mailer/dsl/exposures.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 Attribute Summary collapse
- #exposures ⇒ Object readonly private
Instance Method Summary collapse
- #[](name) ⇒ Object private
- #add(name, proc = nil, **options) ⇒ Object private
- #bind(obj) ⇒ Object private
-
#call(input, dependencies: nil) ⇒ Object
private
Evaluates each exposure and returns a hash of their values.
- #each(&block) ⇒ Object private
- #empty? ⇒ Boolean private
- #import(name, exposure) ⇒ Object private
-
#initialize(exposures = {}) ⇒ Exposures
constructor
private
A new instance of Exposures.
- #initialize_copy(source) ⇒ Object private
- #key?(name) ⇒ Boolean private
-
#reject_private(values) ⇒ Object
private
Removes private exposures from a hash of evaluated values.
Constructor Details
#initialize(exposures = {}) ⇒ Exposures
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.
Returns a new instance of Exposures.
16 17 18 19 |
# File 'lib/hanami/mailer/dsl/exposures.rb', line 16 def initialize(exposures = {}) @exposures = exposures @has_dependencies = false end |
Instance Attribute Details
#exposures ⇒ 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/exposures.rb', line 14 def exposures @exposures end |
Instance Method Details
#[](name) ⇒ 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.
31 32 33 |
# File 'lib/hanami/mailer/dsl/exposures.rb', line 31 def [](name) exposures[name] end |
#add(name, proc = nil, **options) ⇒ 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.
43 44 45 46 47 |
# File 'lib/hanami/mailer/dsl/exposures.rb', line 43 def add(name, proc = nil, **) exposure = Exposure.new(name, proc, **) @has_dependencies ||= exposure.dependencies? exposures[name] = exposure end |
#bind(obj) ⇒ 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.
53 54 55 56 57 58 59 60 61 |
# File 'lib/hanami/mailer/dsl/exposures.rb', line 53 def bind(obj) bound_exposures = exposures.transform_values { |exposure| exposure.bind(obj) } copy = self.class.new(bound_exposures) copy.instance_variable_set(:@has_dependencies, @has_dependencies) copy end |
#call(input, dependencies: nil) ⇒ 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.
Evaluates each exposure and returns a hash of their values.
By default each exposure’s positional parameters resolve against its sibling exposures in this collection (the values accumulate as the collection is evaluated, ordered by tsort).
When ‘dependencies` is given, positional parameters resolve against those instead, and no sibling resolution (or tsort) takes place. This is how the mailer collections like headers and delivery options consume the mailer’s exposures as their one shared dependency graph.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hanami/mailer/dsl/exposures.rb', line 71 def call(input, dependencies: nil) ordered_evaluation_keys(dependencies).each_with_object({}) { |name, memo| next unless (exposure = self[name]) value = exposure.(input, dependencies || memo) value = yield(value, exposure) if block_given? memo[name] = value } end |
#each(&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.
35 36 37 |
# File 'lib/hanami/mailer/dsl/exposures.rb', line 35 def each(&block) exposures.each(&block) end |
#empty? ⇒ 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.
39 40 41 |
# File 'lib/hanami/mailer/dsl/exposures.rb', line 39 def empty? exposures.empty? end |
#import(name, exposure) ⇒ 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.
49 50 51 |
# File 'lib/hanami/mailer/dsl/exposures.rb', line 49 def import(name, exposure) exposures[name] = exposure.dup end |
#initialize_copy(source) ⇒ 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.
21 22 23 24 25 |
# File 'lib/hanami/mailer/dsl/exposures.rb', line 21 def initialize_copy(source) super @exposures = source.exposures.transform_values(&:dup) @has_dependencies = source.instance_variable_get(:@has_dependencies) end |
#key?(name) ⇒ 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.
27 28 29 |
# File 'lib/hanami/mailer/dsl/exposures.rb', line 27 def key?(name) exposures.key?(name) end |
#reject_private(values) ⇒ 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.
Removes private exposures from a hash of evaluated values.
Private exposures are computed and stay available as positional dependencies — to other exposures, and to the mailer’s headers, attachments, and delivery options — but they are never passed to the view for rendering. This filters them out for that final step.
87 88 89 |
# File 'lib/hanami/mailer/dsl/exposures.rb', line 87 def reject_private(values) values.reject { |name, _| self[name]&.private? } end |