Method: Sohm::Model#to_hash

Defined in:
lib/sohm.rb

#to_hashObject

Export the ID of the model. The approach of Ohm is to whitelist public attributes, as opposed to exporting each (possibly sensitive) attribute.

Example:

class User < Sohm::Model
  attribute :name
end

u = User.create(:name => "John")
u.to_hash
# => { :id => "1" }

In order to add additional attributes, you can override ‘to_hash`:

class User < Sohm::Model
  attribute :name

  def to_hash
    super.merge(:name => name)
  end
end

u = User.create(:name => "John")
u.to_hash
# => { :id => "1", :name => "John" }


1064
1065
1066
1067
1068
1069
# File 'lib/sohm.rb', line 1064

def to_hash
  attrs = {}
  attrs[:id] = id unless new?

  return attrs
end