Class: CaringForm::Model
- Inherits:
-
Object
- Object
- CaringForm::Model
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations, ActiveRecord::Validations
- Defined in:
- lib/caring_form/model.rb,
lib/caring_form/model/active_model.rb,
lib/caring_form/model/active_record.rb
Constant Summary collapse
- INHERITED_ATTRIBUTES =
[:url, :id, :classes]
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
Class Method Summary collapse
- .human_attribute_name(attribute) ⇒ Object
- .human_name ⇒ Object
- .inherited(klass) ⇒ Object
- .self_and_descendants_from_active_record ⇒ Object
Instance Method Summary collapse
- #after_initialize ⇒ Object
-
#initialize(attributes = {}) ⇒ Model
constructor
attributes can be scoped within key of the name of the class (posted form) or a flat hash of attributes.
- #new_record? ⇒ Boolean
- #normalize_attribute_value(name, value) ⇒ Object
- #persisted? ⇒ Boolean
- #save ⇒ Object
- #save! ⇒ Object
- #update_attribute ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Model
attributes can be scoped within key of the name of the class (posted form) or a flat hash of attributes
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/caring_form/model.rb', line 16 def initialize(attributes = {}) flatten_attributes(attributes).each do |name, value| send("#{name}=", normalize_attribute_value(name, value)) if respond_to?(name) end (INHERITED_ATTRIBUTES - attributes.keys).each do |name| value = self.class.send(name) send("#{name}=", value) unless value.nil? end after_initialize end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
3 4 5 |
# File 'lib/caring_form/model/active_record.rb', line 3 def errors @errors end |
Class Method Details
.human_attribute_name(attribute) ⇒ Object
9 10 11 |
# File 'lib/caring_form/model/active_record.rb', line 9 def self.human_attribute_name(attribute) attribute.to_s.humanize end |
.human_name ⇒ Object
5 6 7 |
# File 'lib/caring_form/model/active_record.rb', line 5 def self.human_name to_s.humanize end |
.inherited(klass) ⇒ Object
8 9 10 11 12 |
# File 'lib/caring_form/model.rb', line 8 def self.inherited(klass) klass.instance_eval do include CaringForm::Dsl end end |
.self_and_descendants_from_active_record ⇒ Object
13 14 15 |
# File 'lib/caring_form/model/active_record.rb', line 13 def self.self_and_descendants_from_active_record [self] end |
Instance Method Details
#after_initialize ⇒ Object
27 28 29 |
# File 'lib/caring_form/model.rb', line 27 def after_initialize # override if needed end |
#new_record? ⇒ Boolean
25 26 27 |
# File 'lib/caring_form/model/active_record.rb', line 25 def new_record? true end |
#normalize_attribute_value(name, value) ⇒ Object
31 32 33 |
# File 'lib/caring_form/model.rb', line 31 def normalize_attribute_value(name, value) value end |
#persisted? ⇒ Boolean
7 8 9 |
# File 'lib/caring_form/model/active_model.rb', line 7 def persisted? false end |
#save ⇒ Object
17 18 19 |
# File 'lib/caring_form/model/active_record.rb', line 17 def save # TODO end |
#save! ⇒ Object
21 22 23 |
# File 'lib/caring_form/model/active_record.rb', line 21 def save! # TODO end |
#update_attribute ⇒ Object
29 30 |
# File 'lib/caring_form/model/active_record.rb', line 29 def update_attribute end |