Class: Dumpdb::Db

Inherits:
Object
  • Object
show all
Defined in:
lib/dumpdb/db.rb

Constant Summary collapse

DEFAULT_VALUE =
''.freeze

Instance Method Summary collapse

Constructor Details

#initialize(dump_file_name = nil, values = nil) ⇒ Db

Returns a new instance of Db.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dumpdb/db.rb', line 7

def initialize(dump_file_name = nil, values = nil)
  dump_file_name = dump_file_name || 'dump.output'
  @values        = dumpdb_symbolize_keys(values)

  [:host, :port, :user, :pw, :db, :output_root].each do |key|
    @values[key] ||= DEFAULT_VALUE
  end

  @values[:output_dir] = dumpdb_build_output_dir(
    self.output_root,
    self.host,
    self.db
  )
  @values[:dump_file] = File.join(self.output_dir, dump_file_name)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/dumpdb/db.rb', line 25

def method_missing(meth, *args, &block)
  if @values.has_key?(meth.to_sym)
    @values[meth.to_sym]
  else
    super
  end
end

Instance Method Details

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/dumpdb/db.rb', line 33

def respond_to?(meth)
  @values.has_key?(meth.to_sym) || super
end

#to_hashObject



23
# File 'lib/dumpdb/db.rb', line 23

def to_hash; @values; end