Class: Hanami::View::Exposures Private
- Includes:
- TSort
- Defined in:
- lib/hanami/view/exposures.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.
Instance Attribute Summary collapse
- #exposures ⇒ Object readonly private
Instance Method Summary collapse
- #[](name) ⇒ Object private
- #add(name, proc = nil, **options) ⇒ Object private
- #bind(obj) ⇒ Object private
- #call(input) ⇒ Object private
- #each(&block) ⇒ Object private
- #import(name, exposure) ⇒ Object private
-
#initialize(exposures = {}) ⇒ Exposures
constructor
private
A new instance of Exposures.
- #key?(name) ⇒ Boolean private
Constructor Details
#initialize(exposures = {}) ⇒ Exposures
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 Exposures.
20 21 22 |
# File 'lib/hanami/view/exposures.rb', line 20 def initialize(exposures = {}) @exposures = exposures end |
Instance Attribute Details
#exposures ⇒ 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/hanami/view/exposures.rb', line 16 def exposures @exposures end |
Instance Method Details
#[](name) ⇒ 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 |
# File 'lib/hanami/view/exposures.rb', line 32 def [](name) exposures[name] end |
#add(name, proc = nil, **options) ⇒ 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/exposures.rb', line 44 def add(name, proc = nil, **) exposures[name] = Exposure.new(name, proc, **) end |
#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.
56 57 58 59 60 61 62 |
# File 'lib/hanami/view/exposures.rb', line 56 def bind(obj) bound_exposures = exposures.each_with_object({}) { |(name, exposure), memo| memo[name] = exposure.bind(obj) } self.class.new(bound_exposures) end |
#call(input) ⇒ 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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/hanami/view/exposures.rb', line 66 def call(input) # Avoid performance cost of tsorting when we don't need it names = if exposures.values.any?(&:dependencies?) # TODO: this sholud be cachable at time of `#add` tsort else exposures.keys end names .each_with_object({}) { |name, memo| next unless (exposure = self[name]) value = exposure.(input, memo) value = yield(value, exposure) if block_given? memo[name] = value } .tap { |hsh| names.each do |key| hsh.delete(key) if self[key].private? end } end |
#each(&block) ⇒ 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.
38 39 40 |
# File 'lib/hanami/view/exposures.rb', line 38 def each(&block) exposures.each(&block) end |
#import(name, exposure) ⇒ 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 |
# File 'lib/hanami/view/exposures.rb', line 50 def import(name, exposure) exposures[name] = exposure.dup end |
#key?(name) ⇒ 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.
26 27 28 |
# File 'lib/hanami/view/exposures.rb', line 26 def key?(name) exposures.key?(name) end |