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
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_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

#offset_keyObject

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_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



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

#keyObject



21
22
23
# File 'lib/massive_record/wrapper/scanner.rb', line 21

def key
  start_key.empty? ? offset_key : start_key
end

#openObject



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