Class: Hanami::Mailer::DSL::Attachments Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/mailer/dsl/attachments.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.

Collection of class-level attachment definitions for a mailer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definitions = []) ⇒ Attachments

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 Attachments.



12
13
14
# File 'lib/hanami/mailer/dsl/attachments.rb', line 12

def initialize(definitions = [])
  @definitions = definitions
end

Instance Attribute Details

#definitionsObject (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.



10
11
12
# File 'lib/hanami/mailer/dsl/attachments.rb', line 10

def definitions
  @definitions
end

Instance Method Details

#add(name_or_filename, 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.



21
22
23
# File 'lib/hanami/mailer/dsl/attachments.rb', line 21

def add(name_or_filename, proc = nil, **options)
  definitions << Attachment.new(name_or_filename, proc, **options)
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.

Returns a copy with every definition bound to the mailer instance.



26
27
28
# File 'lib/hanami/mailer/dsl/attachments.rb', line 26

def bind(obj)
  self.class.new(definitions.map { |definition| definition.bind(obj) })
end

#call(input, dependencies: {}) ⇒ 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 the bound definitions, returning an AttachmentSet of Hanami::Mailer::DSL::Attachment instances.

Each definition’s positional parameters resolve against ‘dependencies` (the mailer’s exposure values); its keyword parameters resolve against ‘input` (the raw `deliver` input).



34
35
36
37
38
# File 'lib/hanami/mailer/dsl/attachments.rb', line 34

def call(input, dependencies: {})
  attachments = definitions.flat_map { |definition| definition.call(input, dependencies) }

  AttachmentSet.new(attachments)
end