Class: ChefDK::Policyfile::DSL
- Inherits:
-
Object
- Object
- ChefDK::Policyfile::DSL
- Includes:
- StorageConfigDelegation
- Defined in:
- lib/chef-dk/policyfile/dsl.rb
Constant Summary collapse
- RUN_LIST_ITEM_COMPONENT =
%r/^[.[:alnum:]_-]+$/.freeze
Instance Attribute Summary collapse
-
#chef_config ⇒ Object
readonly
Returns the value of attribute chef_config.
-
#cookbook_location_specs ⇒ Object
readonly
Returns the value of attribute cookbook_location_specs.
-
#default_source(source_type = nil, source_argument = nil, &block) ⇒ Object
readonly
Returns the value of attribute default_source.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
- #name(name = nil) ⇒ Object
-
#named_run_lists ⇒ Object
readonly
Returns the value of attribute named_run_lists.
-
#node_attributes ⇒ Object
readonly
Returns the value of attribute node_attributes.
-
#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
- #default ⇒ Object
- #eval_policyfile(policyfile_string) ⇒ Object
-
#initialize(storage_config, chef_config: nil) ⇒ DSL
constructor
A new instance of DSL.
- #named_run_list(name, *run_list_items) ⇒ Object
- #override ⇒ Object
Methods included from StorageConfigDelegation
#cache_path, #policyfile_expanded_path, #policyfile_filename, #policyfile_lock_expanded_path, #relative_paths_root
Constructor Details
#initialize(storage_config, chef_config: nil) ⇒ DSL
Returns a new instance of DSL.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 46 def initialize(storage_config, chef_config: nil) @name = nil @errors = [] @run_list = [] @named_run_lists = {} @default_source = [ NullCookbookSource.new ] @cookbook_location_specs = {} @storage_config = storage_config @chef_config = chef_config @node_attributes = Chef::Node::Attribute.new({}, {}, {}, {}) end |
Instance Attribute Details
#chef_config ⇒ Object (readonly)
Returns the value of attribute chef_config.
45 46 47 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 45 def chef_config @chef_config end |
#cookbook_location_specs ⇒ Object (readonly)
Returns the value of attribute cookbook_location_specs.
38 39 40 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 38 def cookbook_location_specs @cookbook_location_specs end |
#default_source(source_type = nil, source_argument = nil, &block) ⇒ Object (readonly)
Returns the value of attribute default_source.
37 38 39 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 37 def default_source @default_source end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
35 36 37 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 35 def errors @errors end |
#name(name = nil) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 59 def name(name = nil) unless name.nil? @name = name end @name end |
#named_run_lists ⇒ Object (readonly)
Returns the value of attribute named_run_lists.
40 41 42 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 40 def named_run_lists @named_run_lists end |
#node_attributes ⇒ Object (readonly)
Returns the value of attribute node_attributes.
41 42 43 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 41 def node_attributes @node_attributes end |
#run_list(*run_list_items) ⇒ Object (readonly)
Returns the value of attribute run_list.
36 37 38 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 36 def run_list @run_list end |
#storage_config ⇒ Object (readonly)
Returns the value of attribute storage_config.
43 44 45 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 43 def storage_config @storage_config end |
Instance Method Details
#cookbook(name, *version_and_source_opts) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 100 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..inspect}\n" err << "Conflicts with: #{.inspect}\n" @errors << err else @cookbook_location_specs[name] = spec @errors += spec.errors end end |
#default ⇒ Object
123 124 125 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 123 def default @node_attributes.default end |
#eval_policyfile(policyfile_string) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 131 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.}" 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 |
#named_run_list(name, *run_list_items) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 75 def named_run_list(name, *run_list_items) run_list_items = run_list_items.flatten unless run_list_items.empty? validate_run_list_items(run_list_items, name) @named_run_lists[name] = run_list_items end @named_run_lists[name] end |
#override ⇒ Object
127 128 129 |
# File 'lib/chef-dk/policyfile/dsl.rb', line 127 def override @node_attributes.override end |