Class: FormObj::Form
- Inherits:
-
TreeStruct
- Object
- TreeStruct
- FormObj::Form
- Extended by:
- ActiveModel::Naming, ActiveModel::Translation
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- lib/form_obj/form.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#persisted ⇒ Object
Returns the value of attribute persisted.
Class Method Summary collapse
Instance Method Summary collapse
- #_set_attribute_value(attribute, value) ⇒ Object
-
#initialize ⇒ Form
constructor
A new instance of Form.
- #persisted? ⇒ Boolean
- #primary_key ⇒ Object
- #primary_key=(val) ⇒ Object
- #saved ⇒ Object
- #update_attributes(new_attrs, raise_if_not_found: true) ⇒ Object
Constructor Details
#initialize ⇒ Form
Returns a new instance of Form.
48 49 50 51 |
# File 'lib/form_obj/form.rb', line 48 def initialize() @errors = ActiveModel::Errors.new(self) @persisted = false end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
35 36 37 |
# File 'lib/form_obj/form.rb', line 35 def errors @errors end |
#persisted ⇒ Object
Returns the value of attribute persisted.
34 35 36 |
# File 'lib/form_obj/form.rb', line 34 def persisted @persisted end |
Class Method Details
.array_class ⇒ Object
22 23 24 |
# File 'lib/form_obj/form.rb', line 22 def self.array_class Array end |
.attribute_class ⇒ Object
30 31 32 |
# File 'lib/form_obj/form.rb', line 30 def self.attribute_class Attribute end |
.model_name ⇒ Object
44 45 46 |
# File 'lib/form_obj/form.rb', line 44 def self.model_name @model_name || super end |
.nested_class ⇒ Object
26 27 28 |
# File 'lib/form_obj/form.rb', line 26 def self.nested_class ::TreeStruct end |
Instance Method Details
#_set_attribute_value(attribute, value) ⇒ Object
57 58 59 60 |
# File 'lib/form_obj/form.rb', line 57 def _set_attribute_value(attribute, value) @persisted = false super end |
#persisted? ⇒ Boolean
53 54 55 |
# File 'lib/form_obj/form.rb', line 53 def persisted? @persisted end |
#primary_key ⇒ Object
62 63 64 |
# File 'lib/form_obj/form.rb', line 62 def primary_key send(self.class.primary_key) end |
#primary_key=(val) ⇒ Object
66 67 68 |
# File 'lib/form_obj/form.rb', line 66 def primary_key=(val) send("#{self.class.primary_key}=", val) end |
#saved ⇒ Object
87 88 89 90 |
# File 'lib/form_obj/form.rb', line 87 def saved @persisted = true self end |
#update_attributes(new_attrs, raise_if_not_found: true) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/form_obj/form.rb', line 70 def update_attributes(new_attrs, raise_if_not_found: true) new_attrs.each_pair do |new_attr, new_val| attr = self.class._attributes.find(new_attr) if attr.nil? raise UnknownAttributeError.new(new_attr) if raise_if_not_found else if attr.subform? self.send(new_attr).update_attributes(new_val) else self.send("#{new_attr}=", new_val) end end end self end |