Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Created July 21, 2011 06:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilleiguaran/1096606 to your computer and use it in GitHub Desktop.
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)
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