Class: ChefDK::Policyfile::DSL
- Inherits:
-
Object
- Object
- ChefDK::Policyfile::DSL
- Defined in:
- lib/chef-dk/policyfile/dsl.rb
Instance Attribute Summary collapse
-
#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.
-
#policyfile_cookbook_specs ⇒ Object
readonly
Returns the value of attribute policyfile_cookbook_specs.
-
#policyfile_filename ⇒ Object
Returns the value of attribute policyfile_filename.
-
#run_list(*run_list_items) ⇒ Object
readonly
Returns the value of attribute run_list.
Instance Method Summary collapse
- #cookbook(name, *version_and_source_opts) ⇒ Object
- #eval_policyfile(policyfile_string, policyfile_filename) ⇒ Object
-
#initialize ⇒ DSL
constructor
A new instance of DSL.
Constructor Details
#initialize ⇒ DSL
Returns a new instance of DSL.
32 33 34 35 36 37 38 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 32 def initialize @errors = [] @run_list = [] @default_source = NullCookbookSource.new @policyfile_cookbook_specs = {} @policyfile_filename = nil end |
Instance Attribute Details
#default_source(source_type = nil, source_uri = nil) ⇒ Object (readonly)
Returns the value of attribute default_source.
27 28 29 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 27 def default_source @default_source end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
25 26 27 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 25 def errors @errors end |
#policyfile_cookbook_specs ⇒ Object (readonly)
Returns the value of attribute policyfile_cookbook_specs.
28 29 30 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 28 def policyfile_cookbook_specs @policyfile_cookbook_specs end |
#policyfile_filename ⇒ Object
Returns the value of attribute policyfile_filename.
30 31 32 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 30 def policyfile_filename @policyfile_filename end |
#run_list(*run_list_items) ⇒ Object (readonly)
Returns the value of attribute run_list.
26 27 28 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 26 def run_list @run_list end |
Instance Method Details
#cookbook(name, *version_and_source_opts) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 58 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 = CookbookSpec.new(name, constraint, , policyfile_filename) if existing_source = @policyfile_cookbook_specs[name] err = "Cookbook '#{name}' assigned to conflicting sources\n\n" err << "Previous source: #{existing_source..inspect}\n" err << "Conflicts with: #{.inspect}\n" @errors << err else @policyfile_cookbook_specs[name] = spec end end |
#eval_policyfile(policyfile_string, policyfile_filename) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 80 def eval_policyfile(policyfile_string, policyfile_filename) @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.}" 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" << filtered_bt(policyfile_filename, e).inject("") { |formatted_trace, line| formatted_trace << " #{line}" } << "\n" end @errors << end |