Class: MassiveRecord::Wrapper::Scanner
- Inherits:
-
Object
- Object
- MassiveRecord::Wrapper::Scanner
- Defined in:
- lib/massive_record/wrapper/scanner.rb
Instance Attribute Summary collapse
-
#column_family_names ⇒ Object
Returns the value of attribute column_family_names.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#formatted_column_family_names ⇒ Object
Returns the value of attribute formatted_column_family_names.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#offset_key ⇒ Object
Returns the value of attribute offset_key.
-
#opened_scanner ⇒ Object
Returns the value of attribute opened_scanner.
-
#start_key ⇒ Object
Returns the value of attribute start_key.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Instance Method Summary collapse
- #close ⇒ Object
- #fetch_rows(opts = {}) ⇒ Object
- #fetch_trows(opts = {}) ⇒ Object
-
#initialize(connection, table_name, column_family_names, opts = {}) ⇒ Scanner
constructor
A new instance of Scanner.
- #key ⇒ Object
- #open ⇒ Object
- #populate_row(result) ⇒ Object
- #populate_rows(results) ⇒ Object
Constructor Details
#initialize(connection, table_name, column_family_names, opts = {}) ⇒ Scanner
Returns a new instance of Scanner.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/massive_record/wrapper/scanner.rb', line 9 def initialize(connection, table_name, column_family_names, opts = {}) @connection = connection @table_name = table_name @column_family_names = column_family_names.collect{|n| n.split(":").first} @column_family_names = opts[:columns] unless opts[:columns].nil? @formatted_column_family_names = column_family_names.collect{|n| "#{n.split(":").first}:"} @start_key = opts[:start_key].to_s @offset_key = opts[:offset_key].to_s @created_at = opts[:created_at].to_s @limit = opts[:limit] || 10 end |
Instance Attribute Details
#column_family_names ⇒ Object
Returns the value of attribute column_family_names.
5 6 7 |
# File 'lib/massive_record/wrapper/scanner.rb', line 5 def column_family_names @column_family_names end |
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/massive_record/wrapper/scanner.rb', line 5 def connection @connection end |
#created_at ⇒ Object
Returns the value of attribute created_at.
6 7 8 |
# File 'lib/massive_record/wrapper/scanner.rb', line 6 def created_at @created_at end |
#formatted_column_family_names ⇒ Object
Returns the value of attribute formatted_column_family_names.
7 8 9 |
# File 'lib/massive_record/wrapper/scanner.rb', line 7 def formatted_column_family_names @formatted_column_family_names end |
#limit ⇒ Object
Returns the value of attribute limit.
6 7 8 |
# File 'lib/massive_record/wrapper/scanner.rb', line 6 def limit @limit end |
#offset_key ⇒ Object
Returns the value of attribute offset_key.
6 7 8 |
# File 'lib/massive_record/wrapper/scanner.rb', line 6 def offset_key @offset_key end |
#opened_scanner ⇒ Object
Returns the value of attribute opened_scanner.
5 6 7 |
# File 'lib/massive_record/wrapper/scanner.rb', line 5 def opened_scanner @opened_scanner end |
#start_key ⇒ Object
Returns the value of attribute start_key.
6 7 8 |
# File 'lib/massive_record/wrapper/scanner.rb', line 6 def start_key @start_key end |
#table_name ⇒ Object
Returns the value of attribute table_name.
5 6 7 |
# File 'lib/massive_record/wrapper/scanner.rb', line 5 def table_name @table_name end |
Instance Method Details
#close ⇒ Object
33 34 35 |
# File 'lib/massive_record/wrapper/scanner.rb', line 33 def close connection.scannerClose(opened_scanner) end |
#fetch_rows(opts = {}) ⇒ Object
41 42 43 |
# File 'lib/massive_record/wrapper/scanner.rb', line 41 def fetch_rows(opts = {}) populate_rows(fetch_trows(opts)) end |
#fetch_trows(opts = {}) ⇒ Object
37 38 39 |
# File 'lib/massive_record/wrapper/scanner.rb', line 37 def fetch_trows(opts = {}) connection.scannerGetList(opened_scanner, limit) end |
#key ⇒ Object
21 22 23 |
# File 'lib/massive_record/wrapper/scanner.rb', line 21 def key start_key.empty? ? offset_key : start_key end |
#open ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/massive_record/wrapper/scanner.rb', line 25 def open if created_at.empty? self.opened_scanner = connection.scannerOpen(table_name, key, formatted_column_family_names) else self.opened_scanner = connection.scannerOpenTs(table_name, key, formatted_column_family_names, created_at) end end |
#populate_row(result) ⇒ Object
55 56 57 |
# File 'lib/massive_record/wrapper/scanner.rb', line 55 def populate_row(result) Row.populate_from_trow_result(result, connection, table_name, column_family_names) end |
#populate_rows(results) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/massive_record/wrapper/scanner.rb', line 45 def populate_rows(results) results.collect do |result| if offset_key.empty? populate_row(result) unless result.row.match(/^#{start_key}/).nil? else populate_row(result) end end.select{|r| !r.nil?} end |