Class: JbuilderSchema::Renderer
- Inherits:
-
Object
- Object
- JbuilderSchema::Renderer
- Defined in:
- lib/jbuilder/schema/renderer.rb
Overview
Here we initialize all the variables needed for template and pass them to it
Instance Attribute Summary collapse
-
#locals ⇒ Object
readonly
TODO: Find a better way to load main app’s helpers: Helpers don’t work in Jbuilder itself, so no need to include them here! ActionController::Base.all_helpers_from_path(‘app/helpers’).each { |helper| include Object.const_get(“::#helperhelper.camelizeHelper”) }.
-
#options ⇒ Object
readonly
TODO: Find a better way to load main app’s helpers: Helpers don’t work in Jbuilder itself, so no need to include them here! ActionController::Base.all_helpers_from_path(‘app/helpers’).each { |helper| include Object.const_get(“::#helperhelper.camelizeHelper”) }.
Instance Method Summary collapse
-
#initialize(**options) ⇒ Renderer
constructor
A new instance of Renderer.
- #method_missing(method, *args) ⇒ Object
- #render(source) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(**options) ⇒ Renderer
Returns a new instance of Renderer.
17 18 19 20 21 |
# File 'lib/jbuilder/schema/renderer.rb', line 17 def initialize(**) @locals = .delete(:locals) || {} @options = _define_locals! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/jbuilder/schema/renderer.rb', line 30 def method_missing(method, *args) if method.to_s.end_with?("_path", "_url") method.to_s else super end end |
Instance Attribute Details
#locals ⇒ Object (readonly)
TODO: Find a better way to load main app’s helpers: Helpers don’t work in Jbuilder itself, so no need to include them here! ActionController::Base.all_helpers_from_path(‘app/helpers’).each { |helper| include Object.const_get(“::#JbuilderSchema::Renderer.helperhelper.camelizeHelper”) }
15 16 17 |
# File 'lib/jbuilder/schema/renderer.rb', line 15 def locals @locals end |
#options ⇒ Object (readonly)
TODO: Find a better way to load main app’s helpers: Helpers don’t work in Jbuilder itself, so no need to include them here! ActionController::Base.all_helpers_from_path(‘app/helpers’).each { |helper| include Object.const_get(“::#JbuilderSchema::Renderer.helperhelper.camelizeHelper”) }
15 16 17 |
# File 'lib/jbuilder/schema/renderer.rb', line 15 def @options end |
Instance Method Details
#render(source) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/jbuilder/schema/renderer.rb', line 23 def render(source) Template.new(**) do |json| # TODO: Get rid of 'eval' eval source.to_s # standard:disable Security/Eval end end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
38 39 40 |
# File 'lib/jbuilder/schema/renderer.rb', line 38 def respond_to_missing?(method_name, include_private = false) method_name.to_s.end_with?("_path", "_url") || super end |