Class: DBGet::Connector
- Inherits:
-
Object
- Object
- DBGet::Connector
- Defined in:
- lib/dbget/connector.rb
Constant Summary
Constants included from Constants
DBGet::Constants::DBGET_CONFIG_FILE
Instance Attribute Summary collapse
-
#clean ⇒ Object
readonly
Returns the value of attribute clean.
-
#collections ⇒ Object
Returns the value of attribute collections.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#db_path ⇒ Object
readonly
Returns the value of attribute db_path.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #init_ssh_params ⇒ Object
-
#initialize(database, config, options) ⇒ Connector
constructor
A new instance of Connector.
- #send_data! ⇒ Object
Methods included from Utils
randomize, say, say_with_time, stringify
Constructor Details
#initialize(database, config, options) ⇒ Connector
Returns a new instance of Connector.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dbget/connector.rb', line 12 def initialize(database, config, ) @db = database @options = Utils.stringify() @config = config.merge!(@options) @login = @config['login'] @db_type = @options['db_type'] @server = @config['server'] @date = @config['date'] @clean = @config['clean'] @verbose = @config['verbose'] @collections = @config['collections'] @custom_name = @config['name'] @append_date = @config['append_date'] @ssh_params = init_ssh_params end |
Instance Attribute Details
#clean ⇒ Object (readonly)
Returns the value of attribute clean.
10 11 12 |
# File 'lib/dbget/connector.rb', line 10 def clean @clean end |
#collections ⇒ Object
Returns the value of attribute collections.
8 9 10 |
# File 'lib/dbget/connector.rb', line 8 def collections @collections end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
9 10 11 |
# File 'lib/dbget/connector.rb', line 9 def db @db end |
#db_path ⇒ Object (readonly)
Returns the value of attribute db_path.
9 10 11 |
# File 'lib/dbget/connector.rb', line 9 def db_path @db_path end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
10 11 12 |
# File 'lib/dbget/connector.rb', line 10 def verbose @verbose end |
Instance Method Details
#init_ssh_params ⇒ Object
52 53 54 55 |
# File 'lib/dbget/connector.rb', line 52 def init_ssh_params "%s db=%s db_type=%s server=%s date=%s clean=%s verbose=%s collections=%s custom_name=%s append_date=%s" % [@login, @db, @db_type, @server, @date, @clean, @verbose, @collections, @custom_name, @append_date] end |
#send_data! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dbget/connector.rb', line 28 def send_data! user, host = @config['login'].split('@') Net::SSH.start(host, user) do |ssh| channel = ssh.open_channel do |ch| ch.exec(@ssh_params) do |ch, success| raise "SSH connection failure." unless success ch.on_data do |c,data| $stdout.puts data end ch.on_extended_data do |c, type, data| $stderr.print data end end channel.wait end end end |