Class: JbuilderSchema::Renderer

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

Instance Method Summary collapse

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(**options)
  @locals = options.delete(:locals) || {}
  @options = 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

#localsObject (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

#optionsObject (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
  @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(**options) 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

Returns:

  • (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