Class: Forklift::Base::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/forklift/base/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Connection

Returns a new instance of Connection.



5
6
7
# File 'lib/forklift/base/connection.rb', line 5

def initialize(config)
  @config = config
end

Instance Method Details

#clientObject



13
14
15
# File 'lib/forklift/base/connection.rb', line 13

def client
  @client
end

#configObject



9
10
11
# File 'lib/forklift/base/connection.rb', line 9

def config
  @config
end

#connectObject



17
18
19
20
# File 'lib/forklift/base/connection.rb', line 17

def connect
  # Will define @client
  raise 'not implemented'
end

#disconnectObject



22
23
24
# File 'lib/forklift/base/connection.rb', line 22

def disconnect
  raise 'not implemented'
end

#exec(path, *args) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/forklift/base/connection.rb', line 41

def exec(path, *args)
  begin
    exec!(path, &args)
  rescue Exception => e
    forklift.logger.log(e)
  end
end

#exec!(path, *args) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/forklift/base/connection.rb', line 49

def exec!(path, *args)
  forklift.logger.log "Running script: #{path}"
  extension = path.split(".").last
  if(extension == "rb" || extension == "ruby")
    exec_ruby(path, *args)
  else
    exec_script(path, *args)
  end
end

#exec_ruby(path, *args) ⇒ Object



59
60
61
62
63
64
# File 'lib/forklift/base/connection.rb', line 59

def exec_ruby(path, *args)
  klass = forklift.utils.class_name_from_file(path)
  require path
  model = eval("#{klass}.new")
  model.do!(self, forklift, *args)
end

#exec_script(path, *args) ⇒ Object



66
67
68
# File 'lib/forklift/base/connection.rb', line 66

def exec_script(path, *args)
  raise 'not implemented'
end

#pipeObject



36
37
38
39
# File 'lib/forklift/base/connection.rb', line 36

def pipe
  # when copying within the same connection, this method can be defined to speed things up
  raise 'not implemented'
end

#read(query) ⇒ Object



26
27
28
29
# File 'lib/forklift/base/connection.rb', line 26

def read(query)
  # will return an array of data rows
  raise 'not implemented'
end

#write(data, collection) ⇒ Object



31
32
33
34
# File 'lib/forklift/base/connection.rb', line 31

def write(data, collection)
  # will write array data to collection (table)
  raise 'not implemented'
end