Class: Dry::View::Exposures Private
- Inherits:
-
Object
- Object
- Dry::View::Exposures
- Includes:
- TSort
- Defined in:
- lib/dry/view/exposures.rb
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.
16 17 18 |
# File 'lib/dry/view/exposures.rb', line 16 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.
14 15 16 |
# File 'lib/dry/view/exposures.rb', line 14 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.
24 25 26 |
# File 'lib/dry/view/exposures.rb', line 24 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.
32 33 34 |
# File 'lib/dry/view/exposures.rb', line 32 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.
40 41 42 43 44 45 46 |
# File 'lib/dry/view/exposures.rb', line 40 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.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dry/view/exposures.rb', line 48 def call(input) tsort.each_with_object({}) { |name, memo| next unless (exposure = self[name]) value = exposure.(input, memo) value = yield(value, exposure) if block_given? memo[name] = value }.each_with_object({}) { |(name, value), memo| memo[name] = value unless self[name].private? } # rubocop:enable Style/MultilineBlockChain 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.
28 29 30 |
# File 'lib/dry/view/exposures.rb', line 28 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.
36 37 38 |
# File 'lib/dry/view/exposures.rb', line 36 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.
20 21 22 |
# File 'lib/dry/view/exposures.rb', line 20 def key?(name) exposures.key?(name) end |