0
@@ -137,7 +137,7 @@ module Stone
0
def has_many(resource, *args)
0
self.class_eval <<-EOS, __FILE__, __LINE__
0
- #{resource.to_s.singularize.titlecase}.all("#{self.to_s.downcase}_id
== "+self.id.to_s)
0
+ #{resource.to_s.singularize.titlecase}.all("#{self.to_s.downcase}_id
".to_sym.equals => self.id)
0
@@ -233,6 +233,9 @@ module Stone
0
+ # Puts the attribute changes in +hash+
0
+ # +hash+:: the attributes to change
0
def update_attributes(hash)
0
@@ -278,12 +281,13 @@ module Stone
0
if field[:unique] == true
0
- return false if self.class.first(
"#{field[:name]} == '#{self.send(field[:name])}'") && !self.already_exists?
0
+ return false if self.class.first(
field[:name] => self.send(field[:name])) && !self.already_exists?
0
+ # Finds out if the object is already in the current DataStore instance
0
DataStore.determine_save_method(self, @@store) == :put
0
@@ -332,22 +336,30 @@ module Stone
0
def find(conditions, key) #:doc:
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
+ unless conditions.to_a.flatten.map {|e| e.is_a? Query}.include?(true)
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)
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
+ raise "Resource.find expects a Hash, got a #{conditions.class}"
0
+ # Checks the list of fields for a given +klass+ to see if +field+
0
+ # +field+:: The field to look for
0
+ # +klass+:: The class to look in
0
def field_declared?(field,klass)
0
@@fields[klass.to_s.make_key].each do |f|
0
return true if f[:name] == field
0
@@ -381,43 +393,15 @@ module Stone
0
- # Accepts +conditions+ like
0
- # "name.include?('nick') && email == 'nick@bzzybee.com"
0
- # and turns them into an +ary+ of expressions and their conditionals
0
- # +conditions+:: The plain string conditions
0
- def parse_conditions(conditions) #:doc:
0
- # Facets breaks for some reason on single condition expressions
0
- # e.g. "name == 'Nick DeMonner'"
0
- # but not on multiple ones like
0
- # "name == 'Nick DeMonner' && blah.include?('blah')"
0
- expr = conditions.split(/\s+&{2}|\|{2}\s+/)
0
- op = conditions.scan(/&{2}|\|{2}/)
0
- expr.each_with_index do |e,i|
0
- # convert each expr into an obj.meth(arg) format
0
- # so that name == 'nick' becomes name.==('nick')
0
- ary.each_with_index do |e,i|
0
- if i % 2 == 0 && e.split.size != 1 && !e.match(/.+(.+)/)
0
- expr_ary[0] = expr_ary[0] + "."
0
- expr_ary[1] = expr_ary[1] + "("
0
- if expr_ary.size % 2 == 0
0
- expr_ary[expr_ary.size-1] = " " + expr_ary[expr_ary.size-1] + ")"
0
- expr_ary[expr_ary.size-1] = expr_ary[expr_ary.size-1] + ")"
0
- ary[i] = expr_ary.join
0
+ # Turns conditions into a set of expressions that can be evaluated
0
+ def parse_conditions(hash)
0
+ conds << k.expression_for(v)