Class: MassiveRecord::Wrapper::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/massive_record/wrapper/scanner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
# 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
  @created_at = opts[:created_at].to_s
  @limit = opts[:limit] || 10
end

Instance Attribute Details

#column_family_namesObject

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

#connectionObject

Returns the value of attribute connection.



5
6
7
# File 'lib/massive_record/wrapper/scanner.rb', line 5

def connection
  @connection
end

#created_atObject

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_namesObject

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

#limitObject

Returns the value of attribute limit.



6
7
8
# File 'lib/massive_record/wrapper/scanner.rb', line 6

def limit
  @limit
end

#opened_scannerObject

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_keyObject

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_nameObject

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

#closeObject



28
29
30
# File 'lib/massive_record/wrapper/scanner.rb', line 28

def close
  connection.scannerClose(opened_scanner)
end

#fetch_rows(opts = {}) ⇒ Object



36
37
38
# File 'lib/massive_record/wrapper/scanner.rb', line 36

def fetch_rows(opts = {})
  populate_rows(fetch_trows(opts))
end

#fetch_trows(opts = {}) ⇒ Object



32
33
34
# File 'lib/massive_record/wrapper/scanner.rb', line 32

def fetch_trows(opts = {})
  connection.scannerGetList(opened_scanner, limit)
end

#openObject



20
21
22
23
24
25
26
# File 'lib/massive_record/wrapper/scanner.rb', line 20

def open
  if created_at.empty?
    self.opened_scanner = connection.scannerOpen(table_name, start_key, formatted_column_family_names)
  else
    self.opened_scanner = connection.scannerOpenTs(table_name, start_key, formatted_column_family_names, created_at)
  end
end

#populate_row(result) ⇒ Object



44
45
46
# File 'lib/massive_record/wrapper/scanner.rb', line 44

def populate_row(result)
  Row.populate_from_trow_result(result, connection, table_name, column_family_names)
end

#populate_rows(results) ⇒ Object



40
41
42
# File 'lib/massive_record/wrapper/scanner.rb', line 40

def populate_rows(results)
  results.collect{|result| populate_row(result)}
end