Class: MongoDbUtils::Tools::BaseCmd

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo-db-utils/tools/commands.rb

Direct Known Subclasses

Dump, Export, Import, Restore

Instance Method Summary collapse

Constructor Details

#initialize(cmd_name, host_and_port, db, username = '', password = '') ⇒ BaseCmd

Returns a new instance of BaseCmd.



19
20
21
22
23
# File 'lib/mongo-db-utils/tools/commands.rb', line 19

def initialize(cmd_name, host_and_port, db, username = '', password = '')
  @unsafe_options = build_base_options(host_and_port, db, username, password)
  @options_without_credentials = build_base_options(host_and_port, db, username.empty? ? '':'****', password.empty? ? '':'****')
  @cmd_name = cmd_name
end

Instance Method Details

#cmdObject



31
32
33
# File 'lib/mongo-db-utils/tools/commands.rb', line 31

def cmd
  "#{@cmd_name} #{options_string(@options_without_credentials)}"
end

#executable_cmdObject



35
36
37
# File 'lib/mongo-db-utils/tools/commands.rb', line 35

def executable_cmd
  "#{@cmd_name} #{options_string(@unsafe_options)}"
end

#runObject

Raises:



25
26
27
28
29
# File 'lib/mongo-db-utils/tools/commands.rb', line 25

def run
  puts "[#{self.class}] run: #{cmd}"
  output = `#{executable_cmd} 2>&1`
  raise ToolsException.new("#{cmd}", output, "Error in #{@cmd_name}:: #{output}, cmd: #{cmd}") unless $?.to_i == 0
end