Class: Mysql2psql::ConfigBase

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql2psql/config_base.rb

Direct Known Subclasses

Config

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configfilepath) ⇒ ConfigBase

Returns a new instance of ConfigBase.



9
10
11
12
# File 'lib/mysql2psql/config_base.rb', line 9

def initialize(configfilepath)
  @filepath=configfilepath
  @config = YAML::load(File.read(filepath))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mysql2psql/config_base.rb', line 16

def method_missing(name, *args)
  token=name.to_s
  default = args.length>0 ? args[0] : ''
  must_be_defined = default == :none
  case token
  when /mysql/i
    key=token.sub( /^mysql/, '' )
    value=config["mysql"][key]
  when /pg/i
    key=token.sub( /^pg/, '' )
    value=config["destination"]["postgres"][key]
  when /dest/i
    key=token.sub( /^dest/, '' )
    value=config["destination"][key]
  when /only_tables/i
    value=config["tables"] 
  else
    value=config[token]
  end
  value.nil? ? ( must_be_defined ? (raise Mysql2psql::UninitializedValueError.new("no value and no default for #{name}")) : default ) : value
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/mysql2psql/config_base.rb', line 7

def config
  @config
end

#filepathObject (readonly)

Returns the value of attribute filepath.



7
8
9
# File 'lib/mysql2psql/config_base.rb', line 7

def filepath
  @filepath
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
# File 'lib/mysql2psql/config_base.rb', line 13

def [](key)
  self.send( key )
end