Class: Jbuilder::Jpartial::JbuilderProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/jbuilder/jpartial.rb

Overview

Partial method execution is defined here. Jbuilder only knows how to initialize an instance of the proxy class and send it the right message. The proxy is initialized with the execution context if there is any so it can pass along context methods when they’re defined.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, context = nil) ⇒ JbuilderProxy

Returns a new instance of JbuilderProxy.



64
65
66
67
# File 'lib/jbuilder/jpartial.rb', line 64

def initialize(json, context = nil)
  @json    = json
  @context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/jbuilder/jpartial.rb', line 69

def method_missing(method_name, *args, &block)
  if _method_defined_in_context?(method_name)
    @context.send(method_name, *args, &block)
  else
    super(method_name, *args, &block)
  end
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



62
63
64
# File 'lib/jbuilder/jpartial.rb', line 62

def json
  @json
end

Instance Method Details

#_method_defined_in_context?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/jbuilder/jpartial.rb', line 77

def _method_defined_in_context?(method_name)
  !@context.nil? && @context.respond_to?(method_name)
end