Class: Dry::View::Exposure Private
- Inherits:
-
Object
- Object
- Dry::View::Exposure
- 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
- #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
- #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.
21 22 23 24 25 26 |
# File 'lib/dry/view/exposure.rb', line 21 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.
16 17 18 |
# File 'lib/dry/view/exposure.rb', line 16 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.
18 19 20 |
# File 'lib/dry/view/exposure.rb', line 18 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.
19 20 21 |
# File 'lib/dry/view/exposure.rb', line 19 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.
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, **) 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.
56 57 58 |
# File 'lib/dry/view/exposure.rb', line 56 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.
64 65 66 |
# File 'lib/dry/view/exposure.rb', line 64 def default_value [:default] 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.
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.
52 53 54 |
# File 'lib/dry/view/exposure.rb', line 52 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.
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.
60 61 62 |
# File 'lib/dry/view/exposure.rb', line 60 def private? .fetch(:private, false) end |