Class: Hanami::View::Rendering::Scope
- Inherits:
-
LayoutScope
- Object
- LayoutScope
- Hanami::View::Rendering::Scope
- Defined in:
- lib/hanami/view/rendering/scope.rb
Overview
Rendering view scope
Direct Known Subclasses
Instance Method Summary collapse
-
#format ⇒ Symbol
Returns the requested format.
-
#initialize(view, locals = {}) ⇒ Scope
constructor
private
Initialize the scope.
-
#inspect ⇒ String
Returns an inspect String.
-
#respond_to_missing?(m, include_all) ⇒ TrueClass, FalseClass
private
Implements “respond to” logic.
Methods inherited from LayoutScope
#class, #local, #locals, #render, #respond_to?, #view
Constructor Details
#initialize(view, locals = {}) ⇒ Scope
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.
Initialize the scope
23 24 25 26 27 28 |
# File 'lib/hanami/view/rendering/scope.rb', line 23 def initialize(view, locals = {}) @view = view @locals = locals @layout = layout @scope = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object (protected)
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.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/hanami/view/rendering/scope.rb', line 71 def method_missing(m, *args, &block) ::Hanami::View::Escape.html( # FIXME: this isn't compatible with Hanami 2.0, as it extends a view # that we want to be frozen in the future # # See https://github.com/hanami/view/issues/130#issuecomment-319326236 if @view.respond_to?(m, true) @view.__send__ m, *args, &block elsif @locals.key?(m) @locals[m] else super end ) end |
Instance Method Details
#format ⇒ Symbol
Returns the requested format.
47 48 49 |
# File 'lib/hanami/view/rendering/scope.rb', line 47 def format locals[:format] end |
#inspect ⇒ String
Returns an inspect String
35 36 37 38 39 40 |
# File 'lib/hanami/view/rendering/scope.rb', line 35 def inspect base = "#<#{ self.class }: #{'%x' % (self.object_id << 1)}" base << " @view=\"#{@view}\"" if @view base << " @locals=\"#{@locals}\"" if @locals base << ">" end |
#respond_to_missing?(m, include_all) ⇒ TrueClass, FalseClass
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.
Implements “respond to” logic
59 60 61 62 63 64 65 66 |
# File 'lib/hanami/view/rendering/scope.rb', line 59 def respond_to_missing?(m, include_all) # FIXME: this isn't compatible with Hanami 2.0, as it extends a view # that we want to be frozen in the future # # See https://github.com/hanami/view/issues/130#issuecomment-319326236 @view.respond_to?(m, include_all) || @locals.key?(m) end |