Class: Dry::View::Exposure Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/view/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 view

Constant Summary collapse

EXPOSURE_DEPENDENCY_PARAMETER_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i[req opt].freeze
INPUT_PARAMETER_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i[key keyreq keyrest].freeze

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.



21
22
23
24
25
26
# File 'lib/dry/view/exposure.rb', line 21

def initialize(name, proc = nil, object = nil, **options)
  @name = name
  @proc = prepare_proc(proc, object)
  @object = object
  @options = options
end

Instance Attribute Details

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



16
17
18
# File 'lib/dry/view/exposure.rb', line 16

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.



18
19
20
# File 'lib/dry/view/exposure.rb', line 18

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.



19
20
21
# File 'lib/dry/view/exposure.rb', line 19

def options
  @options
end

#procObject (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/dry/view/exposure.rb', line 17

def proc
  @proc
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.



28
29
30
# File 'lib/dry/view/exposure.rb', line 28

def bind(obj)
  self.class.new(name, 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.



68
69
70
71
72
73
74
# File 'lib/dry/view/exposure.rb', line 68

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

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


56
57
58
# File 'lib/dry/view/exposure.rb', line 56

def decorate?
  options.fetch(:decorate, true)
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.



64
65
66
# File 'lib/dry/view/exposure.rb', line 64

def default_value
  options[:default]
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.



32
33
34
35
36
37
38
39
40
# File 'lib/dry/view/exposure.rb', line 32

def dependency_names
  if proc
    proc.parameters.each_with_object([]) { |(type, name), names|
      names << name if EXPOSURE_DEPENDENCY_PARAMETER_TYPES.include?(type)
    }
  else
    []
  end
end

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


52
53
54
# File 'lib/dry/view/exposure.rb', line 52

def for_layout?
  options.fetch(:layout, false)
end

#input_keysObject

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.



42
43
44
45
46
47
48
49
50
# File 'lib/dry/view/exposure.rb', line 42

def input_keys
  if proc
    proc.parameters.each_with_object([]) { |(type, name), keys|
      keys << name if INPUT_PARAMETER_TYPES.include?(type)
    }
  else
    []
  end
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)


60
61
62
# File 'lib/dry/view/exposure.rb', line 60

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