Class: Dry::View::Exposures Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#exposuresObject (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, **options)
  exposures[name] = Exposure.new(name, proc, **options)
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.

Returns:

  • (Boolean)


20
21
22
# File 'lib/dry/view/exposures.rb', line 20

def key?(name)
  exposures.key?(name)
end