0
@@ -13,23 +13,36 @@ module Stone
0
+ rsrc_sym = base.to_s.make_key
0
+ @@callbacks ||= Callbacks.new
0
+ @@callbacks.register_klass(base)
0
+ @@store ||= DataStore.new
0
base.send(:extend, self)
0
base.send(:include, ::Validatable)
0
unless base.to_s.downcase == "spec::example::examplegroup::subclass_1"
0
base.class_eval <<-EOS, __FILE__, __LINE__
0
+ def initialize
(hash = nil)0
self.id = self.next_id_for_klass(self.class)
0
+ self.send(k.to_s+"=",v)
0
+ self.send(k.to_s+"=", hash[k])
0
- rsrc_sym = base.to_s.make_key
0
- @@callbacks ||= Callbacks.new
0
- @@callbacks.register_klass(base)
0
- @@store ||= DataStore.new
0
- unless @@store.resources.include? rsrc_sym
0
+ unless @@store.resources.include?(rsrc_sym)
0
@@store.resources[rsrc_sym] = DataStore.load_data(rsrc_sym)
0
@@ -149,31 +162,6 @@ module Stone
0
def has_and_belongs_to_many(resource, *args)
0
- # Save an object to the current DataStore instance.
0
- return false unless self.fields_are_valid?
0
- return false unless self.valid?
0
- sym = DataStore.determine_save_method(self, @@store)
0
- self.class.send(sym, self)
0
- # Determines whether the field classes of a given object match the field
0
- klass_sym = self.class.to_s.make_key
0
- @@fields[klass_sym].each do |field|
0
- unless self.send(field[:name]).class == field[:klass] || self.send(field[:name]) == nil
0
- if field[:unique] == true
0
- return false if self.class.first("#{field[:name]} == '#{self.send(field[:name])}'")
0
# Returns the first object matching +conditions+, or the first object
0
# if no conditions are specified
0
@@ -245,6 +233,19 @@ module Stone
0
+ def update_attributes(hash)
0
+ self.send(k.to_s+"=",v)
0
+ self.send(k.to_s+"=", hash[k])
0
# Determine the next id number to use based on the last stored object's id
0
@@ -257,7 +258,36 @@ module Stone
0
+ # Save an object to the current DataStore instance.
0
+ return false unless self.fields_are_valid?
0
+ return false unless self.valid?
0
+ sym = DataStore.determine_save_method(self, @@store)
0
+ self.class.send(sym, self)
0
+ # Determines whether the field classes of a given object match the field
0
+ klass_sym = self.class.to_s.make_key
0
+ @@fields[klass_sym].each do |field|
0
+ unless self.send(field[:name]).class == field[:klass] || self.send(field[:name]) == nil || self.already_exists?
0
+ if field[:unique] == true
0
+ return false if self.class.first("#{field[:name]} == '#{self.send(field[:name])}'") && !self.already_exists?
0
+ DataStore.determine_save_method(self, @@store) == :put
0
# Fires the given callback in the current instance of Callbacks
0
@@ -302,9 +332,18 @@ module Stone
0
def find(conditions, key) #:doc:
0
- parsed_conditions = parse_conditions(conditions)
0
- @@store.resources[key].each do |o|
0
- objs << o[1] if matches_conditions?(o[1], parsed_conditions)
0
+ if conditions.is_a? Hash
0
+ raise "Resource.find(Hash) expects a single key, value pair" \
0
+ unless conditions.size == 1
0
+ conds = conditions.to_a.flatten
0
+ @@store.resources[key].each do |o|
0
+ objs << o[1] if o[1].send(conds[0]) == conds[1]
0
+ parsed_conditions = parse_conditions(conditions)
0
+ @@store.resources[key].each do |o|
0
+ objs << o[1] if matches_conditions?(o[1], parsed_conditions)