Created
July 21, 2011 06:06
-
-
Save guilleiguaran/1096606 to your computer and use it in GitHub Desktop.
Ohm::ActiveModelCompliant, allows to Ohm (Redis OHM) to be partially compliant with ActiveModel (except errors)
This file contains 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
require 'active_model' | |
module Ohm | |
module ActiveModelCompliant | |
def self.included(base) | |
base.send(:extend, ActiveModel::Naming) | |
base.send(:include, ActiveModel::Conversion) | |
base.send(:include, InstanceMethods) | |
end | |
module InstanceMethods | |
def to_key | |
self.id rescue nil | |
end | |
def to_param | |
self.id.to_s rescue nil | |
end | |
def persisted? | |
!self.new? | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment