Module: Ambry::ActiveModel::InstanceMethods
- Defined in:
- lib/ambry/active_model.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #destroy ⇒ Object
- #initialize(*args) ⇒ Object
- #keys ⇒ Object
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #save ⇒ Object
- #save! ⇒ Object
- #to_key ⇒ Object
- #to_model ⇒ Object
- #to_param ⇒ Object
- #to_partial_path ⇒ Object
- #update_attributes(*args) ⇒ Object
Instance Method Details
#attributes ⇒ Object
75 76 77 78 79 |
# File 'lib/ambry/active_model.rb', line 75 def attributes hash = to_hash hash.keys.each {|k| hash[k.to_s] = hash.delete(k)} hash end |
#destroy ⇒ Object
121 122 123 |
# File 'lib/ambry/active_model.rb', line 121 def destroy run_callbacks(:destroy) { delete } end |
#initialize(*args) ⇒ Object
70 71 72 73 |
# File 'lib/ambry/active_model.rb', line 70 def initialize(*args) @new_record = true super end |
#keys ⇒ Object
81 82 83 |
# File 'lib/ambry/active_model.rb', line 81 def keys self.class.attribute_names end |
#new_record? ⇒ Boolean
89 90 91 |
# File 'lib/ambry/active_model.rb', line 89 def new_record? @new_record end |
#persisted? ⇒ Boolean
93 94 95 |
# File 'lib/ambry/active_model.rb', line 93 def persisted? !new_record? end |
#save ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/ambry/active_model.rb', line 97 def save return false unless valid? run_callbacks(:save) do @new_record = false super end end |
#save! ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/ambry/active_model.rb', line 105 def save! if !valid? raise Ambry::AmbryError, errors.to_a.join(", ") else save end end |
#to_key ⇒ Object
117 118 119 |
# File 'lib/ambry/active_model.rb', line 117 def to_key [to_param] if persisted? end |
#to_model ⇒ Object
85 86 87 |
# File 'lib/ambry/active_model.rb', line 85 def to_model self end |
#to_param ⇒ Object
113 114 115 |
# File 'lib/ambry/active_model.rb', line 113 def to_param to_id if persisted? end |
#to_partial_path ⇒ Object
129 130 131 |
# File 'lib/ambry/active_model.rb', line 129 def to_partial_path "#{self.class.name.pluralize.underscore}/#{self.class.name.underscore}" end |
#update_attributes(*args) ⇒ Object
125 126 127 |
# File 'lib/ambry/active_model.rb', line 125 def update_attributes(*args) run_callbacks(:save) { update(*args) } end |