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 |
# File 'lib/objective_form/base.rb', line 8 def initialize(attributes = {}) attributes.each do |name, value| send("#{name}=", value) end pseudo_relations.each do |rel| instance_variable_set("@#{rel.name}", []) unless send(rel.name) end end |
Class Method Details
.attribute(name, klass_or_proc = String) ⇒ Object
62 63 64 65 |
# File 'lib/objective_form/base.rb', line 62 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
57 58 59 60 |
# File 'lib/objective_form/base.rb', line 57 def has_many(name, pseudo_record) store_relation(name, pseudo_record) define_relation_accessors(name, pseudo_record) end |
Instance Method Details
#persist! ⇒ Object
31 32 33 |
# File 'lib/objective_form/base.rb', line 31 def persist! raise NotImplementedError end |
#persisted? ⇒ Boolean
18 19 20 |
# File 'lib/objective_form/base.rb', line 18 def persisted? false end |
#save ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/objective_form/base.rb', line 22 def save if valid? persist! true else false end end |