Class: Hanami::View::Exposure Private

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

Since:

  • 2.1.0

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.

Since:

  • 2.1.0

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

Since:

  • 2.1.0

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

Since:

  • 2.1.0



35
36
37
38
39
40
# File 'lib/hanami/view/exposure.rb', line 35

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.

Since:

  • 2.1.0



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

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.

Since:

  • 2.1.0



27
28
29
# File 'lib/hanami/view/exposure.rb', line 27

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.

Since:

  • 2.1.0



31
32
33
# File 'lib/hanami/view/exposure.rb', line 31

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.

Since:

  • 2.1.0



23
24
25
# File 'lib/hanami/view/exposure.rb', line 23

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.

Since:

  • 2.1.0



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

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.

Since:

  • 2.1.0



106
107
108
109
110
111
112
# File 'lib/hanami/view/exposure.rb', line 106

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)

Since:

  • 2.1.0



88
89
90
# File 'lib/hanami/view/exposure.rb', line 88

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.

Since:

  • 2.1.0



100
101
102
# File 'lib/hanami/view/exposure.rb', line 100

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)

Since:

  • 2.1.0



63
64
65
# File 'lib/hanami/view/exposure.rb', line 63

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.

Since:

  • 2.1.0



50
51
52
53
54
55
56
57
58
59
# File 'lib/hanami/view/exposure.rb', line 50

def dependency_names
  @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)

Since:

  • 2.1.0



82
83
84
# File 'lib/hanami/view/exposure.rb', line 82

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.

Since:

  • 2.1.0



69
70
71
72
73
74
75
76
77
78
# File 'lib/hanami/view/exposure.rb', line 69

def input_keys
  @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)

Since:

  • 2.1.0



94
95
96
# File 'lib/hanami/view/exposure.rb', line 94

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