Module: Norman::ActiveModel::InstanceMethods

Defined in:
lib/norman/active_model.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



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

#destroyObject



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

#keysObject



74
75
76
# File 'lib/norman/active_model.rb', line 74

def keys
  self.class.attribute_names
end

#new_record?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/norman/active_model.rb', line 82

def new_record?
  @new_record
end

#persisted?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/norman/active_model.rb', line 86

def persisted?
  !new_record?
end

#saveObject



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_keyObject



109
110
111
# File 'lib/norman/active_model.rb', line 109

def to_key
  [to_param] if persisted?
end

#to_modelObject



78
79
80
# File 'lib/norman/active_model.rb', line 78

def to_model
  self
end

#to_paramObject



105
106
107
# File 'lib/norman/active_model.rb', line 105

def to_param
  to_id if persisted?
end

#update_attributesObject



117
118
119
# File 'lib/norman/active_model.rb', line 117

def update_attributes
  run_callbacks(:save) { update }
end