Class: Hanami::View::Exposure Private
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
- #name ⇒ Object readonly private
- #object ⇒ Object readonly private
- #options ⇒ Object readonly private
- #proc ⇒ Object readonly private
Instance Method Summary collapse
- #bind(obj) ⇒ Object private
- #call(input, locals = {}) ⇒ Object private
- #decorate? ⇒ Boolean private
- #default_value ⇒ Object private
- #dependencies? ⇒ Boolean private
- #dependency_names ⇒ Object private
- #for_layout? ⇒ Boolean private
-
#initialize(name, proc = nil, object = nil, **options) ⇒ Exposure
constructor
private
A new instance of Exposure.
- #input_keys ⇒ Object private
- #private? ⇒ Boolean private
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.
35 36 37 38 39 40 |
# File 'lib/hanami/view/exposure.rb', line 35 def initialize(name, proc = nil, object = nil, **) @name = name @proc = prepare_proc(proc, object) @object = object @options = end |
Instance Attribute Details
#name ⇒ Object (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/hanami/view/exposure.rb', line 19 def name @name end |
#object ⇒ Object (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.
27 28 29 |
# File 'lib/hanami/view/exposure.rb', line 27 def object @object end |
#options ⇒ Object (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.
31 32 33 |
# File 'lib/hanami/view/exposure.rb', line 31 def @options end |
#proc ⇒ Object (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.
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.
44 45 46 |
# File 'lib/hanami/view/exposure.rb', line 44 def bind(obj) self.class.new(name, proc, obj, **) 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.
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.
88 89 90 |
# File 'lib/hanami/view/exposure.rb', line 88 def decorate? .fetch(:decorate, true) end |
#default_value ⇒ 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.
100 101 102 |
# File 'lib/hanami/view/exposure.rb', line 100 def default_value [: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.
63 64 65 |
# File 'lib/hanami/view/exposure.rb', line 63 def dependencies? !dependency_names.empty? end |
#dependency_names ⇒ 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.
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.
82 83 84 |
# File 'lib/hanami/view/exposure.rb', line 82 def for_layout? .fetch(:layout, false) end |
#input_keys ⇒ 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.
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.
94 95 96 |
# File 'lib/hanami/view/exposure.rb', line 94 def private? .fetch(:private, false) end |