Class: Cartage::Config
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Cartage::Config
- Defined in:
- lib/cartage/config.rb
Overview
The Cartage configuration structure. The supported Cartage-wide configuration fields are:
name-
The name of the application. Sets Cartage#name. Equivalent to
--name. Optional, defaults to the basename of the origin repo URL. Overridden withcartage --name NAME. target-
The target path for the Cartage package. Optional, defaults to
./tmp. Overridden withcartage --target PATH. root_path-
The root path of the application. Optional, defaults to the top of the repository (
git rev-parse --show-cdup). Overridden withcartage --root-path ROOT_PATH. timestamp-
Equivalent to
--timestamp. The timestamp for the final package (which is<em>name</em>-<em>timestamp</em>). Optional, defaults to the current time in UTC. Overridden withcartage --timestamp TIMESTAMP. This value is not validated to be a time value when supplied. compression-
The type of compression to be used. Optional, defaults to ‘bzip2’. Must be one of ‘bzip2’, ‘gzip’, or ‘none’. Overridden with
cartage --compression TYPE.This affects the compression and filenames of both the final package and the dependency cache.
quiet-
Silence normal output. Optional, defaults false. Overridden with
cartage --quiet. verbose-
Show verbose output. Optional, defaults false. Overridden with
cartage --verbose. disable_dependency_cache-
Disable dependency caching. Optional, defaults false.
dependency_cache_path-
The path where the dependency cache will be written (
dependency-cache.tar.*) for use in successive builds. Optional, defaults to./tmp. Overridden withcartage --dependency-cache-path PATH.On a CI system, this should be written somewhere that the CI system uses for build caching.
Commands and Plug-Ins
Commands and plug-ins have access to configuration dictinoaries in the main Cartage configuration structure. Command configuration dictionaries are found under commands and plug-in configuration dictionaries are found under plugins.
commands-
This dictionary is for command-specific configuration. The keys are freeform and should be based on the primary name of the command (so the
cartage packcommand should use the keypack.) plugins-
This dictionary is for plug-in-specific configuration. See each plug-in for configuration options. The keys to the plug-ins are based on the plug-in name. cartage-bundler is available as Cartage::Bundler; the transformed plug-in name will be
bundler.
Loading Configuration
When --config-file is specified, the configuration file will be loaded and parsed. If a filename is given, that file will be loaded. If a filename is not given, Cartage will look for the configuration in the following locations:
-
./config/cartage.yml
-
./.cartage.yml
-
./cartage.yml
The contents of the configuration file are evaluated through ERB and then parsed from YAML and converted to nested OpenStruct objects.
Constant Summary collapse
- DEFAULT_CONFIG_FILES =
:stopdoc:
%w( ./config/cartage.yml ./cartage.yml ./.cartage.yml ).each(&:freeze).freeze
Class Method Summary collapse
-
.import(filename) ⇒ Object
Read the contents of
filenameif and only if it exists. -
.load(filename) ⇒ Object
Load a Cartage configuration file as specified by
filename.
Instance Method Summary collapse
-
#initialize(hash = nil) ⇒ Config
constructor
:nodoc:.
-
#to_h ⇒ Object
Convert the entire Config structure to a hash recursively.
-
#to_yaml ⇒ Object
Override the default #to_yaml implementation.
Constructor Details
#initialize(hash = nil) ⇒ Config
:nodoc:
155 156 157 158 159 |
# File 'lib/cartage/config.rb', line 155 def initialize(hash = nil) # :nodoc: super(hash && self.class.send(:ostructify, hash)) self.plugins ||= OpenStruct.new self.commands ||= OpenStruct.new end |
Class Method Details
.import(filename) ⇒ Object
Read the contents of filename if and only if it exists. For use in ERB configuration of Cartage to read local or Ansible-created files.
103 104 105 |
# File 'lib/cartage/config.rb', line 103 def import(filename) File.read(filename) if File.exist?(filename) end |
.load(filename) ⇒ Object
Load a Cartage configuration file as specified by filename. If filename is the special value :default, project-specific configuration files will be located.
95 96 97 98 99 |
# File 'lib/cartage/config.rb', line 95 def load(filename) config_file = resolve_config_file(filename) config = ::YAML.load(ERB.new(config_file.read, nil, '%<>-').result) new(config) end |
Instance Method Details
#to_h ⇒ Object
Convert the entire Config structure to a hash recursively.
146 147 148 |
# File 'lib/cartage/config.rb', line 146 def to_h hashify(self) end |
#to_yaml ⇒ Object
Override the default #to_yaml implementation.
151 152 153 |
# File 'lib/cartage/config.rb', line 151 def to_yaml to_h.to_yaml end |