Class: ObjectiveForm::Base
- Inherits:
-
Object
- Object
- ObjectiveForm::Base
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- lib/objective_form/base.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
- #persist! ⇒ Object
- #persisted? ⇒ Boolean
- #save ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/objective_form/base.rb', line 8 def initialize(attributes = {}) attributes.each do |name, value| send("#{name}=", value) end unless pseudo_relations.nil? pseudo_relations.each do |rel| instance_variable_set("@#{rel.name}", []) unless send(rel.name) end end end |
Class Method Details
.attribute(name, klass_or_proc = String) ⇒ Object
64 65 66 67 |
# File 'lib/objective_form/base.rb', line 64 def attribute(name, klass_or_proc = String) store_attribute(name, klass_or_proc) define_attribute_accessors(name, klass_or_proc) end |
.has_many(name, pseudo_record) ⇒ Object
59 60 61 62 |
# File 'lib/objective_form/base.rb', line 59 def has_many(name, pseudo_record) store_relation(name, pseudo_record) define_relation_accessors(name, pseudo_record) end |
Instance Method Details
#persist! ⇒ Object
33 34 35 |
# File 'lib/objective_form/base.rb', line 33 def persist! raise NotImplementedError end |
#persisted? ⇒ Boolean
20 21 22 |
# File 'lib/objective_form/base.rb', line 20 def persisted? false end |
#save ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/objective_form/base.rb', line 24 def save if valid? persist! true else false end end |