Class: Ion::Search
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #each(&blk) ⇒ Object
- #ids ⇒ Object
-
#initialize(options, &blk) ⇒ Search
constructor
A new instance of Search.
- #key ⇒ Object
-
#model ⇒ Object
Returns the model.
- #range(args = nil) ⇒ Object
-
#search_hash ⇒ Object
Returns a unique hash for the search.
- #size ⇒ Object
- #sort_by(what) ⇒ Object
- #to_a ⇒ Object
- #yieldie(&blk) ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/ion/search.rb', line 4 def @options end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
5 6 7 |
# File 'lib/ion/search.rb', line 5 def scope @scope end |
Instance Method Details
#each(&blk) ⇒ Object
52 53 54 |
# File 'lib/ion/search.rb', line 52 def each(&blk) to_a.each &blk end |
#ids ⇒ Object
68 69 70 |
# File 'lib/ion/search.rb', line 68 def ids @scope.ids range end |
#key ⇒ Object
72 73 74 |
# File 'lib/ion/search.rb', line 72 def key @scope.key end |
#model ⇒ Object
Returns the model.
18 19 20 |
# File 'lib/ion/search.rb', line 18 def model @options.model end |
#range(args = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ion/search.rb', line 28 def range(args=nil) @range = if args == :all nil elsif args.is_a?(Range) args elsif !args.is_a?(Hash) @range elsif args[:from] && args[:limit] ((args[:from]-1)..(args[:from]-1 + args[:limit]-1)) elsif args[:page] && args[:limit] (((args[:page]-1)*args[:limit])..((args[:page])*args[:limit])) elsif args[:from] && args[:to] ((args[:from]-1)..(args[:to]-1)) elsif args[:from] ((args[:from]-1)..-1) else @range end || (0..-1) end |
#search_hash ⇒ Object
Returns a unique hash for the search.
23 24 25 26 |
# File 'lib/ion/search.rb', line 23 def search_hash require 'digest' Digest::MD5.hexdigest @scope.search_hash.inspect end |
#size ⇒ Object
56 57 58 |
# File 'lib/ion/search.rb', line 56 def size @scope.count end |
#sort_by(what) ⇒ Object
64 65 66 |
# File 'lib/ion/search.rb', line 64 def sort_by(what) @scope.sort_by what end |
#to_a ⇒ Object
48 49 50 |
# File 'lib/ion/search.rb', line 48 def to_a ids.map &model end |
#yieldie(&blk) ⇒ Object
60 61 62 |
# File 'lib/ion/search.rb', line 60 def yieldie(&blk) @scope.yieldie &blk end |