Skip to content

Instantly share code, notes, and snippets.

@the-architect
Created February 14, 2013 14:16
Show Gist options
  • Save the-architect/4953099 to your computer and use it in GitHub Desktop.
Save the-architect/4953099 to your computer and use it in GitHub Desktop.
Simple object attributes that are persisted in couchbase.
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