Module: Norman::ActiveModel::InstanceMethods
- Defined in:
- lib/norman/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
- #update_attributes ⇒ Object
Instance Method Details
#attributes ⇒ Object
68 69 70 71 72 |
# File 'lib/norman/active_model.rb', line 68 def attributes hash = to_hash hash.keys.each {|k| hash[k.to_s] = hash.delete(k)} hash end |
#destroy ⇒ Object
113 114 115 |
# File 'lib/norman/active_model.rb', line 113 def destroy run_callbacks(:destroy) { delete } end |
#initialize(*args) ⇒ Object
63 64 65 66 |
# File 'lib/norman/active_model.rb', line 63 def initialize(*args) @new_record = true super end |
#keys ⇒ Object
74 75 76 |
# File 'lib/norman/active_model.rb', line 74 def keys self.class.attribute_names end |
#new_record? ⇒ Boolean
82 83 84 |
# File 'lib/norman/active_model.rb', line 82 def new_record? @new_record end |
#persisted? ⇒ Boolean
86 87 88 |
# File 'lib/norman/active_model.rb', line 86 def persisted? !new_record? end |
#save ⇒ Object
90 91 92 93 94 95 |
# File 'lib/norman/active_model.rb', line 90 def save run_callbacks(:save) do @new_record = false super end end |
#save! ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/norman/active_model.rb', line 97 def save! if !valid? raise Norman::NormanError, errors.to_a.join(", ") else save end end |
#to_key ⇒ Object
109 110 111 |
# File 'lib/norman/active_model.rb', line 109 def to_key [to_param] if persisted? end |
#to_model ⇒ Object
78 79 80 |
# File 'lib/norman/active_model.rb', line 78 def to_model self end |
#to_param ⇒ Object
105 106 107 |
# File 'lib/norman/active_model.rb', line 105 def to_param to_id if persisted? end |
#update_attributes ⇒ Object
117 118 119 |
# File 'lib/norman/active_model.rb', line 117 def update_attributes run_callbacks(:save) { update } end |