Class: Docker::Template::Config
- Extended by:
- Forwardable
- Defined in:
- lib/docker/template/config.rb
Overview
Configuration is a global version of meatadata, where anything that can be set on configuration can be optimized and stored globally in a opts.json,yml file in the current working directory.
Constant Summary collapse
- DEFAULTS =
{ "type" => "simple", "user" => "envygeeks", "local_prefix" => "local", "rootfs_base_img" => "envygeeks/ubuntu:tiny", "maintainer" => "Jordon Bedwell <[email protected]>", "dockerhub_copy" => false, "repos_dir" => "repos", "copy_dir" => "copy", "tag" => "latest", "env" => { "tag" => {}, "type" => {}, "all" => nil }, "pkgs" => { "tag" => {}, "type" => {}, "all" => nil }, "entries" => { "tag" => {}, "type" => {}, "all" => nil }, "releases" => { "tag" => {}, "type" => {}, "all" => nil }, "versions" => { "tag" => {}, "type" => {}, "all" => nil }, "aliases" => {}, "tags" => {} }.freeze
- EMPTY_DEFAULTS =
{ "tags" => { "latest" => "normal" } }
Instance Method Summary collapse
- #build_types ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#read_config_from(dir = Docker::Template.root) ⇒ Object
Allows you to read a configuration file from a root and get back either the parsed data or a blank hash that can be merged the way you wish to merge it (if you even care to merge it.).
Constructor Details
#initialize ⇒ Config
53 54 55 56 57 58 59 60 |
# File 'lib/docker/template/config.rb', line 53 def initialize @config = DEFAULTS.deep_merge(read_config_from) @config = @config.merge(EMPTY_DEFAULTS) do |_, oval, nval| oval.nil? || oval.empty?? nval : oval end @config.freeze end |
Instance Method Details
#build_types ⇒ Object
75 76 77 |
# File 'lib/docker/template/config.rb', line 75 def build_types @build_types ||= %W(simple scratch).freeze end |
#read_config_from(dir = Docker::Template.root) ⇒ Object
Allows you to read a configuration file from a root and get back either the parsed data or a blank hash that can be merged the way you wish to merge it (if you even care to merge it.)
66 67 68 69 70 71 |
# File 'lib/docker/template/config.rb', line 66 def read_config_from(dir = Docker::Template.root) file = Dir[dir.join("*.{json,yml}")].first return {} unless file && (file = Pathname.new(file)).file? return JSON.parse(file.read).stringify if file.extname == ".json" YAML.load_file(file).stringify end |