Class: Hanami::Mailer::DSL::Exposure Private

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

An exposure defined on a mailer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, proc = nil, object = nil, **options) ⇒ Exposure

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



19
20
21
22
23
24
# File 'lib/hanami/mailer/dsl/exposure.rb', line 19

def initialize(name, proc = nil, object = nil, **options)
  @name = name
  @object = object
  @options = options
  @callable = PluckyProc.from_name(proc, name, object)
end

Instance Attribute Details

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



17
18
19
# File 'lib/hanami/mailer/dsl/exposure.rb', line 17

def callable
  @callable
end

#nameObject (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/exposure.rb', line 14

def name
  @name
end

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



15
16
17
# File 'lib/hanami/mailer/dsl/exposure.rb', line 15

def object
  @object
end

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



16
17
18
# File 'lib/hanami/mailer/dsl/exposure.rb', line 16

def options
  @options
end

Instance Method Details

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



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

def bind(obj)
  self.class.new(name, callable&.proc, obj, **options)
end

#call(input, locals = {}) ⇒ 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.



52
53
54
55
56
57
58
# File 'lib/hanami/mailer/dsl/exposure.rb', line 52

def call(input, locals = {})
  if callable
    call_proc(input, locals)
  else
    input.fetch(name) { default_value }
  end
end

#default_valueObject

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.



48
49
50
# File 'lib/hanami/mailer/dsl/exposure.rb', line 48

def default_value
  options[:default]
end

#dependencies?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)


40
41
42
# File 'lib/hanami/mailer/dsl/exposure.rb', line 40

def dependencies?
  !dependency_names.empty?
end

#dependency_namesObject

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.



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

def dependency_names
  return [] unless callable

  callable.dependency_names
end

#private?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)


44
45
46
# File 'lib/hanami/mailer/dsl/exposure.rb', line 44

def private?
  options.fetch(:private, false)
end

#procObject

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.



30
31
32
# File 'lib/hanami/mailer/dsl/exposure.rb', line 30

def proc
  callable&.proc
end