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
76 77 78 79 80 |
# File 'lib/ambry/active_model.rb', line 76 def attributes hash = to_hash hash.keys.each {|k| hash[k.to_s] = hash.delete(k)} hash end |
#destroy ⇒ Object
122 123 124 |
# File 'lib/ambry/active_model.rb', line 122 def destroy run_callbacks(:destroy) { delete } end |
#initialize(*args) ⇒ Object
71 72 73 74 |
# File 'lib/ambry/active_model.rb', line 71 def initialize(*args) @new_record = true super end |
#keys ⇒ Object
82 83 84 |
# File 'lib/ambry/active_model.rb', line 82 def keys self.class.attribute_names end |
#new_record? ⇒ Boolean
90 91 92 |
# File 'lib/ambry/active_model.rb', line 90 def new_record? @new_record end |
#persisted? ⇒ Boolean
94 95 96 |
# File 'lib/ambry/active_model.rb', line 94 def persisted? !new_record? end |
#save ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/ambry/active_model.rb', line 98 def save return false unless valid? run_callbacks(:save) do @new_record = false super end end |
#save! ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/ambry/active_model.rb', line 106 def save! if !valid? raise Ambry::AmbryError, errors.to_a.join(", ") else save end end |
#to_key ⇒ Object
118 119 120 |
# File 'lib/ambry/active_model.rb', line 118 def to_key [to_param] if persisted? end |
#to_model ⇒ Object
86 87 88 |
# File 'lib/ambry/active_model.rb', line 86 def to_model self end |
#to_param ⇒ Object
114 115 116 |
# File 'lib/ambry/active_model.rb', line 114 def to_param to_id if persisted? end |
#to_partial_path ⇒ Object
130 131 132 |
# File 'lib/ambry/active_model.rb', line 130 def to_partial_path "#{self.class.name.pluralize.underscore}/#{self.class.name.underscore}" end |
#update_attributes(*args) ⇒ Object
126 127 128 |
# File 'lib/ambry/active_model.rb', line 126 def update_attributes(*args) run_callbacks(:save) { update(*args) } end |