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



71
72
73
74
75
76
77
78
79
# File 'lib/docker_builder/config.rb', line 71

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

.load(opts = {}) ⇒ Object

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



38
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
# File 'lib/docker_builder/config.rb', line 38

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

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

  config = File.read(config_file)

  #version = DockerBuilder::VERSION.split('.').first
  #unless config =~ /^# Backup v#{ version }\.x Configuration$/
  #  raise Error, <<-EOS
  #    Invalid Configuration File
  #  EOS
  #end

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

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

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

  # servers
  load_servers(opts)

end

.load_servers(opts) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/docker_builder/config.rb', line 92

def load_servers(opts)
  # Identify all servers
  if opts[:server]
    server_name = opts[:server]
    options[:servers] = {server_name=>options[:servers][server_name] }
  else
    # get from config
    #options[:servers] = options[:servers]
  end


end

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

Define on self, since it’s a class method



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

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