diff options
Diffstat (limited to 'lib/chef/cookbook')
-rw-r--r-- | lib/chef/cookbook/chefignore.rb | 3 | ||||
-rw-r--r-- | lib/chef/cookbook/cookbook_collection.rb | 4 | ||||
-rw-r--r-- | lib/chef/cookbook/cookbook_version_loader.rb | 2 | ||||
-rw-r--r-- | lib/chef/cookbook/file_vendor.rb | 1 | ||||
-rw-r--r-- | lib/chef/cookbook/metadata.rb | 100 | ||||
-rw-r--r-- | lib/chef/cookbook/remote_file_vendor.rb | 2 | ||||
-rw-r--r-- | lib/chef/cookbook/synchronizer.rb | 4 | ||||
-rw-r--r-- | lib/chef/cookbook/syntax_check.rb | 8 |
8 files changed, 61 insertions, 63 deletions
diff --git a/lib/chef/cookbook/chefignore.rb b/lib/chef/cookbook/chefignore.rb index f0cbf12d4e..71ef53c9e5 100644 --- a/lib/chef/cookbook/chefignore.rb +++ b/lib/chef/cookbook/chefignore.rb @@ -40,7 +40,7 @@ class Chef end def ignored?(file_name) - @ignores.any? {|glob| File.fnmatch?(glob, file_name)} + @ignores.any? { |glob| File.fnmatch?(glob, file_name) } end private @@ -72,4 +72,3 @@ class Chef end end end - diff --git a/lib/chef/cookbook/cookbook_collection.rb b/lib/chef/cookbook/cookbook_collection.rb index a9de718902..81e7bb92b4 100644 --- a/lib/chef/cookbook/cookbook_collection.rb +++ b/lib/chef/cookbook/cookbook_collection.rb @@ -33,12 +33,12 @@ class Chef # The input is a mapping of cookbook name to CookbookVersion objects. We # simply extract them - def initialize(cookbook_versions={}) + def initialize(cookbook_versions = {}) super() do |hash, key| raise Chef::Exceptions::CookbookNotFound, "Cookbook #{key} not found. " << "If you're loading #{key} from another cookbook, make sure you configure the dependency in your metadata" end - cookbook_versions.each{ |cookbook_name, cookbook_version| self[cookbook_name] = cookbook_version } + cookbook_versions.each { |cookbook_name, cookbook_version| self[cookbook_name] = cookbook_version } end # Validates that the cookbook metadata allows it to run on this instance. diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index 370a77ecaf..04be8c725c 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -32,7 +32,7 @@ class Chef attr_reader :metadata_error - def initialize(path, chefignore=nil) + def initialize(path, chefignore = nil) @cookbook_path = File.expand_path( path ) # cookbook_path from which this was loaded # We keep a list of all cookbook paths that have been merged in @cookbook_paths = [ cookbook_path ] diff --git a/lib/chef/cookbook/file_vendor.rb b/lib/chef/cookbook/file_vendor.rb index 2501d4b8de..f849f79296 100644 --- a/lib/chef/cookbook/file_vendor.rb +++ b/lib/chef/cookbook/file_vendor.rb @@ -17,7 +17,6 @@ # limitations under the License. # - class Chef class Cookbook # == Chef::Cookbook::FileVendor diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index 8050c4f892..7cc4be9f89 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -65,14 +65,14 @@ class Chef :replacing, :attributes, :groupings, :recipes, :version, :source_url, :issues_url, :privacy, :chef_versions, :ohai_versions ] - VERSION_CONSTRAINTS = {:depends => DEPENDENCIES, - :recommends => RECOMMENDATIONS, - :suggests => SUGGESTIONS, - :conflicts => CONFLICTING, - :provides => PROVIDING, - :replaces => REPLACING, - :chef_version => CHEF_VERSIONS, - :ohai_version => OHAI_VERSIONS } + VERSION_CONSTRAINTS = { :depends => DEPENDENCIES, + :recommends => RECOMMENDATIONS, + :suggests => SUGGESTIONS, + :conflicts => CONFLICTING, + :provides => PROVIDING, + :replaces => REPLACING, + :chef_version => CHEF_VERSIONS, + :ohai_version => OHAI_VERSIONS } include Chef::Mixin::ParamsValidate include Chef::Mixin::FromFile @@ -105,7 +105,7 @@ class Chef # === Returns # metadata<Chef::Cookbook::Metadata> def initialize - @name = nil + @name = nil @description = "" @long_description = "" @@ -173,7 +173,7 @@ class Chef # # === Returns # maintainer<String>:: Returns the current maintainer. - def maintainer(arg=nil) + def maintainer(arg = nil) set_or_return( :maintainer, arg, @@ -188,7 +188,7 @@ class Chef # # === Returns # maintainer_email<String>:: Returns the current maintainer email. - def maintainer_email(arg=nil) + def maintainer_email(arg = nil) set_or_return( :maintainer_email, arg, @@ -203,7 +203,7 @@ class Chef # # === Returns # license<String>:: Returns the current license - def license(arg=nil) + def license(arg = nil) set_or_return( :license, arg, @@ -218,7 +218,7 @@ class Chef # # === Returns # description<String>:: Returns the description - def description(arg=nil) + def description(arg = nil) set_or_return( :description, arg, @@ -233,7 +233,7 @@ class Chef # # === Returns # long_description<String>:: Returns the long description - def long_description(arg=nil) + def long_description(arg = nil) set_or_return( :long_description, arg, @@ -249,7 +249,7 @@ class Chef # # === Returns # version<String>:: Returns the current version - def version(arg=nil) + def version(arg = nil) if arg @version = Chef::Version.new(arg) end @@ -264,7 +264,7 @@ class Chef # # === Returns # name<String>:: Returns the current cookbook name. - def name(arg=nil) + def name(arg = nil) set_or_return( :name, arg, @@ -321,7 +321,7 @@ class Chef # === Returns # versions<Array>:: Returns the list of versions for the platform def recommends(cookbook, *version_args) - version = new_args_format(:recommends, cookbook, version_args) + version = new_args_format(:recommends, cookbook, version_args) constraint = validate_version_constraint(:recommends, cookbook, version) @recommendations[cookbook] = constraint.to_s @recommendations[cookbook] @@ -622,11 +622,11 @@ class Chef metadata = new() VERSION_CONSTRAINTS.each do |dependency_type, hash_key| if dependency_group = o[hash_key] - dependency_group.each do |cb_name, constraints| - if metadata.respond_to?(method_name) - metadata.public_send(method_name, cb_name, *Array(constraints)) - end - end + dependency_group.each do |cb_name, constraints| + if metadata.respond_to?(method_name) + metadata.public_send(method_name, cb_name, *Array(constraints)) + end + end end end true @@ -644,7 +644,7 @@ class Chef # # === Returns # source_url<String>:: Returns the current source URL. - def source_url(arg=nil) + def source_url(arg = nil) set_or_return( :source_url, arg, @@ -659,7 +659,7 @@ class Chef # # === Returns # issues_url<String>:: Returns the current issues URL. - def issues_url(arg=nil) + def issues_url(arg = nil) set_or_return( :issues_url, arg, @@ -676,7 +676,7 @@ class Chef # === Returns # privacy<TrueClass,FalseClass>:: Whether this cookbook is private or not # - def privacy(arg=nil) + def privacy(arg = nil) set_or_return( :privacy, arg, @@ -733,14 +733,14 @@ class Chef elsif version_constraints.size == 1 version_constraints.first else - msg=<<-OBSOLETED + msg = <<-OBSOLETED The dependency specification syntax you are using is no longer valid. You may not specify more than one version constraint for a particular cookbook. Consult https://docs.chef.io/config_rb_metadata.html for the updated syntax. -Called by: #{caller_name} '#{dep_name}', #{version_constraints.map {|vc| vc.inspect}.join(", ")} +Called by: #{caller_name} '#{dep_name}', #{version_constraints.map { |vc| vc.inspect }.join(", ")} Called from: -#{caller[0...5].map {|line| " " + line}.join("\n")} +#{caller[0...5].map { |line| " " + line }.join("\n")} OBSOLETED raise Exceptions::ObsoleteDependencySyntax, msg end @@ -751,7 +751,7 @@ OBSOLETED rescue Chef::Exceptions::InvalidVersionConstraint => e Log.debug(e) - msg=<<-INVALID + msg = <<-INVALID The version constraint syntax you are using is not valid. If you recently upgraded to Chef 0.10.0, be aware that you no may longer use "<<" and ">>" for 'less than' and 'greater than'; use '<' and '>' instead. @@ -759,7 +759,7 @@ Consult https://docs.chef.io/config_rb_metadata.html for more information. Called by: #{caller_name} '#{dep_name}', '#{constraint_str}' Called from: -#{caller[0...5].map {|line| " " + line}.join("\n")} +#{caller[0...5].map { |line| " " + line }.join("\n")} INVALID raise Exceptions::InvalidVersionConstraint, msg end @@ -773,7 +773,7 @@ INVALID def validate_string_array(arry) if arry.kind_of?(Array) arry.each do |choice| - validate( {:choice => choice}, {:choice => {:kind_of => String}} ) + validate( { :choice => choice }, { :choice => { :kind_of => String } } ) end end end @@ -783,28 +783,28 @@ INVALID # Raise an exception if the members of the array do not match the defaults # === Parameters # opts<Hash>:: The options hash - def validate_choice_array(opts) - if opts[:choice].kind_of?(Array) - case opts[:type] - when "string" - validator = [ String ] - when "array" - validator = [ Array ] - when "hash" - validator = [ Hash ] - when "symbol" - validator = [ Symbol ] - when "boolean" - validator = [ TrueClass, FalseClass ] - when "numeric" - validator = [ Numeric ] - end + def validate_choice_array(opts) + if opts[:choice].kind_of?(Array) + case opts[:type] + when "string" + validator = [ String ] + when "array" + validator = [ Array ] + when "hash" + validator = [ Hash ] + when "symbol" + validator = [ Symbol ] + when "boolean" + validator = [ TrueClass, FalseClass ] + when "numeric" + validator = [ Numeric ] + end - opts[:choice].each do |choice| - validate( {:choice => choice}, {:choice => {:kind_of => validator}} ) - end + opts[:choice].each do |choice| + validate( { :choice => choice }, { :choice => { :kind_of => validator } } ) end end + end # For backwards compatibility, remap Boolean values to String # true is mapped to "required" diff --git a/lib/chef/cookbook/remote_file_vendor.rb b/lib/chef/cookbook/remote_file_vendor.rb index d483c54f8f..9155162c4c 100644 --- a/lib/chef/cookbook/remote_file_vendor.rb +++ b/lib/chef/cookbook/remote_file_vendor.rb @@ -45,7 +45,7 @@ class Chef end raise "No such segment #{segment} in cookbook #{@cookbook_name}" unless @manifest[segment] - found_manifest_record = @manifest[segment].find {|manifest_record| manifest_record[:path] == filename } + found_manifest_record = @manifest[segment].find { |manifest_record| manifest_record[:path] == filename } raise "No such file #{filename} in #{@cookbook_name}" unless found_manifest_record cache_filename = File.join("cookbooks", @cookbook_name, found_manifest_record["path"]) diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb index 9955bae6bb..e8b90a45c3 100644 --- a/lib/chef/cookbook/synchronizer.rb +++ b/lib/chef/cookbook/synchronizer.rb @@ -141,7 +141,7 @@ class Chef # === Returns # true:: Always returns true def sync_cookbooks - Chef::Log.info("Loading cookbooks [#{cookbooks.map {|ckbk| ckbk.name + '@' + ckbk.version}.join(', ')}]") + Chef::Log.info("Loading cookbooks [#{cookbooks.map { |ckbk| ckbk.name + '@' + ckbk.version }.join(', ')}]") Chef::Log.debug("Cookbooks detail: #{cookbooks.inspect}") clear_obsoleted_cookbooks @@ -176,7 +176,7 @@ class Chef # Saves the full_path to the file of the cookbook to be updated # in the manifest later def save_full_file_path(file, full_path) - @cookbook_full_file_paths[file.cookbook] ||= { } + @cookbook_full_file_paths[file.cookbook] ||= {} @cookbook_full_file_paths[file.cookbook][file.segment] ||= [ ] @cookbook_full_file_paths[file.cookbook][file.segment] << full_path end diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb index d6849584c4..fd7835db96 100644 --- a/lib/chef/cookbook/syntax_check.rb +++ b/lib/chef/cookbook/syntax_check.rb @@ -43,7 +43,7 @@ class Chef # Create a new PersistentSet. Values in the set are persisted by # creating a file in the +cache_path+ directory. - def initialize(cache_path=Chef::Config[:syntax_check_cache_path]) + def initialize(cache_path = Chef::Config[:syntax_check_cache_path]) @cache_path = cache_path @cache_path_created = false end @@ -82,7 +82,7 @@ class Chef # Creates a new SyntaxCheck given the +cookbook_name+ and a +cookbook_path+. # If no +cookbook_path+ is given, +Chef::Config.cookbook_path+ is used. - def self.for_cookbook(cookbook_name, cookbook_path=nil) + def self.for_cookbook(cookbook_name, cookbook_path = nil) cookbook_path ||= Chef::Config.cookbook_path unless cookbook_path raise ArgumentError, "Cannot find cookbook #{cookbook_name} unless Chef::Config.cookbook_path is set or an explicit cookbook path is given" @@ -209,7 +209,7 @@ class Chef # Debug a syntax error in a template. def invalid_erb_file(erb_file, error_message) - file_relative_path = erb_file[/^#{Regexp.escape(cookbook_path+File::Separator)}(.*)/, 1] + file_relative_path = erb_file[/^#{Regexp.escape(cookbook_path + File::Separator)}(.*)/, 1] Chef::Log.fatal("Erb template #{file_relative_path} has a syntax error:") error_message.each_line { |l| Chef::Log.fatal(l.chomp) } nil @@ -244,7 +244,7 @@ class Chef # Debugs ruby syntax errors by printing the path to the file and any # diagnostic info given in +error_message+ def invalid_ruby_file(ruby_file, error_message) - file_relative_path = ruby_file[/^#{Regexp.escape(cookbook_path+File::Separator)}(.*)/, 1] + file_relative_path = ruby_file[/^#{Regexp.escape(cookbook_path + File::Separator)}(.*)/, 1] Chef::Log.fatal("Cookbook file #{file_relative_path} has a ruby syntax error:") error_message.each_line { |l| Chef::Log.fatal(l.chomp) } false |