Class: CHBuild::Config
- Inherits:
-
Object
- Object
- CHBuild::Config
- Defined in:
- lib/chbuild/config.rb,
lib/chbuild/config/env.rb,
lib/chbuild/config/use.rb,
lib/chbuild/config/before.rb,
lib/chbuild/config/errors.rb,
lib/chbuild/config/version.rb
Overview
Build configuration object
Defined Under Namespace
Classes: Before, Env, NotFoundError, Use, Version
Instance Attribute Summary collapse
-
#before ⇒ Object
readonly
Returns the value of attribute before.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#use ⇒ Object
readonly
Returns the value of attribute use.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #errors ⇒ Object
- #init_script ⇒ Object
-
#initialize(path_to_config) ⇒ Config
constructor
A new instance of Config.
- #inspect ⇒ Object
Constructor Details
#initialize(path_to_config) ⇒ Config
Returns a new instance of Config.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chbuild/config.rb', line 15 def initialize(path_to_config) begin @path = path_to_config build_config = YAML.load_file(path_to_config) rescue Errno::ENOENT raise CHBuild::Config::NotFoundError, "'#{path_to_config}': file not found" end @errors = [] unless build_config @errors << 'Build file is empty' return end @raw = build_config @version = Version.new(build_config['version']) @use = Use.new(build_config['use']) @env = Env.new(build_config['env']) @before = Before.new(build_config['before']) end |
Instance Attribute Details
#before ⇒ Object (readonly)
Returns the value of attribute before.
13 14 15 |
# File 'lib/chbuild/config.rb', line 13 def before @before end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
13 14 15 |
# File 'lib/chbuild/config.rb', line 13 def env @env end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/chbuild/config.rb', line 13 def path @path end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
13 14 15 |
# File 'lib/chbuild/config.rb', line 13 def raw @raw end |
#use ⇒ Object (readonly)
Returns the value of attribute use.
13 14 15 |
# File 'lib/chbuild/config.rb', line 13 def use @use end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
13 14 15 |
# File 'lib/chbuild/config.rb', line 13 def version @version end |
Instance Method Details
#errors ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chbuild/config.rb', line 46 def errors all_errors = Array.new(@errors) instance_variables.each do |var| section = instance_variable_get(var) next unless section.respond_to?(:name) && section.respond_to?(:errors) section_name = section.send(:name) section_errors = section.send(:errors) section_errors.each do |err| all_errors << "#{section_name}: #{err}" end end all_errors end |
#init_script ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/chbuild/config.rb', line 36 def init_script unless @init_script generation_time = "echo \"Generated at: [#{Time.now}]\"\n\n" env_script = @env.to_bash_script before_script = @before.to_bash_script @init_script = generation_time + env_script + before_script end @init_script end |
#inspect ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/chbuild/config.rb', line 62 def inspect data = [] instance_variables.each do |var| section = instance_variable_get(var) if section.respond_to?(:name) section_name = section.send(:name) data << "#{section_name}: #{section.inspect}" end end data.join("\n") end |