Class: Dry::View::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/view/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(renderer, data, context = nil) ⇒ Scope

Returns a new instance of Scope.



12
13
14
15
16
# File 'lib/dry/view/scope.rb', line 12

def initialize(renderer, data, context = nil)
  @_renderer = renderer
  @_data = data.to_hash
  @_context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dry/view/scope.rb', line 24

def method_missing(name, *args, &block)
  if _data.key?(name)
    _data[name]
  elsif _context.respond_to?(name)
    _context.public_send(name, *args, &block)
  elsif (template_path = _template?(name))
    _render(template_path, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#_contextObject (readonly)

Returns the value of attribute _context.



10
11
12
# File 'lib/dry/view/scope.rb', line 10

def _context
  @_context
end

#_dataObject (readonly)

Returns the value of attribute _data.



9
10
11
# File 'lib/dry/view/scope.rb', line 9

def _data
  @_data
end

#_rendererObject (readonly)

Returns the value of attribute _renderer.



8
9
10
# File 'lib/dry/view/scope.rb', line 8

def _renderer
  @_renderer
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/dry/view/scope.rb', line 18

def respond_to_missing?(name, include_private = false)
  _template?(name) || _data.key?(name) || _context.respond_to?(name)
end