Class: FormObj::Mappable::Attribute

Inherits:
Attribute
  • Object
show all
Defined in:
lib/form_obj/mappable/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, array: false, class: nil, default: nil, hash: false, model: :default, model_attribute: nil, model_class: nil, parent:, primary_key: nil, &block) ⇒ Attribute

Returns a new instance of Attribute.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/form_obj/mappable/attribute.rb', line 8

def initialize(name, array: false, class: nil, default: nil, hash: false, model: :default, model_attribute: nil, model_class: nil, parent:, primary_key: nil, &block)
  @hash = hash
  @model_attribute = ModelAttribute.new(model: model, names: model_attribute, classes: model_class, default_name: name, array: array, hash: hash, subform: binding.local_variable_get(:class) || block_given?)

  if block_given?
    new_block = Proc.new do
      include FormObj::Mappable
      class_eval &block
    end
  end
  super(name, array: array, class: binding.local_variable_get(:class), default: default, parent: parent, primary_key: primary_key, &new_block)

  @nested_class = Class.new(@nested_class) if binding.local_variable_get(:class)
  @nested_class.hash = hash if @nested_class
end

Instance Attribute Details

#model_attributeObject (readonly)

Returns the value of attribute model_attribute.



6
7
8
# File 'lib/form_obj/mappable/attribute.rb', line 6

def model_attribute
  @model_attribute
end

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/form_obj/mappable/attribute.rb', line 24

def array?
  @array
end