Class: ActiveObjects
- Inherits:
-
Object
- Object
- ActiveObjects
- Includes:
- ActiveModel::Model
- Defined in:
- lib/active_objects.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attr = {}) ⇒ ActiveObjects
constructor
A new instance of ActiveObjects.
- #save ⇒ Object
- #update(attr) ⇒ Object
Constructor Details
#initialize(attr = {}) ⇒ ActiveObjects
Returns a new instance of ActiveObjects.
14 15 16 17 18 19 20 21 22 |
# File 'lib/active_objects.rb', line 14 def initialize(attr = {}) generate_attr_accessors if attr[:id].present? @object = object_class.find(attr[:id]) generate_instances_for @object else super(attr) end end |
Class Method Details
.i18n_scope ⇒ Object
5 6 7 |
# File 'lib/active_objects.rb', line 5 def i18n_scope :activerecord end |
.lookup_ancestors ⇒ Object
9 10 11 |
# File 'lib/active_objects.rb', line 9 def lookup_ancestors [new.send(:object_class)] end |
Instance Method Details
#save ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/active_objects.rb', line 24 def save if valid? persist! else false end end |
#update(attr) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/active_objects.rb', line 32 def update(attr) assign_attributes(attr) if valid? update_form! else false end end |