Module: DockerBuilder::Config

Defined in:
lib/docker_builder/config.rb,
lib/docker_builder/config/dsl.rb,
lib/docker_builder/config/helpers.rb

Defined Under Namespace

Modules: Helpers Classes: DSL, Defaults

Constant Summary collapse

DEFAULTS =

class Error < DockerBuilder::Error; end

{
    :config_file  => 'config.rb',
    :tmp_path     => 'temp'
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.config_fileObject (readonly)

include Utilities::Helpers



19
20
21
# File 'lib/docker_builder/config.rb', line 19

def config_file
  @config_file
end

.optionsObject (readonly)

include Utilities::Helpers



19
20
21
# File 'lib/docker_builder/config.rb', line 19

def options
  @options
end

.root_pathObject (readonly)

include Utilities::Helpers



19
20
21
# File 'lib/docker_builder/config.rb', line 19

def root_path
  @root_path
end

.serversObject (readonly)

include Utilities::Helpers



19
20
21
# File 'lib/docker_builder/config.rb', line 19

def servers
  @servers
end

.tmp_pathObject (readonly)

include Utilities::Helpers



19
20
21
# File 'lib/docker_builder/config.rb', line 19

def tmp_path
  @tmp_path
end

Class Method Details

.dir_gem_rootObject



89
90
91
92
93
94
95
96
97
# File 'lib/docker_builder/config.rb', line 89

def dir_gem_root
  return @dir_gem_root unless @dir_gem_root.nil?

  #
  spec = Gem::Specification.find_by_name("docker-builder")
  @dir_gem_root = spec.gem_dir

  @dir_gem_root
end

.file_server_base_settingsObject



155
156
157
# File 'lib/docker_builder/config.rb', line 155

def self.file_server_base_settings
  File.join(File.dirname(__FILE__), '..', 'config' ,'common.rb')
end

.file_settings_for_server(name) ⇒ Object

helpers



150
151
152
153
# File 'lib/docker_builder/config.rb', line 150

def self.file_settings_for_server(name)
  #File.join(File.dirname(__FILE__), '..', 'config', "#{name}.rb")
  File.join(Config.root_path, 'servers', name, 'config.rb')
end

.load(opts = {}) ⇒ Object

Loads the user’s config.rb and all model files.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/docker_builder/config.rb', line 39

def load(opts = {})
  update(opts)  # from the command line

  #config_file = 'temp_config.rb'

  puts "config file: #{config_file}"

  unless File.exist?(config_file)
    #raise Error, "Could not find configuration file: '#{config_file}'."
    raise "Could not find configuration file: '#{config_file}'."
  end

  text_config = File.read(config_file)

  dsl = DSL.new
  dsl.instance_eval(text_config, config_file)

  # set options from dsl object
  update(dsl._config_options)  # from config.rb
  # command line takes precedence
  update(opts)

  #Dir[File.join(File.dirname(config_file), 'models', '*.rb')].each do |model|
  #  dsl.instance_eval(File.read(model), model)
  #end

  # servers
  # Identify all servers
  if @options['server']
    srv_name = @options['server'] || @options[:server]
    # one server
    @servers = {srv_name => dsl._config_servers[srv_name]}
  else
    # all servers
    @servers = dsl._config_servers
  end


  @servers.each do |name, sc|
    # from common config
    sc.common_config = self
    sc.properties['name'] ||= name
    #sc.properties['common'] = Config.options[:common]
  end



end

.load_settings_for_server(name, opts = {}) ⇒ Object

NOT USED TODO: refactor



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/docker_builder/config.rb', line 114

def self.load_settings_for_server(name, opts={})
  settings = ServerSettings.new

  settings.set 'name', name

  # set from main Config
  Config.servers[name].each do |k,v|
    settings.properties[k]=v
  end


  #puts "current=#{File.dirname(__FILE__)}"
  #puts "ff=#{file_base_settings}"

  #
  #t = File.read(file_base_settings) rescue ''
  #eval(t, settings.get_binding)


  #
  f = file_settings_for_server(name)
  t = File.read(f) rescue ''
  eval(t, settings.get_binding)

  #
  settings.properties['name'] ||= name

  # from common config
  settings.properties['common'] = Config.options[:common]

  settings
end

.method_missing(method_sym, *arguments, &block) ⇒ Object

Define on self, since it’s a class method



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/docker_builder/config.rb', line 24

def method_missing(method_sym, *arguments, &block)
  # the first argument is a Symbol, so you need to_s it if you want to pattern match
  if options.has_key?(method_sym)
    return options[method_sym]
  else
    super
  end
  #if method_sym.to_s =~ /^find_by_(.*)$/
  #  find($1.to_sym => arguments.first)

end