Class: ViewPartialFormBuilder::TemplateProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/view_partial_form_builder/template_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder:, template:) ⇒ TemplateProxy

Returns a new instance of TemplateProxy.



5
6
7
8
# File 'lib/view_partial_form_builder/template_proxy.rb', line 5

def initialize(builder:, template:)
  @template = template
  @builder = builder
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/view_partial_form_builder/template_proxy.rb', line 37

def method_missing(name, *arguments, &block)
  if @builder.respond_to?(name)
    arguments_after_object_name = arguments.from(1)

    render(name, arguments: arguments_after_object_name, block: block) do
      @template.public_send(name, *arguments, &block)
    end
  elsif @template.respond_to?(name)
    @template.public_send(name, *arguments, &block)
  else
    super
  end
end

Instance Method Details

#button_tag(value, options, &block) ⇒ Object



10
11
12
13
14
# File 'lib/view_partial_form_builder/template_proxy.rb', line 10

def button_tag(value, options, &block)
  render(:button, arguments: [value, options], block: block) do
    @template.button_tag(value, options, &block)
  end
end

#label(object_name, method, content_or_options = nil, options = nil, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/view_partial_form_builder/template_proxy.rb', line 22

def label(object_name, method, content_or_options = nil, options = nil, &block)
  if content_or_options.is_a?(Hash)
    options.merge! content_or_options
    content = nil
  else
    content = content_or_options
  end

  render(:label, arguments: [method, content, options], block: block) do
    @template.label(object_name, method, content, options, &block)
  end
end

#submit_tag(value, options) ⇒ Object



16
17
18
19
20
# File 'lib/view_partial_form_builder/template_proxy.rb', line 16

def submit_tag(value, options)
  render(:submit, arguments: [value, options]) do
    @template.submit_tag(value, options)
  end
end