Skip to content

Instantly share code, notes, and snippets.

@nchapman
Created August 20, 2010 00:17
Show Gist options
  • Save nchapman/539280 to your computer and use it in GitHub Desktop.
Save nchapman/539280 to your computer and use it in GitHub Desktop.
class ActiveOhm < Ohm::Model
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
include Ohm::Boundaries
include Ohm::Callbacks
include Ohm::Timestamping
include Ohm::Typecast
attribute :created_at, Time
attribute :updated_at, Time
def self.find(target)
target.is_a?(Hash) ? super : self[target]
end
def save(perform_validation = true)
!perform_validation || valid? ? super() : false
end
def update(attributes)
valid? ? super : false
end
def destroy
delete
end
def new_record?
new?
end
def persisted?
!new?
end
def to_key
persisted? ? [self.id] : nil
end
def to_param
persisted? ? self.id.to_s : nil
end
def initialize_id
self.id = SecureRandom.hex(16)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment