lib/chef-dk/policyfile_compiler.rb in chef-dk-1.2.22 vs lib/chef-dk/policyfile_compiler.rb in chef-dk-1.3.40
- old
+ new
@@ -13,29 +13,29 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require 'set'
-require 'forwardable'
+require "set"
+require "forwardable"
-require 'solve'
-require 'chef/run_list'
+require "solve"
+require "chef/run_list"
-require 'chef-dk/policyfile/dsl'
-require 'chef-dk/policyfile_lock'
-require 'chef-dk/ui'
-require 'chef-dk/policyfile/reports/install'
-require 'chef-dk/exceptions'
+require "chef-dk/policyfile/dsl"
+require "chef-dk/policyfile_lock"
+require "chef-dk/ui"
+require "chef-dk/policyfile/reports/install"
+require "chef-dk/exceptions"
module ChefDK
class PolicyfileCompiler
extend Forwardable
- DEFAULT_DEMAND_CONSTRAINT = '>= 0.0.0'.freeze
+ DEFAULT_DEMAND_CONSTRAINT = ">= 0.0.0".freeze
# Cookbooks from these sources lock that cookbook to exactly one version
SOURCE_TYPES_WITH_FIXED_VERSIONS = [:git, :path].freeze
def self.evaluate(policyfile_string, policyfile_filename, ui: nil, chef_config: nil)
@@ -93,11 +93,11 @@
expanded
end
end
def normalized_named_run_lists
- expanded_named_run_lists.inject({}) do |normalized,(name, run_list)|
+ expanded_named_run_lists.inject({}) do |normalized, (name, run_list)|
normalized[name] = run_list.map { |i| normalize_recipe(i) }
normalized
end
end
@@ -124,38 +124,36 @@
missing_recipes_by_cb_spec = {}
graph_solution.each do |cookbook_name, version|
spec = cookbook_location_spec_for(cookbook_name)
- if spec.nil? or !spec.version_fixed?
+ if spec.nil? || !spec.version_fixed?
spec = create_spec_for_cookbook(cookbook_name, version)
install_report.installing_cookbook(spec)
spec.ensure_cached
end
required_recipes = cookbook_and_recipe_list.select { |cb_name, _recipe| cb_name == spec.name }
- missing_recipes = required_recipes.select {|_cb_name, recipe| !spec.cookbook_has_recipe?(recipe) }
+ missing_recipes = required_recipes.select { |_cb_name, recipe| !spec.cookbook_has_recipe?(recipe) }
unless missing_recipes.empty?
missing_recipes_by_cb_spec[spec] = missing_recipes
end
end
unless missing_recipes_by_cb_spec.empty?
message = "The installed cookbooks do not contain all the recipes required by your run list(s):\n"
missing_recipes_by_cb_spec.each do |spec, missing_items|
- message << "#{spec.to_s}\nis missing the following required recipes:\n"
+ message << "#{spec}\nis missing the following required recipes:\n"
missing_items.each { |_cb, recipe| message << "* #{recipe}\n" }
end
message << "\n"
message << "You may have specified an incorrect recipe in your run list,\nor this recipe may not be available in that version of the cookbook\n"
raise CookbookDoesNotContainRequiredRecipe, message
end
-
-
end
def create_spec_for_cookbook(cookbook_name, version)
matching_source = best_source_for(cookbook_name)
source_options = matching_source.source_options_for(cookbook_name, version)
@@ -263,11 +261,11 @@
merged
end
end
def version_constraint_for(cookbook_name)
- if (cookbook_location_spec = cookbook_location_spec_for(cookbook_name)) and cookbook_location_spec.version_fixed?
+ if (cookbook_location_spec = cookbook_location_spec_for(cookbook_name)) && cookbook_location_spec.version_fixed?
version = cookbook_location_spec.version
"= #{version}"
else
DEFAULT_DEMAND_CONSTRAINT
end
@@ -280,11 +278,11 @@
false
end
end
def cookbooks_in_run_list
- recipes = combined_run_lists.map {|recipe| recipe.name }
+ recipes = combined_run_lists.map { |recipe| recipe.name }
recipes.map { |r| r[/^([^:]+)/, 1] }
end
def combined_run_lists
expanded_named_run_lists.values.inject(expanded_run_list.to_a) do |accum_run_lists, run_list|
@@ -296,11 +294,10 @@
combined_run_lists.inject({}) do |by_name_accum, run_list_item|
by_name_accum
end
end
-
def build
yield @dsl
self
end
@@ -355,10 +352,9 @@
}
else
preferred
end
end
-
def preferred_source_for_cookbook(conflicting_cb_name)
default_source.find { |s| s.preferred_source_for?(conflicting_cb_name) }
end