Class: Tarantool::BaseRecord::Select
- Inherits:
-
Object
- Object
- Tarantool::BaseRecord::Select
- Includes:
- Enumerable
- Defined in:
- lib/tarantool/record/select.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #all ⇒ Object (also: #to_a)
- #auto_shard ⇒ Object
- #call(*args) ⇒ Object
- #each ⇒ Object
- #first ⇒ Object
-
#initialize(record, params = {}) ⇒ Select
constructor
A new instance of Select.
- #limit(limit) ⇒ Object
- #offset(offset) ⇒ Object
- #reset! ⇒ Object
- #results ⇒ Object
- #shard(params) ⇒ Object
- #space ⇒ Object
- #space_no ⇒ Object
- #where(params) ⇒ Object
Constructor Details
#initialize(record, params = {}) ⇒ Select
Returns a new instance of Select.
7 8 9 10 |
# File 'lib/tarantool/record/select.rb', line 7 def initialize(record, params={}) @record = record @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/tarantool/record/select.rb', line 6 def params @params end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
6 7 8 |
# File 'lib/tarantool/record/select.rb', line 6 def record @record end |
Instance Method Details
#all ⇒ Object Also known as: to_a
63 64 65 |
# File 'lib/tarantool/record/select.rb', line 63 def all results.dup end |
#auto_shard ⇒ Object
57 58 59 60 61 |
# File 'lib/tarantool/record/select.rb', line 57 def auto_shard params = @params.dup params.delete :shard self.class.new(@record, params) end |
#call(*args) ⇒ Object
37 38 39 |
# File 'lib/tarantool/record/select.rb', line 37 def call(*args) @record.call(*args) end |
#each ⇒ Object
32 33 34 35 |
# File 'lib/tarantool/record/select.rb', line 32 def each return to_enum unless block_given? results.each{|a| yield a} end |
#first ⇒ Object
68 69 70 |
# File 'lib/tarantool/record/select.rb', line 68 def first space.select(@params[:where], @params[:offset] || 0, 1).first end |
#limit(limit) ⇒ Object
41 42 43 |
# File 'lib/tarantool/record/select.rb', line 41 def limit(limit) self.class.new(@record, @params.merge(limit: limit)) end |
#offset(offset) ⇒ Object
45 46 47 |
# File 'lib/tarantool/record/select.rb', line 45 def offset(offset) self.class.new(@record, @params.merge(offset: offset)) end |
#reset! ⇒ Object
27 28 29 30 |
# File 'lib/tarantool/record/select.rb', line 27 def reset! @results = nil self end |
#results ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tarantool/record/select.rb', line 16 def results @results ||= begin raise "Condition is not set" unless @params[:where] @record.auto_space.select( @params[:where], @params[:offset] || 0, @params[:limit] || -1 ) end end |
#shard(params) ⇒ Object
53 54 55 |
# File 'lib/tarantool/record/select.rb', line 53 def shard(params) self.class.new(@record, @params.merge(shard: params)) end |
#space ⇒ Object
72 73 74 75 |
# File 'lib/tarantool/record/select.rb', line 72 def space space = @record.auto_space @params[:shard] ? space.shard(@params[:shard]) : space end |
#space_no ⇒ Object
12 13 14 |
# File 'lib/tarantool/record/select.rb', line 12 def space_no @record.space_no end |
#where(params) ⇒ Object
49 50 51 |
# File 'lib/tarantool/record/select.rb', line 49 def where(params) self.class.new(@record, @params.merge(where: params)) end |