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, #update_attributes
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
#errors ⇒ Object
Returns the value of attribute errors.
36
37
38
|
# File 'lib/form_obj/form.rb', line 36
def errors
@errors
end
|
#persisted=(value) ⇒ Object
Sets the attribute persisted
35
36
37
|
# File 'lib/form_obj/form.rb', line 35
def persisted=(value)
@persisted = value
end
|
Class Method Details
.array_class ⇒ Object
18
19
20
|
# File 'lib/form_obj/form.rb', line 18
def array_class
Array
end
|
.attribute_class ⇒ Object
26
27
28
|
# File 'lib/form_obj/form.rb', line 26
def attribute_class
Attribute
end
|
.model_name ⇒ Object
30
31
32
|
# File 'lib/form_obj/form.rb', line 30
def model_name
@model_name || super
end
|
.nested_class ⇒ Object
22
23
24
|
# File 'lib/form_obj/form.rb', line 22
def nested_class
::FormObj::Form
end
|
Instance Method Details
#mark_as_persisted ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/form_obj/form.rb', line 50
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_destruction ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/form_obj/form.rb', line 58
def mark_for_destruction
@marked_for_destruction = true
self.class._attributes.each { |attr|
read_attribute(attr).mark_for_destruction if attr.subform?
}
self.persisted = false
self
end
|
#marked_for_destruction? ⇒ Boolean
67
68
69
|
# File 'lib/form_obj/form.rb', line 67
def marked_for_destruction?
@marked_for_destruction ||= false
end
|
#persisted? ⇒ Boolean
44
45
46
47
48
|
# File 'lib/form_obj/form.rb', line 44
def persisted?
@persisted && self.class._attributes.reduce(true) { |persisted, attr|
persisted && (!attr.subform? || read_attribute(attr).persisted?)
}
end
|