Created
March 4, 2010 09:41
-
-
Save tomafro/321584 to your computer and use it in GitHub Desktop.
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
class Pumphouse::Model | |
extend ActiveModel::Naming | |
def self.connection=(*args) | |
@connection = Cassandra.new(*args) | |
end | |
def self.connection | |
@connection | |
end | |
def self.load(key) | |
attributes = Pumphouse::Model.connection.get(model_name, key) | |
instantiate(key, attributes) if attributes | |
end | |
def initialize(attributes) | |
@attributes = attributes | |
@key = UUID.new.to_guid | |
end | |
def self.instantiate(key, attributes) | |
returning allocate do |object| | |
object.instance_variable_set("@key", key) | |
object.instance_variable_set("@attributes", attributes) | |
end | |
end | |
def attributes | |
@attributes | |
end | |
def save | |
returning @key do | |
Pumphouse::Model.connection.insert(self.class.model_name, @key.to_s, attributes, {}) | |
end | |
end | |
end |
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
Pumphouse::Model.connection = 'Pumphouse' | |
class Vegetable < Pumphouse::Model | |
end | |
key = Vegetable.new(:name => 'Aubergine').save | |
Vegetable.find(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment