Class: Flattener::NestedConfigurator

Inherits:
Configurator show all
Defined in:
lib/flattener/configurator.rb

Instance Attribute Summary collapse

Attributes inherited from Configurator

#accessor, #flattened_attrs, #klass, #name, #options, #prefix

Instance Method Summary collapse

Methods inherited from Configurator

#accessor_method_name, #add_build_method!, #add_proxy_method!, #add_validator_method!, #attribute, #attributes, #build_method_name, #flat, flat, #mass_assignment_is_supported?, #method_name_for, #module_included?, #proxy_method_name, #validate_method_name, #validations_are_supported?

Constructor Details

#initialize(parent, name, options = {}, &block) ⇒ NestedConfigurator

Returns a new instance of NestedConfigurator.



147
148
149
150
151
152
153
154
155
156
# File 'lib/flattener/configurator.rb', line 147

def initialize(parent, name, options = {}, &block)
  @parent = parent
  options[:prefix] ||= if @parent.prefix.blank?
    name.to_s
  else
    "#{@parent.prefix}_#{name.to_s}"
  end
  options[:accessor] ||= "#{parent.accessor_method_name}_#{name}"
  super(parent.klass, name, options, &block)
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



145
146
147
# File 'lib/flattener/configurator.rb', line 145

def parent
  @parent
end

Instance Method Details

#prepare!Object



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/flattener/configurator.rb', line 158

def prepare!
  super
  code = <<-CODE
    # customer_payment_profile_address
    
    def #{parent.accessor_method_name}_#{name}
      #{parent.proxy_method_name}.#{name}
    end
  CODE
  @klass.class_eval code
end