Class: IndexFor::Builder

Inherits:
Object
  • Object
show all
Includes:
Attribute, ShareHelper
Defined in:
lib/index_for/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, html_options, template) ⇒ Builder

Returns a new instance of Builder.



10
11
12
# File 'lib/index_for/builder.rb', line 10

def initialize object, html_options, template
  @object, @html_options, @template = object, html_options, template
end

Instance Attribute Details

#html_optionsObject

Returns the value of attribute html_options.



8
9
10
# File 'lib/index_for/builder.rb', line 8

def html_options
  @html_options
end

#objectObject

Returns the value of attribute object.



8
9
10
# File 'lib/index_for/builder.rb', line 8

def object
  @object
end

#templateObject

Returns the value of attribute template.



8
9
10
# File 'lib/index_for/builder.rb', line 8

def template
  @template
end

Instance Method Details

#actions(*action_names, &block) ⇒ Object



35
# File 'lib/index_for/builder.rb', line 35

def actions *action_names, █ end

#association(attribute_name, options = {}, &block) ⇒ Object



15
16
17
# File 'lib/index_for/builder.rb', line 15

def association attribute_name, options = {}, &block
  attribute attribute_name, options, &block
end

#attribute(attribute_name, options = {}, &block) ⇒ Object



14
# File 'lib/index_for/builder.rb', line 14

def attribute attribute_name, options = {}, █ end

#attributes(*attribute_names) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/index_for/builder.rb', line 19

def attributes *attribute_names
  options = attribute_names.extract_options!

  attribute_names.map do |attribute_name|
    attribute attribute_name, options
  end.join.html_safe
end

#fields_for(attribute_name, options = {}, &block) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/index_for/builder.rb', line 27

def fields_for attribute_name, options = {}, &block
  object = @object.send(attribute_name)
  fields_for = @html_options[:fields_for] || []
  fields_for.push attribute_name
  options.merge!(fields_for: attribute_name)
  @template.capture(self.class.new(object, options, @template), &block)
end