Class: CassandraBackup::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra_backup/importer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Importer

Returns a new instance of Importer.



8
9
10
# File 'lib/cassandra_backup/importer.rb', line 8

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/cassandra_backup/importer.rb', line 7

def config
  @config
end

Class Method Details

.run_command(command) ⇒ Object



3
4
5
# File 'lib/cassandra_backup/importer.rb', line 3

def self.run_command(command)
  new(command.config).run
end

Instance Method Details

#each_full_statement(io) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cassandra_backup/importer.rb', line 22

def each_full_statement(io)
  current_cql = ''

  io.each_line do |line|
    next unless line =~ /[^[:space:]]/

    current_cql << line.rstrip

    if current_cql =~ /;$/
      yield(current_cql)
      current_cql = ''
    end
  end
end

#execute(cql) ⇒ Object



18
19
20
# File 'lib/cassandra_backup/importer.rb', line 18

def execute(cql)
  config.connection.execute(cql) # passing an empty array ensures that no variable binding is attempted
end

#runObject



12
13
14
15
16
# File 'lib/cassandra_backup/importer.rb', line 12

def run
  each_full_statement(config.input) do |cql|
    execute cql
  end
end