Class: Hanami::Mailer::DSL::Exposures Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#exposuresObject (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, **options)
  exposure = Exposure.new(name, proc, **options)
  @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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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