Created
February 14, 2013 14:16
-
-
Save the-architect/4953099 to your computer and use it in GitHub Desktop.
Simple object attributes that are persisted in couchbase.
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
module CouchbaseAttributes | |
module ClassMethods | |
def couchbase_attribute(name) | |
class_eval %Q{ | |
def #{name}=(value) | |
Couchbase.bucket.set([couchbase_id, '#{name}'].join('::'), value) | |
end | |
def #{name} | |
Couchbase.bucket.get([couchbase_id, '#{name}'].join('::')) | |
end | |
} | |
end | |
end | |
module InstanceMethods | |
def couchbase_id | |
[self.class.name, to_param].join('::') | |
end | |
end | |
def self.included(receiver) | |
receiver.send :include, InstanceMethods | |
receiver.extend ClassMethods | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment