lib/collector/repository.rb in collector-0.0.8 vs lib/collector/repository.rb in collector-0.0.9
- old
+ new
@@ -41,23 +41,41 @@
def serialize(model)
model.attributes.with_indifferent_access
end
- # def all
- # collection.find_all.map do |document|
- # deserialize!(document)
- # end
- # end
-
def deserialize!(attributes)
attributes = attributes.with_indifferent_access
attributes["id"] = attributes.delete("_id")
deserialize(attributes)
end
def deserialize(attributes)
model.new(attributes)
+ end
+
+ def all
+ collection.find_all.map do |document|
+ deserialize!(document)
+ end
+ end
+
+ def method_missing(method_sym, *arguments, &block)
+ if method_sym.to_s =~ /^find_by_(.*)$/
+ collection.find($1.to_sym => arguments.first).map do |document|
+ deserialize!(document)
+ end
+ else
+ super
+ end
+ end
+
+ def respond_to?(method_sym, include_private = false)
+ if method_sym.to_s =~ /^find_by_(.*)$/
+ true
+ else
+ super
+ end
end
end
end