Class: ChefDK::Policyfile::DSL
- Inherits:
-
Object
- Object
- ChefDK::Policyfile::DSL
- Includes:
- StorageConfigDelegation
- Defined in:
- lib/chef-dk/policyfile/dsl.rb
Instance Attribute Summary collapse
-
#cookbook_location_specs ⇒ Object
readonly
Returns the value of attribute cookbook_location_specs.
-
#default_source(source_type = nil, source_uri = nil) ⇒ Object
readonly
Returns the value of attribute default_source.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
- #name(name = nil) ⇒ Object
-
#run_list(*run_list_items) ⇒ Object
readonly
Returns the value of attribute run_list.
-
#storage_config ⇒ Object
readonly
Returns the value of attribute storage_config.
Instance Method Summary collapse
- #cookbook(name, *version_and_source_opts) ⇒ Object
- #eval_policyfile(policyfile_string) ⇒ Object
-
#initialize(storage_config) ⇒ DSL
constructor
A new instance of DSL.
Methods included from StorageConfigDelegation
#cache_path, #policyfile_filename, #relative_paths_root
Constructor Details
#initialize(storage_config) ⇒ DSL
Returns a new instance of DSL.
37 38 39 40 41 42 43 44 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 37 def initialize(storage_config) @name = nil @errors = [] @run_list = [] @default_source = NullCookbookSource.new @cookbook_location_specs = {} @storage_config = storage_config end |
Instance Attribute Details
#cookbook_location_specs ⇒ Object (readonly)
Returns the value of attribute cookbook_location_specs.
33 34 35 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 33 def cookbook_location_specs @cookbook_location_specs end |
#default_source(source_type = nil, source_uri = nil) ⇒ Object (readonly)
Returns the value of attribute default_source.
32 33 34 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 32 def default_source @default_source end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
30 31 32 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 30 def errors @errors end |
#name(name = nil) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 46 def name(name = nil) unless name.nil? @name = name end @name end |
#run_list(*run_list_items) ⇒ Object (readonly)
Returns the value of attribute run_list.
31 32 33 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 31 def run_list @run_list end |
#storage_config ⇒ Object (readonly)
Returns the value of attribute storage_config.
35 36 37 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 35 def storage_config @storage_config end |
Instance Method Details
#cookbook(name, *version_and_source_opts) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 71 def cookbook(name, *version_and_source_opts) = if version_and_source_opts.last.is_a?(Hash) version_and_source_opts.pop else {} end constraint = version_and_source_opts.first || ">= 0.0.0" spec = CookbookLocationSpecification.new(name, constraint, , storage_config) if existing_source = @cookbook_location_specs[name] err = "Cookbook '#{name}' assigned to conflicting sources\n\n" err << "Previous source: #{existing_source.source_options.inspect}\n" err << "Conflicts with: #{source_options.inspect}\n" @errors << err else @cookbook_location_specs[name] = spec @errors += spec.errors end end |
#eval_policyfile(policyfile_string) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 94 def eval_policyfile(policyfile_string) @policyfile_filename = policyfile_filename instance_eval(policyfile_string, policyfile_filename) validate! self rescue SyntaxError => e @errors << "Invalid ruby syntax in policyfile '#{policyfile_filename}':\n\n#{e.message}" rescue SignalException, SystemExit # allow signal from kill, ctrl-C, etc. to bubble up: raise rescue Exception => e = "Evaluation of policyfile '#{policyfile_filename}' raised an exception\n" << " Exception: #{e.class.name} \"#{e.to_s}\"\n\n" trace = filtered_bt(policyfile_filename, e) << " Relevant Code:\n" << " #{error_context(policyfile_string, policyfile_filename, e)}\n\n" unless trace.empty? << " Backtrace:\n" # TODO: need a way to disable filtering << filtered_bt(policyfile_filename, e).inject("") { |formatted_trace, line| formatted_trace << " #{line}\n" } end @errors << end |