Class: ActiveGroonga::ResultSet
- Inherits:
-
Object
- Object
- ActiveGroonga::ResultSet
- Includes:
- Enumerable
- Defined in:
- lib/active_groonga/result_set.rb
Defined Under Namespace
Modules: PaginationProxy
Instance Attribute Summary (collapse)
-
- (Object) expression
readonly
Returns the value of attribute expression.
-
- (Object) n_records
readonly
Returns the value of attribute n_records.
-
- (Object) records
readonly
Returns the value of attribute records.
Instance Method Summary (collapse)
- - (Object) each
-
- (Boolean) empty?
この結果セットがレコードを持っているかどうかを返します。.
- - (Object) group(key)
-
- (ResultSet) initialize(records, klass, options = {})
constructor
A new instance of ResultSet.
-
- (Object) paginate(sort_keys = nil, options = {})
結果セットをページネーションします。.
-
- (Object) sort(keys = nil, options = {})
結果セットをソートします。.
Constructor Details
- (ResultSet) initialize(records, klass, options = {})
Returns a new instance of ResultSet
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_groonga/result_set.rb', line 21 def initialize(records, klass, ={}) @records = records @klass = klass @groups = {} @expression = [:expression] if @expression.nil? and @records.respond_to?(:expression) @expression = @records.expression end @n_records = [:n_records] || @records.size @default_sort_keys = [:default_sort_keys] @default_limit = [:default_limit] compute_n_key_nested end |
Instance Attribute Details
- (Object) expression (readonly)
Returns the value of attribute expression
20 21 22 |
# File 'lib/active_groonga/result_set.rb', line 20 def expression @expression end |
- (Object) n_records (readonly)
Returns the value of attribute n_records
20 21 22 |
# File 'lib/active_groonga/result_set.rb', line 20 def n_records @n_records end |
- (Object) records (readonly)
Returns the value of attribute records
20 21 22 |
# File 'lib/active_groonga/result_set.rb', line 20 def records @records end |
Instance Method Details
- (Object) each
152 153 154 155 156 157 158 |
# File 'lib/active_groonga/result_set.rb', line 152 def each @records.each do |record| object = instantiate(record) next if object.nil? yield(object) end end |
- (Boolean) empty?
この結果セットがレコードを持っているかどうかを返します。
164 165 166 |
# File 'lib/active_groonga/result_set.rb', line 164 def empty? records.empty? end |
- (Object) group(key)
148 149 150 |
# File 'lib/active_groonga/result_set.rb', line 148 def group(key) @groups[key] ||= @records.group(key) end |
- (ResultSet) paginate(sort_keys, options = {}) - (ResultSet) paginate(options = {})
結果セットをページネーションします。
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/active_groonga/result_set.rb', line 80 def paginate(sort_keys=nil, ={}) if sort_keys.is_a?(Hash) and .empty? = sort_keys sort_keys = nil end [:size] = normalize_limit([:size]) [:page] = normalize_page([:page]) sort_keys = normalize_sort_keys(sort_keys) records = @records.paginate(sort_keys, ) set = create_result_set(records) set.extend(PaginationProxy) set end |
- (ResultSet) sort(keys, options = {}) - (ResultSet) sort(options = {})
結果セットをソートします。
138 139 140 141 142 143 144 145 146 |
# File 'lib/active_groonga/result_set.rb', line 138 def sort(keys=nil, ={}) if keys.is_a?(Hash) and .empty? = keys keys = nil end keys = normalize_sort_keys(keys) [:limit] = normalize_limit([:limit]) || @n_records create_result_set(@records.sort(keys, )) end |