Module: Slingshot::Model::Persistence::Finders::ClassMethods
- Defined in:
- lib/slingshot/model/persistence/finders.rb
Instance Method Summary collapse
Instance Method Details
#all ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/slingshot/model/persistence/finders.rb', line 34 def all # TODO: Options like `sort`; Possibly `filters` old_wrapper = Slingshot::Configuration.wrapper Slingshot::Configuration.wrapper self s = Slingshot::Search::Search.new(index_name).query { all } s.perform.results ensure Slingshot::Configuration.wrapper old_wrapper end |
#find(*args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/slingshot/model/persistence/finders.rb', line 10 def find *args # TODO: Options like `sort` old_wrapper = Slingshot::Configuration.wrapper Slingshot::Configuration.wrapper self = args.pop if args.last.is_a?(Hash) args.flatten! if args.size > 1 Slingshot::Search::Search.new(index.name).query do |query| query.ids(args, document_type) end.perform.results else case args = args.pop when Fixnum, String Index.new(index_name).retrieve document_type, args when :all, :first send(args) else raise ArgumentError, "Please pass either ID as Fixnum or String, or :all, :first as an argument" end end ensure Slingshot::Configuration.wrapper old_wrapper end |
#first ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/slingshot/model/persistence/finders.rb', line 44 def first # TODO: Options like `sort`; Possibly `filters` old_wrapper = Slingshot::Configuration.wrapper Slingshot::Configuration.wrapper self s = Slingshot::Search::Search.new(index_name).query { all }.size(1) s.perform.results.first ensure Slingshot::Configuration.wrapper old_wrapper end |