Created
August 20, 2010 00:17
-
-
Save nchapman/539280 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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