module Rethinker::Document::Selection::ClassMethods
Public Instance Methods
all()
click to toggle source
# File lib/rethinker/document/selection.rb, line 9 def all sel = Rethinker::Selection.new(Rethinker::Criterion.new(:table, table_name), :klass => self) unless is_root_class? # TODO use this: sel = sel.where(:_type.in(descendants_type_values)) sel = sel.where do |doc| doc.has_fields(:_type) & descendants_type_values.map { |type| doc[:_type].eq(type) } .reduce { |a,b| a | b } end end sel end
find(id)
click to toggle source
XXX this doesn’t have the same semantics as other ORMs. the equivalent is find!.
# File lib/rethinker/document/selection.rb, line 39 def find(id) new_from_db(selector_for(id).run) end
find!(id)
click to toggle source
# File lib/rethinker/document/selection.rb, line 43 def find!(id) find(id).tap do |doc| doc or raise Rethinker::Error::DocumentNotFound, "#{self.class} id #{id} not found" end end
scope(name, selection)
click to toggle source
# File lib/rethinker/document/selection.rb, line 24 def scope(name, selection) singleton_class.class_eval do define_method(name) { |*args| selection.call(*args) } end end
selector_for(id)
click to toggle source
# File lib/rethinker/document/selection.rb, line 32 def selector_for(id) # TODO Pass primary key if not default Rethinker::Selection.new([Rethinker::Criterion.new(:table, table_name), Rethinker::Criterion.new(:get, id)], :klass => self) end