Class: FormObj::Form

Inherits:
Struct show all
Extended by:
ActiveModel::Naming, ActiveModel::Translation
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
lib/form_obj/form.rb,
lib/form_obj/form/array.rb,
lib/form_obj/form/attribute.rb,
lib/form_obj/form/attributes.rb

Defined Under Namespace

Classes: Array, Attribute, Attributes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

attribute, attributes, inspect, #inspect, #primary_key, #primary_key=, #to_hash

Constructor Details

#initialize(*args) ⇒ Form

Returns a new instance of Form.



38
39
40
41
42
# File 'lib/form_obj/form.rb', line 38

def initialize(*args)
  @errors = ActiveModel::Errors.new(self)
  @persisted = false
  super
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



36
37
38
# File 'lib/form_obj/form.rb', line 36

def errors
  @errors
end

#persisted=(value) ⇒ Object (writeonly)

Sets the attribute persisted

Parameters:

  • value

    the value to set the attribute persisted to.



35
36
37
# File 'lib/form_obj/form.rb', line 35

def persisted=(value)
  @persisted = value
end

Class Method Details

.array_classObject



18
19
20
# File 'lib/form_obj/form.rb', line 18

def array_class
  Array
end

.attribute_classObject



26
27
28
# File 'lib/form_obj/form.rb', line 26

def attribute_class
  Attribute
end

.model_nameObject



30
31
32
# File 'lib/form_obj/form.rb', line 30

def model_name
  @model_name || super
end

.nested_classObject



22
23
24
# File 'lib/form_obj/form.rb', line 22

def nested_class
  ::FormObj::Form
end

Instance Method Details

#mark_as_persistedObject



48
49
50
51
52
53
54
# File 'lib/form_obj/form.rb', line 48

def mark_as_persisted
  self.persisted = true
  self.class._attributes.each { |attr|
    read_attribute(attr).mark_as_persisted if attr.subform?
  }
  self
end

#mark_for_destructionObject



56
57
58
59
60
61
62
# File 'lib/form_obj/form.rb', line 56

def mark_for_destruction
  @marked_for_destruction = true
  self.class._attributes.each { |attr|
    read_attribute(attr).mark_for_destruction if attr.subform?
  }
  self
end

#marked_for_destruction?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/form_obj/form.rb', line 64

def marked_for_destruction?
  @marked_for_destruction ||= false
end

#persisted?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/form_obj/form.rb', line 44

def persisted?
  @persisted
end

#update_attributes(attrs, raise_if_not_found: false) ⇒ Object



68
69
70
# File 'lib/form_obj/form.rb', line 68

def update_attributes(attrs, raise_if_not_found: false)
  super
end