Class: AttributesFor::Rails::AttributesForHelper::AttributeBuilder

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers, FontAwesome::Rails::IconHelper
Defined in:
app/helpers/attributes_for/rails/attributes_for_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, template, options = {}) ⇒ AttributeBuilder

Returns a new instance of AttributeBuilder.



16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/attributes_for/rails/attributes_for_helper.rb', line 16

def initialize(object, template, options = {})
  options = options.dup
  @object   = object
  @template = template
  @default_options = options[:defaults] || {}

  @wrappers = { label: 'span', value: 'span' }
  @wrappers.merge!(options.delete(:wrappers)) if options.key?(:wrappers)

  @empty    = options.delete(:empty) if options.key?(:empty)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



28
29
30
# File 'app/helpers/attributes_for/rails/attributes_for_helper.rb', line 28

def method_missing(method, *args, &block)
  build_content(method, *args, &block)
end

Instance Attribute Details

#default_optionsObject

Returns the value of attribute default_options.



13
14
15
# File 'app/helpers/attributes_for/rails/attributes_for_helper.rb', line 13

def default_options
  @default_options
end

#objectObject

Returns the value of attribute object.



13
14
15
# File 'app/helpers/attributes_for/rails/attributes_for_helper.rb', line 13

def object
  @object
end

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'app/helpers/attributes_for/rails/attributes_for_helper.rb', line 13

def options
  @options
end

#templateObject

Returns the value of attribute template.



13
14
15
# File 'app/helpers/attributes_for/rails/attributes_for_helper.rb', line 13

def template
  @template
end

#wrappersObject

Returns the value of attribute wrappers.



13
14
15
# File 'app/helpers/attributes_for/rails/attributes_for_helper.rb', line 13

def wrappers
  @wrappers
end

Instance Method Details

#string(label, options = {}, &block) ⇒ Object



32
33
34
# File 'app/helpers/attributes_for/rails/attributes_for_helper.rb', line 32

def string(label, options = {}, &block)
  wrap_content(label, template.capture(&block), options)
end