Class: DBGeni::Environment

Inherits:
BlankSlate show all
Defined in:
lib/dbgeni/environment.rb

Constant Summary

Constants inherited from BlankSlate

BlankSlate::KEEP_METHODS

Instance Method Summary collapse

Constructor Details

#initialize(environment_name) ⇒ Environment

Returns a new instance of Environment.

[View source]

5
6
7
8
9
# File 'lib/dbgeni/environment.rb', line 5

def initialize(environment_name)
  @environment_name = environment_name
  @params           = Hash.new
  @loading          = true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

[View source]

41
42
43
44
45
46
47
48
# File 'lib/dbgeni/environment.rb', line 41

def method_missing(name, *args, &block)
  str_name = name.to_s.gsub(/=$/, '')
  if __is_loadable?
    __load_parameter(str_name, *args)
  else
    __get_parameter(str_name, *args)
  end
end

Instance Method Details

#__completed_loadingObject

[View source]

20
21
22
# File 'lib/dbgeni/environment.rb', line 20

def __completed_loading
  @loading = false
end

#__enable_loadingObject

[View source]

16
17
18
# File 'lib/dbgeni/environment.rb', line 16

def __enable_loading
  @loading = true
end

#__environment_nameObject

[View source]

28
29
30
# File 'lib/dbgeni/environment.rb', line 28

def __environment_name
  @environment_name
end

#__is_loadable?Boolean

Returns:

  • (Boolean)
[View source]

24
25
26
# File 'lib/dbgeni/environment.rb', line 24

def __is_loadable?
  @loading
end

#__merge_defaults(default_params) ⇒ Object

[View source]

36
37
38
39
# File 'lib/dbgeni/environment.rb', line 36

def __merge_defaults(default_params)
  all_params = default_params.merge(@params)
  @params = all_params
end

#__merge_environment(new_env) ⇒ Object

[View source]

12
13
14
# File 'lib/dbgeni/environment.rb', line 12

def __merge_environment(new_env)
  @params.merge!(new_env.__params)
end

#__paramsObject

[View source]

32
33
34
# File 'lib/dbgeni/environment.rb', line 32

def __params
  @params
end

#__to_sObject

[View source]

50
51
52
53
54
55
56
57
58
# File 'lib/dbgeni/environment.rb', line 50

def __to_s
  str = ''
  # get the longest key length to pad the keys
  max_length = @params.keys.map{ |k| k.length }.sort.last
  @params.keys.sort.each do |k|
    str << "#{k.ljust(max_length, ' ')} => #{@params[k]}\n"
  end
  str
end