diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 628247db22d..d6f6bd063ad 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -652,19 +652,6 @@ Style/OptionalBooleanParameter: Style/PreferredHashMethods: Enabled: false -# This cop supports unsafe auto-correction (--auto-correct-all). -Style/RedundantInterpolation: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Enabled: false - -# This cop supports safe auto-correction (--auto-correct). -Style/RedundantSelf: - Enabled: false - # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyle. # SupportedStyles: implicit, explicit diff --git a/lib/hiera/scope.rb b/lib/hiera/scope.rb index 2d419c0bca8..726b0405c39 100644 --- a/lib/hiera/scope.rb +++ b/lib/hiera/scope.rb @@ -77,11 +77,11 @@ def compiler def find_hostclass(scope) if scope.source and scope.source.type == :hostclass - return scope.source.name.downcase + scope.source.name.downcase elsif scope.parent - return find_hostclass(scope.parent) + find_hostclass(scope.parent) else - return nil + nil end end private :find_hostclass diff --git a/lib/hiera_puppet.rb b/lib/hiera_puppet.rb index 94dd92c88a5..fa48532e60e 100644 --- a/lib/hiera_puppet.rb +++ b/lib/hiera_puppet.rb @@ -47,7 +47,7 @@ def parse_args(args) default = args[1] override = args[2] - return [key, default, override] + [key, default, override] end def hiera diff --git a/lib/puppet.rb b/lib/puppet.rb index b7a06508d44..40f990a52b5 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -75,9 +75,9 @@ def self.replace_settings_object(new_settings) # @api public def self.[](param) if param == :debug - return Puppet::Util::Log.level == :debug + Puppet::Util::Log.level == :debug else - return @@settings[param] + @@settings[param] end end diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index afa51f4e9cb..92ca1f4640d 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -184,10 +184,10 @@ def option(*options, &block) define_method(fname, &block) else define_method(fname) do |value| - self.options["#{long}".to_sym] = value + self.options[long.to_s.to_sym] = value end end - self.option_parser_commands << [options, fname] + option_parser_commands << [options, fname] end def banner(banner = nil) @@ -254,14 +254,14 @@ def find(application_name) raise Puppet::Error, _("Unable to load application class '%{class_name}' from file 'puppet/application/%{application_name}.rb'") % { class_name: class_name, application_name: application_name } end - return clazz + clazz end # Given the fully qualified name of a class, attempt to get the class instance. # @param [String] class_name the fully qualified name of the class to try to load # @return [Class] the Class instance, or nil? if it could not be loaded. def try_load_class(class_name) - return self.const_defined?(class_name) ? const_get(class_name) : nil + const_defined?(class_name) ? const_get(class_name) : nil end private :try_load_class @@ -330,7 +330,7 @@ def clear_everything_for_tests # See also `lib/puppet/util/command_line.rb` for some special case early # handling of this. option("--version", "-V") do |_arg| - puts "#{Puppet.version}" + puts Puppet.version exit(0) end @@ -553,14 +553,14 @@ def parse_options self.class.option_parser_commands.each do |options, fname| option_parser.on(*options) do |value| # Call the method that "option()" created. - self.send(fname, value) + send(fname, value) end end # Scan command line. We just hand any exceptions to our upper levels, # rather than printing help and exiting, so that we can meaningfully # respond with context-sensitive help if we want to. --daniel 2011-04-12 - option_parser.parse!(self.command_line.args) + option_parser.parse!(command_line.args) end def handlearg(opt, val) diff --git a/lib/puppet/application/describe.rb b/lib/puppet/application/describe.rb index 7e2969878f7..1b11c9fa0d8 100644 --- a/lib/puppet/application/describe.rb +++ b/lib/puppet/application/describe.rb @@ -44,9 +44,9 @@ def scrub(text) # indent from every line. if text =~ /^(\s+)/ indent = ::Regexp.last_match(1) - return text.gsub(/^#{indent}/, '') + text.gsub(/^#{indent}/, '') else - return text + text end end end diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb index 073a6172790..b6da159d96b 100644 --- a/lib/puppet/application/doc.rb +++ b/lib/puppet/application/doc.rb @@ -122,7 +122,7 @@ def handle_unknown(opt, arg) end def run_command - return [:rdoc].include?(options[:mode]) ? send(options[:mode]) : other + [:rdoc].include?(options[:mode]) ? send(options[:mode]) : other end def rdoc diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb index 8e81025c070..b3a7363db52 100644 --- a/lib/puppet/application/face_base.rb +++ b/lib/puppet/application/face_base.rb @@ -164,7 +164,7 @@ def find_global_settings_argument(item) pattern.match item and return object end end - return nil # nothing found. + nil # nothing found. end def find_application_argument(item) @@ -181,7 +181,7 @@ def find_application_argument(item) } end end - return nil # not found + nil # not found end def setup diff --git a/lib/puppet/application/ssl.rb b/lib/puppet/application/ssl.rb index 4434163bac5..00c665ab795 100644 --- a/lib/puppet/application/ssl.rb +++ b/lib/puppet/application/ssl.rb @@ -234,7 +234,7 @@ def download_cert(ssl_context) cert rescue Puppet::HTTP::ResponseError => e if e.response.code == 404 - return nil + nil else raise Puppet::Error.new(_("Failed to download certificate: %{message}") % { message: e.message }, e) end diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb index dc340305be5..cea6c5c2500 100644 --- a/lib/puppet/configurer.rb +++ b/lib/puppet/configurer.rb @@ -505,7 +505,7 @@ def run_internal(options) true rescue => detail Puppet.log_exception(detail, _("Failed to apply catalog: %{detail}") % { detail: detail }) - return nil + nil ensure execute_postrun_command or return nil # rubocop:disable Lint/EnsureReturn end @@ -675,12 +675,12 @@ def resubmit_facts puppet.put_facts(facts.name, facts: facts, environment: Puppet.lookup(:current_environment).name.to_s) - return true + true rescue => detail Puppet.log_exception(detail, _("Failed to submit facts: %{detail}") % { detail: detail }) - return false + false end private @@ -722,7 +722,7 @@ def retrieve_catalog_from_cache(query_options) result rescue => detail Puppet.log_exception(detail, _("Could not retrieve catalog from cache: %{detail}") % { detail: detail }) - return nil + nil end def retrieve_new_catalog(facts, query_options) @@ -744,7 +744,7 @@ def retrieve_new_catalog(facts, query_options) result rescue StandardError => detail Puppet.log_exception(detail, _("Could not retrieve catalog from remote server: %{detail}") % { detail: detail }) - return nil + nil end def download_plugins(remote_environment_for_plugins) diff --git a/lib/puppet/configurer/downloader.rb b/lib/puppet/configurer/downloader.rb index 52928f8eccd..61c05e44420 100644 --- a/lib/puppet/configurer/downloader.rb +++ b/lib/puppet/configurer/downloader.rb @@ -86,6 +86,6 @@ def default_arguments defargs[:owner] = Process.uid defargs[:group] = Process.gid end - return defargs + defargs end end diff --git a/lib/puppet/confine.rb b/lib/puppet/confine.rb index 752d6452c37..003a54169da 100644 --- a/lib/puppet/confine.rb +++ b/lib/puppet/confine.rb @@ -75,7 +75,7 @@ def valid? end end - return true + true ensure reset end diff --git a/lib/puppet/confine/variable.rb b/lib/puppet/confine/variable.rb index 4c4cf31622d..3a194f1c424 100644 --- a/lib/puppet/confine/variable.rb +++ b/lib/puppet/confine/variable.rb @@ -29,7 +29,7 @@ def initialize(values) end def message(value) - "facter value '#{test_value}' for '#{self.name}' not in required list '#{values.join(",")}'" + "facter value '#{test_value}' for '#{name}' not in required list '#{values.join(",")}'" end # Compare the passed-in value to the retrieved value. diff --git a/lib/puppet/confine_collection.rb b/lib/puppet/confine_collection.rb index 08fb3cc63da..d50028ea319 100644 --- a/lib/puppet/confine_collection.rb +++ b/lib/puppet/confine_collection.rb @@ -22,7 +22,7 @@ def confine(hash) confine.name = test @confines << confine end - @confines[-1].label = self.label + @confines[-1].label = label end end diff --git a/lib/puppet/confiner.rb b/lib/puppet/confiner.rb index 563808ee0b8..f4d1dc4492f 100644 --- a/lib/puppet/confiner.rb +++ b/lib/puppet/confiner.rb @@ -33,7 +33,7 @@ def confine(hash) # @api private # def confine_collection - @confine_collection ||= Puppet::ConfineCollection.new(self.to_s) + @confine_collection ||= Puppet::ConfineCollection.new(to_s) end # Checks whether this implementation is suitable for the current platform (or returns a summary @@ -43,6 +43,6 @@ def confine_collection # @api public # def suitable?(short = true) - return(short ? confine_collection.valid? : confine_collection.summary) + (short ? confine_collection.valid? : confine_collection.summary) end end diff --git a/lib/puppet/environments.rb b/lib/puppet/environments.rb index a3c4d829d66..29536d529e0 100644 --- a/lib/puppet/environments.rb +++ b/lib/puppet/environments.rb @@ -194,7 +194,7 @@ def self.real_path(dir) if Puppet::FileSystem.symlink?(dir) && Puppet[:versioned_environment_dirs] dir = Pathname.new Puppet::FileSystem.expand_path(Puppet::FileSystem.readlink(dir)) end - return dir + dir end # @!macro loader_search_paths diff --git a/lib/puppet/error.rb b/lib/puppet/error.rb index 96d2335e2e8..30c67ed8f45 100644 --- a/lib/puppet/error.rb +++ b/lib/puppet/error.rb @@ -98,7 +98,7 @@ def to_h def self.from_issue_and_stack(issue, args = {}) filename, line = Puppet::Pops::PuppetStack.top_of_stack - self.new( + new( issue.format(args), filename, line, diff --git a/lib/puppet/external/dot.rb b/lib/puppet/external/dot.rb index ac2cc255921..c8177a4424d 100644 --- a/lib/puppet/external/dot.rb +++ b/lib/puppet/external/dot.rb @@ -165,7 +165,7 @@ def initialize(params = {}) end def to_s - (@name && @name != "" ? "<#{@name}>" : "") + "#{@label}" + (@name && @name != "" ? "<#{@name}>" : "") + @label.to_s end end diff --git a/lib/puppet/face/help.rb b/lib/puppet/face/help.rb index adcdce764b1..cfd71c902fc 100644 --- a/lib/puppet/face/help.rb +++ b/lib/puppet/face/help.rb @@ -95,7 +95,7 @@ def render_face_man(facename) end def render_application_help(applicationname) - return Puppet::Application[applicationname].help + Puppet::Application[applicationname].help rescue StandardError, LoadError => detail message = [] message << _('Could not load help for the application %{application_name}.') % { application_name: applicationname } @@ -107,7 +107,7 @@ def render_application_help(applicationname) def render_face_help(facename, actionname, version) face, action = load_face_help(facename, actionname, version) - return template_for(face, action).result(binding) + template_for(face, action).result(binding) rescue StandardError, LoadError => detail message = [] message << _('Could not load help for the face %{face_name}.') % { face_name: facename } @@ -141,7 +141,7 @@ def erb(name) template = (Pathname(__FILE__).dirname + "help" + name) erb = Puppet::Util.create_erb(template.read) erb.filename = template.to_s - return erb + erb end # Return a list of applications that are not simply just stubs for Faces. @@ -213,7 +213,7 @@ def horribly_extract_summary_from(appname) return md[1] end end - return '' + '' end # This should absolutely be a private method, but for some reason it appears # that you can't use the 'private' keyword inside of a Face definition. diff --git a/lib/puppet/face/module/changes.rb b/lib/puppet/face/module/changes.rb index bea0bba9c49..66256a29a8d 100644 --- a/lib/puppet/face/module/changes.rb +++ b/lib/puppet/face/module/changes.rb @@ -39,7 +39,7 @@ Puppet.warning _("%{count} files modified") % { count: return_value.size } end return_value.map do |changed_file| - "#{changed_file}" + changed_file.to_s end.join("\n") end end diff --git a/lib/puppet/face/node/clean.rb b/lib/puppet/face/node/clean.rb index 3f817136f3f..0be63f74bf4 100644 --- a/lib/puppet/face/node/clean.rb +++ b/lib/puppet/face/node/clean.rb @@ -104,6 +104,6 @@ def type_is_ensurable(resource) return true if type && type.arguments.keys.include?('ensure') end - return false + false end end diff --git a/lib/puppet/facter_impl.rb b/lib/puppet/facter_impl.rb index 524737e39b2..4abec318cc8 100644 --- a/lib/puppet/facter_impl.rb +++ b/lib/puppet/facter_impl.rb @@ -58,7 +58,7 @@ def load_external? end def load_external(value) - ::Facter.load_external(value) if self.load_external? + ::Facter.load_external(value) if load_external? end private diff --git a/lib/puppet/file_bucket/dipper.rb b/lib/puppet/file_bucket/dipper.rb index 1de5c23296e..31312e8cccd 100644 --- a/lib/puppet/file_bucket/dipper.rb +++ b/lib/puppet/file_bucket/dipper.rb @@ -52,7 +52,7 @@ def backup(file) Puppet::FileBucket::File.indirection.save(file_bucket_file, dest_path) end - return file_bucket_file.checksum_data + file_bucket_file.checksum_data rescue => detail message = _("Could not back up %{file}: %{detail}") % { file: file, detail: detail } Puppet.log_exception(detail, message) @@ -152,9 +152,9 @@ def restore(file, sum) Puppet.err _("Could not find file with checksum %{sum}") % { sum: sum } return nil end - return newsum + newsum else - return nil + nil end end diff --git a/lib/puppet/file_bucket/file.rb b/lib/puppet/file_bucket/file.rb index 55639ac6bfe..4c92bc585ee 100644 --- a/lib/puppet/file_bucket/file.rb +++ b/lib/puppet/file_bucket/file.rb @@ -73,7 +73,7 @@ def name end def self.from_binary(contents) - self.new(contents) + new(contents) end class StringContents @@ -102,7 +102,7 @@ def checksum_data(base_method) def to_binary # This is not so horrible as for FileContent, but still possible to mutate the content that the # checksum is based on... so semi horrible... - return @contents; + @contents; end end diff --git a/lib/puppet/file_serving/base.rb b/lib/puppet/file_serving/base.rb index d2713a9f25e..6e55c05a1c1 100644 --- a/lib/puppet/file_serving/base.rb +++ b/lib/puppet/file_serving/base.rb @@ -13,9 +13,9 @@ class Puppet::FileServing::Base # Does our file exist? def exist? stat - return true + true rescue - return false + false end # Return the full path to our file. Fails if there's no path set. @@ -76,7 +76,7 @@ def relative_path=(path) # Stat our file, using the appropriate link-sensitive method. def stat - @stat_method ||= self.links == :manage ? :lstat : :stat + @stat_method ||= links == :manage ? :lstat : :stat Puppet::FileSystem.send(@stat_method, full_path) end diff --git a/lib/puppet/file_serving/configuration.rb b/lib/puppet/file_serving/configuration.rb index c5442f3515f..cc771050f50 100644 --- a/lib/puppet/file_serving/configuration.rb +++ b/lib/puppet/file_serving/configuration.rb @@ -74,7 +74,7 @@ def split_path(request) path = path.gsub(%r{/+}, "/") end - return mount, path + [mount, path] end def umount(name) diff --git a/lib/puppet/file_serving/fileset.rb b/lib/puppet/file_serving/fileset.rb index 84cc0ac8f54..da4981dfc0c 100644 --- a/lib/puppet/file_serving/fileset.rb +++ b/lib/puppet/file_serving/fileset.rb @@ -185,6 +185,6 @@ def valid?(path) def continue_recursion_at?(depth) # recurse if told to, and infinite recursion or current depth not at the limit - self.recurse && (self.recurselimit == :infinite || depth <= self.recurselimit) + recurse && (recurselimit == :infinite || depth <= recurselimit) end end diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb index 6edfec97f84..ab1bd6937c3 100644 --- a/lib/puppet/file_serving/metadata.rb +++ b/lib/puppet/file_serving/metadata.rb @@ -80,7 +80,7 @@ def initialize(stat, path, source_permissions) :group => 'S-1-0-0', :mode => 0o644 }.each do |method, default_value| define_method method do - return default_value + default_value end end end diff --git a/lib/puppet/file_serving/mount/file.rb b/lib/puppet/file_serving/mount/file.rb index 6454e0c8bcf..73f860f9d10 100644 --- a/lib/puppet/file_serving/mount/file.rb +++ b/lib/puppet/file_serving/mount/file.rb @@ -40,9 +40,9 @@ def find(short_file, request) # Return the path as appropriate, expanding as necessary. def path(node = nil) if expandable? - return expand(@path, node) + expand(@path, node) else - return @path + @path end end diff --git a/lib/puppet/file_system/memory_impl.rb b/lib/puppet/file_system/memory_impl.rb index f2cc71b0093..a909a90e65e 100644 --- a/lib/puppet/file_system/memory_impl.rb +++ b/lib/puppet/file_system/memory_impl.rb @@ -74,7 +74,7 @@ def open(path, *args, &block) if block_given? yield handle else - return handle + handle end end diff --git a/lib/puppet/file_system/windows.rb b/lib/puppet/file_system/windows.rb index 988d6245b04..ca4c8b6a5c3 100644 --- a/lib/puppet/file_system/windows.rb +++ b/lib/puppet/file_system/windows.rb @@ -36,7 +36,7 @@ def expand_path(path, dir_string = nil) end def exist?(path) - return Puppet::Util::Windows::File.exist?(path) + Puppet::Util::Windows::File.exist?(path) end def symlink(path, dest, options = {}) diff --git a/lib/puppet/forge.rb b/lib/puppet/forge.rb index 8f084766627..9fad982ae5e 100644 --- a/lib/puppet/forge.rb +++ b/lib/puppet/forge.rb @@ -114,7 +114,7 @@ def fetch(input) uri = decode_uri(response['pagination']['next']) end - return releases + releases end def make_http_request(*args) @@ -148,7 +148,7 @@ def initialize(source, data) end def install(dir) - staging_dir = self.prepare + staging_dir = prepare module_dir = dir + name[/-(.*)/, 1] module_dir.rmtree if module_dir.exist? @@ -161,7 +161,7 @@ def install(dir) # Return the Pathname object representing the directory where the # module release archive was unpacked the to. - return module_dir + module_dir ensure staging_dir.rmtree if staging_dir.exist? end diff --git a/lib/puppet/forge/cache.rb b/lib/puppet/forge/cache.rb index c004ce4fa60..17d91422d41 100644 --- a/lib/puppet/forge/cache.rb +++ b/lib/puppet/forge/cache.rb @@ -38,7 +38,7 @@ def retrieve(url) # Return contents of file at the given URI's +uri+. def read_retrieve(uri) - return uri.read + uri.read end # Return Pathname for repository's cache directory, create it if needed. diff --git a/lib/puppet/forge/errors.rb b/lib/puppet/forge/errors.rb index 18732ed5a93..84dff168c78 100644 --- a/lib/puppet/forge/errors.rb +++ b/lib/puppet/forge/errors.rb @@ -13,7 +13,7 @@ class ForgeError < Puppet::Error # # @return [String] the multiline version of the error message def multiline - self.message + message end end diff --git a/lib/puppet/forge/repository.rb b/lib/puppet/forge/repository.rb index a18be50fea3..fcf23afb9ea 100644 --- a/lib/puppet/forge/repository.rb +++ b/lib/puppet/forge/repository.rb @@ -69,7 +69,7 @@ def forge_authorization # repository at +release+ (e.g. "myuser-mymodule"). def retrieve(release) path = @host.chomp('/') + release - return cache.retrieve(path) + cache.retrieve(path) end # Return the URI string for this repository. @@ -80,7 +80,7 @@ def to_s # Return the cache key for this repository, this a hashed string based on # the URI. def cache_key - return @cache_key ||= [ + @cache_key ||= [ @host.to_s.gsub(/[^[:alnum:]]+/, '_').sub(/_$/, ''), Digest::SHA1.hexdigest(@host.to_s) ].join('-').freeze diff --git a/lib/puppet/functions.rb b/lib/puppet/functions.rb index a00d6e3990e..c033f058f67 100644 --- a/lib/puppet/functions.rb +++ b/lib/puppet/functions.rb @@ -569,7 +569,7 @@ def dispatch(meth_name, argument_mismatch_handler, &block) @block_name = nil @return_type = nil @argument_mismatch_hander = argument_mismatch_handler - self.instance_eval(&block) + instance_eval(&block) callable_t = create_callable(@types, @block_type, @return_type, @min, @max) @dispatcher.add(Puppet::Pops::Functions::Dispatch.new(callable_t, meth_name, @names, @max == :default, @block_name, @injections, @weaving, @argument_mismatch_hander)) end @@ -748,7 +748,7 @@ def call(scope, *args, &block) # this is the scope.function_xxx(...) call return scope.send(self.class.method3x, mapped_args) end - return result.value + result.value rescue Puppet::Pops::Evaluator::Next => jumper begin throw :next, jumper.value diff --git a/lib/puppet/functions/compare.rb b/lib/puppet/functions/compare.rb index 9f5c8afb1f3..accce889ae7 100644 --- a/lib/puppet/functions/compare.rb +++ b/lib/puppet/functions/compare.rb @@ -115,7 +115,7 @@ def on_error(a, b, *ignore_case) if a.class != b.class # TRANSLATORS 'compare' is a name - return _("compare(): Can only compare values of the same type (or for Timestamp/Timespan also against Numeric). Got %{type_a} and %{type_b}") % { + _("compare(): Can only compare values of the same type (or for Timestamp/Timespan also against Numeric). Got %{type_a} and %{type_b}") % { type_a: type_label(a), type_b: type_label(b) } end diff --git a/lib/puppet/functions/get.rb b/lib/puppet/functions/get.rb index 33c89572461..6fe21373542 100644 --- a/lib/puppet/functions/get.rb +++ b/lib/puppet/functions/get.rb @@ -138,7 +138,7 @@ def get_from_value(value, navigation, default_value = nil, &block) begin result = call_function('dig', value, *segments) - return result.nil? ? default_value : result + result.nil? ? default_value : result rescue Puppet::ErrorWithData => e if block_given? yield(e.error_data) diff --git a/lib/puppet/functions/new.rb b/lib/puppet/functions/new.rb index 424cde559a8..9ffe34b841f 100644 --- a/lib/puppet/functions/new.rb +++ b/lib/puppet/functions/new.rb @@ -994,7 +994,7 @@ def new_instance(scope, t, *args) return args[0] if args.size == 1 && !t.is_a?(Puppet::Pops::Types::PInitType) && t.instance?(args[0]) result = assert_type(t, new_function_for_type(t).call(scope, *args)) - return block_given? ? yield(result) : result + block_given? ? yield(result) : result end def new_function_for_type(t) diff --git a/lib/puppet/gettext/config.rb b/lib/puppet/gettext/config.rb index 9581566eaf0..e9a9bcfb508 100644 --- a/lib/puppet/gettext/config.rb +++ b/lib/puppet/gettext/config.rb @@ -43,9 +43,9 @@ def self.gettext_loaded? # @return [String] the active locale def self.current_locale if gettext_loaded? - return FastGettext.default_locale + FastGettext.default_locale else - return 'en' + 'en' end end @@ -55,7 +55,7 @@ def self.current_locale def self.loaded_text_domains return [] if @gettext_disabled || !gettext_loaded? - return FastGettext.translation_repositories.keys + FastGettext.translation_repositories.keys end # @api private @@ -191,11 +191,11 @@ def self.copy_default_translations(domain_name) # @return [String] path to the config, or nil if not found def self.puppet_locale_path if Puppet::FileSystem.exist?(LOCAL_PATH) - return LOCAL_PATH + LOCAL_PATH elsif Puppet::Util::Platform.windows? && Puppet::FileSystem.exist?(WINDOWS_PATH) - return WINDOWS_PATH + WINDOWS_PATH elsif !Puppet::Util::Platform.windows? && Puppet::FileSystem.exist?(POSIX_PATH) - return POSIX_PATH + POSIX_PATH else nil end @@ -207,9 +207,9 @@ def self.puppet_locale_path # @return [Symbol] :mo if in a package structure, :po otherwise def self.translation_mode(conf_path) if WINDOWS_PATH == conf_path || POSIX_PATH == conf_path - return :mo + :mo else - return :po + :po end end @@ -239,7 +239,7 @@ def self.load_translations(project_name, locale_dir, file_format, text_domain = end add_repository_to_domain(project_name, locale_dir, file_format, text_domain) - return true + true end # @api private diff --git a/lib/puppet/graph/rb_tree_map.rb b/lib/puppet/graph/rb_tree_map.rb index 2c75718261d..cf757c933cf 100644 --- a/lib/puppet/graph/rb_tree_map.rb +++ b/lib/puppet/graph/rb_tree_map.rb @@ -329,7 +329,7 @@ def delete_recursive(node, key) node.right, result = delete_recursive(node.right, key) end end - return node.fixup, result + [node.fixup, result] end def delete_min_recursive(node) @@ -342,7 +342,7 @@ def delete_min_recursive(node) end node.left, result = delete_min_recursive(node.left) - return node.fixup, result + [node.fixup, result] end def delete_max_recursive(node) @@ -356,16 +356,16 @@ def delete_max_recursive(node) end node.right, result = delete_max_recursive(node.right) - return node.fixup, result + [node.fixup, result] end def get_recursive(node, key) return nil if node.nil? case key <=> node.key - when 0 then return node - when -1 then return get_recursive(node.left, key) - when 1 then return get_recursive(node.right, key) + when 0 then node + when -1 then get_recursive(node.left, key) + when 1 then get_recursive(node.right, key) end end diff --git a/lib/puppet/graph/simple_graph.rb b/lib/puppet/graph/simple_graph.rb index a050b365df1..308ae18d6cd 100644 --- a/lib/puppet/graph/simple_graph.rb +++ b/lib/puppet/graph/simple_graph.rb @@ -223,7 +223,7 @@ def paths_in_cycle(cycle, max_paths = 1) end end - return found.sort + found.sort end # @return [Array] array of dependency cycles (arrays) @@ -268,7 +268,7 @@ def write_cycles_to_graph(cycles) filename = File.join(Puppet[:graphdir], "cycles.dot") # DOT files are assumed to be UTF-8 by default - http://www.graphviz.org/doc/info/lang.html File.open(filename, "w:UTF-8") { |f| f.puts graph } - return filename + filename end # Add a new vertex to the graph. diff --git a/lib/puppet/http/dns.rb b/lib/puppet/http/dns.rb index 833165dcf07..4e148b8c363 100644 --- a/lib/puppet/http/dns.rb +++ b/lib/puppet/http/dns.rb @@ -118,7 +118,7 @@ def weight(record) # @param [String] service_name the service whose TTL we want # @return [Integer] the TTL for this service, in seconds def ttl(service_name) - return @record_cache[service_name].ttl + @record_cache[service_name].ttl end # Checks if the cached entry for the given service has expired. @@ -128,9 +128,9 @@ def ttl(service_name) def expired?(service_name) entry = @record_cache[service_name] if entry - return Time.now > (entry.resolution_time + entry.ttl) + Time.now > (entry.resolution_time + entry.ttl) else - return true + true end end diff --git a/lib/puppet/http/proxy.rb b/lib/puppet/http/proxy.rb index cb01e3fbe2d..e1d642a751e 100644 --- a/lib/puppet/http/proxy.rb +++ b/lib/puppet/http/proxy.rb @@ -6,7 +6,7 @@ module Puppet::HTTP::Proxy def self.proxy(uri) if http_proxy_host && !no_proxy?(uri) - Net::HTTP.new(uri.host, uri.port, self.http_proxy_host, self.http_proxy_port, self.http_proxy_user, self.http_proxy_password) + Net::HTTP.new(uri.host, uri.port, http_proxy_host, http_proxy_port, http_proxy_user, http_proxy_password) else http = Net::HTTP.new(uri.host, uri.port, nil, nil, nil, nil) # Net::HTTP defaults the proxy port even though we said not to @@ -24,7 +24,7 @@ def self.http_proxy_env rescue URI::InvalidURIError return nil end - return nil + nil end # The documentation around the format of the no_proxy variable seems @@ -60,7 +60,7 @@ def self.no_proxy?(dest) dest_string = "#{dest.host}:#{dest.port}" else no_proxy_regex = /#{host}$/ - dest_string = "#{dest.host}" + dest_string = dest.host.to_s end if no_proxy_regex.match(dest_string) @@ -68,11 +68,11 @@ def self.no_proxy?(dest) end end - return false + false end def self.http_proxy_host - env = self.http_proxy_env + env = http_proxy_env if env and env.host return env.host @@ -82,21 +82,21 @@ def self.http_proxy_host return nil end - return Puppet.settings[:http_proxy_host] + Puppet.settings[:http_proxy_host] end def self.http_proxy_port - env = self.http_proxy_env + env = http_proxy_env if env and env.port return env.port end - return Puppet.settings[:http_proxy_port] + Puppet.settings[:http_proxy_port] end def self.http_proxy_user - env = self.http_proxy_env + env = http_proxy_env if env and env.user return env.user @@ -106,11 +106,11 @@ def self.http_proxy_user return nil end - return Puppet.settings[:http_proxy_user] + Puppet.settings[:http_proxy_user] end def self.http_proxy_password - env = self.http_proxy_env + env = http_proxy_env if env and env.password return env.password @@ -120,7 +120,7 @@ def self.http_proxy_password return nil end - return Puppet.settings[:http_proxy_password] + Puppet.settings[:http_proxy_password] end def self.no_proxy @@ -134,6 +134,6 @@ def self.no_proxy return nil end - return Puppet.settings[:no_proxy] + Puppet.settings[:no_proxy] end end diff --git a/lib/puppet/http/resolver.rb b/lib/puppet/http/resolver.rb index 5b9164ec5c2..85200b7084a 100644 --- a/lib/puppet/http/resolver.rb +++ b/lib/puppet/http/resolver.rb @@ -42,9 +42,9 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil) # @api public def check_connection?(session, service, ssl_context: nil) service.connect(ssl_context: ssl_context) - return true + true rescue Puppet::HTTP::ConnectionError => e Puppet.log_exception(e, "Connection to #{service.url} failed, trying next route: #{e.message}") - return false + false end end diff --git a/lib/puppet/http/site.rb b/lib/puppet/http/site.rb index 5b6f0100a1a..036cd819421 100644 --- a/lib/puppet/http/site.rb +++ b/lib/puppet/http/site.rb @@ -10,7 +10,7 @@ class Puppet::HTTP::Site attr_reader :scheme, :host, :port def self.from_uri(uri) - self.new(uri.scheme, uri.host, uri.port) + new(uri.scheme, uri.host, uri.port) end def initialize(scheme, host, port) diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index 15e1f7e4a6a..0ef64b3e304 100644 --- a/lib/puppet/indirector/catalog/compiler.rb +++ b/lib/puppet/indirector/catalog/compiler.rb @@ -120,9 +120,9 @@ def convert_wire_facts(facts, format) when 'pson' # We unescape here because the corresponding code in Puppet::Configurer::FactHandler encodes with Puppet::Util.uri_query_encode # PSON is deprecated, but continue to accept from older agents - return Puppet::Node::Facts.convert_from('pson', CGI.unescape(facts)) + Puppet::Node::Facts.convert_from('pson', CGI.unescape(facts)) when 'application/json' - return Puppet::Node::Facts.convert_from('json', CGI.unescape(facts)) + Puppet::Node::Facts.convert_from('json', CGI.unescape(facts)) else raise ArgumentError, _("Unsupported facts format") end @@ -156,24 +156,23 @@ def get_content_uri(metadata, source, environment_path) source_as_uri = URI.parse(Puppet::Util.uri_encode(source)) server = source_as_uri.host port = ":#{source_as_uri.port}" if source_as_uri.port - return "puppet://#{server}#{port}/#{path}" + "puppet://#{server}#{port}/#{path}" end # Helper method to decide if a file resource's metadata can be inlined. # Also used to profile/log reasons for not inlining. def inlineable?(resource, sources) - case - when resource[:ensure] == 'absent' + if resource[:ensure] == 'absent' # TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining) - return Puppet::Util::Profiler.profile(_("Not inlining absent resource"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :absent]) { false } - when sources.empty? + Puppet::Util::Profiler.profile(_("Not inlining absent resource"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :absent]) { false } + elsif sources.empty? # TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining) - return Puppet::Util::Profiler.profile(_("Not inlining resource without sources"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :no_sources]) { false } - when !(sources.all? { |source| source =~ /^puppet:/ }) + Puppet::Util::Profiler.profile(_("Not inlining resource without sources"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :no_sources]) { false } + elsif !(sources.all? { |source| source =~ /^puppet:/ }) # TRANSLATORS Inlining refers to adding additional metadata (in this case we are not inlining) - return Puppet::Util::Profiler.profile(_("Not inlining unsupported source scheme"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :unsupported_scheme]) { false } + Puppet::Util::Profiler.profile(_("Not inlining unsupported source scheme"), [:compiler, :static_compile_inlining, :skipped_file_metadata, :unsupported_scheme]) { false } else - return true + true end end diff --git a/lib/puppet/indirector/exec.rb b/lib/puppet/indirector/exec.rb index a851c2dbdff..6e8a47218cf 100644 --- a/lib/puppet/indirector/exec.rb +++ b/lib/puppet/indirector/exec.rb @@ -25,9 +25,9 @@ def find(request) if output =~ /\A\s*\Z/ # all whitespace Puppet.debug { "Empty response for #{name} from #{self.name} terminus" } - return nil + nil else - return output + output end end diff --git a/lib/puppet/indirector/face.rb b/lib/puppet/indirector/face.rb index 8593c581aa9..5db462ae6d3 100644 --- a/lib/puppet/indirector/face.rb +++ b/lib/puppet/indirector/face.rb @@ -53,7 +53,7 @@ def call_indirection_method(method, key, options) raise RuntimeError, message, detail.backtrace end - return result + result end action :destroy do diff --git a/lib/puppet/indirector/fact_search.rb b/lib/puppet/indirector/fact_search.rb index 772e5f614ad..a1a4c44a3e0 100644 --- a/lib/puppet/indirector/fact_search.rb +++ b/lib/puppet/indirector/fact_search.rb @@ -9,7 +9,7 @@ def node_matches?(facts, options) return false unless node_matches_option?(type, name, operator, value, facts) end - return true + true end def node_matches_option?(type, name, operator, value, facts) diff --git a/lib/puppet/indirector/facts/json.rb b/lib/puppet/indirector/facts/json.rb index 7c89bb1595c..fdf502b87fe 100644 --- a/lib/puppet/indirector/facts/json.rb +++ b/lib/puppet/indirector/facts/json.rb @@ -24,6 +24,6 @@ def search(request) private def json_dir_path - self.path("*") + path("*") end end diff --git a/lib/puppet/indirector/file_bucket_file/file.rb b/lib/puppet/indirector/file_bucket_file/file.rb index 72eb127eb4b..d0cd2d0ea88 100644 --- a/lib/puppet/indirector/file_bucket_file/file.rb +++ b/lib/puppet/indirector/file_bucket_file/file.rb @@ -31,7 +31,7 @@ def find(request) raise _("could not find diff_with %{diff}") % { diff: request.options[:diff_with] } unless Puppet::FileSystem.exist?(other_contents_file) raise _("Unable to diff on this platform") unless Puppet[:diff] != "" - return diff(Puppet::FileSystem.path_string(contents_file), Puppet::FileSystem.path_string(other_contents_file)) + diff(Puppet::FileSystem.path_string(contents_file), Puppet::FileSystem.path_string(other_contents_file)) else # TRANSLATORS "FileBucket" should not be translated Puppet.info _("FileBucket read %{checksum}") % { checksum: checksum } @@ -88,7 +88,7 @@ def list(request) msg += "#{chksum} #{date} #{filename}\n" } } - return model.new(msg) + model.new(msg) end def head(request) @@ -137,7 +137,7 @@ def path_match(file_handle, files_original_path) file_handle.each_line do |line| return true if line.chomp == files_original_path end - return false + false end # @param bucket_file [Puppet::FileBucket::File] IO object representing diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 63afaa7d2d2..d1f354bbcde 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -135,13 +135,13 @@ def set_global_setting(setting, value) # Set up our request object. def request(*args) - Puppet::Indirector::Request.new(self.name, *args) + Puppet::Indirector::Request.new(name, *args) end # Return the singleton terminus for this indirection. def terminus(terminus_name = nil) # Get the name of the terminus. - raise Puppet::DevError, _("No terminus specified for %{name}; cannot redirect") % { name: self.name } unless terminus_name ||= terminus_class + raise Puppet::DevError, _("No terminus specified for %{name}; cannot redirect") % { name: name } unless terminus_name ||= terminus_class termini[terminus_name] ||= make_terminus(terminus_name) end @@ -158,11 +158,11 @@ def terminus_setting=(setting) # Determine the terminus class. def terminus_class unless @terminus_class.value - setting = self.terminus_setting + setting = terminus_setting if setting self.terminus_class = Puppet.settings[setting] else - raise Puppet::DevError, _("No terminus class nor terminus setting was provided for indirection %{name}") % { name: self.name } + raise Puppet::DevError, _("No terminus class nor terminus setting was provided for indirection %{name}") % { name: name } end end @terminus_class.value @@ -184,9 +184,9 @@ def validate_terminus_class(terminus_class) raise ArgumentError, _("Invalid terminus name %{terminus_class}") % { terminus_class: terminus_class.inspect } end - unless Puppet::Indirector::Terminus.terminus_class(self.name, terminus_class) + unless Puppet::Indirector::Terminus.terminus_class(name, terminus_class) raise ArgumentError, _("Could not find terminus %{terminus_class} for indirection %{name}") % - { terminus_class: terminus_class, name: self.name } + { terminus_class: terminus_class, name: name } end end @@ -201,7 +201,7 @@ def expire(key, options = {}) instance = cache.find(request(:find, key, nil, options)) return nil unless instance - Puppet.info _("Expiring the %{cache} cache of %{instance}") % { cache: self.name, instance: instance.name } + Puppet.info _("Expiring the %{cache} cache of %{instance}") % { cache: name, instance: instance.name } # Set an expiration date in the past instance.expiration = Time.now - 60 @@ -229,9 +229,9 @@ def find(key, options = {}) # appropriate. result = terminus.find(request) unless result.nil? - result.expiration ||= self.expiration if result.respond_to?(:expiration) + result.expiration ||= expiration if result.respond_to?(:expiration) if cache? && !request.ignore_cache_save? - Puppet.info _("Caching %{indirection} for %{request}") % { indirection: self.name, request: request.key } + Puppet.info _("Caching %{indirection} for %{request}") % { indirection: name, request: request.key } begin cache.save request(:save, key, result, options) rescue => detail @@ -242,7 +242,7 @@ def find(key, options = {}) filtered = result if terminus.respond_to?(:filter) - Puppet::Util::Profiler.profile(_("Filtered result for %{indirection} %{request}") % { indirection: self.name, request: request.key }, [:indirector, :filter, self.name, request.key]) do + Puppet::Util::Profiler.profile(_("Filtered result for %{indirection} %{request}") % { indirection: name, request: request.key }, [:indirector, :filter, name, request.key]) do filtered = terminus.filter(result) rescue Puppet::Error => detail Puppet.log_exception(detail) @@ -271,14 +271,14 @@ def find_in_cache(request) return nil unless cached if cached.expired? - Puppet.info _("Not using expired %{indirection} for %{request} from cache; expired at %{expiration}") % { indirection: self.name, request: request.key, expiration: cached.expiration } + Puppet.info _("Not using expired %{indirection} for %{request} from cache; expired at %{expiration}") % { indirection: name, request: request.key, expiration: cached.expiration } return nil end - Puppet.debug { "Using cached #{self.name} for #{request.key}" } + Puppet.debug { "Using cached #{name} for #{request.key}" } cached rescue => detail - Puppet.log_exception(detail, _("Cached %{indirection} for %{request} failed: %{detail}") % { indirection: self.name, request: request.key, detail: detail }) + Puppet.log_exception(detail, _("Cached %{indirection} for %{request} failed: %{detail}") % { indirection: name, request: request.key, detail: detail }) nil end @@ -309,9 +309,9 @@ def search(key, options = {}) result.each do |instance| next unless instance.respond_to? :expiration - instance.expiration ||= self.expiration + instance.expiration ||= expiration end - return result + result end end @@ -371,9 +371,9 @@ def prepare(request) # Create a new terminus instance. def make_terminus(terminus_class) # Load our terminus class. - klass = Puppet::Indirector::Terminus.terminus_class(self.name, terminus_class) + klass = Puppet::Indirector::Terminus.terminus_class(name, terminus_class) unless klass - raise ArgumentError, _("Could not find terminus %{terminus_class} for indirection %{indirection}") % { terminus_class: terminus_class, indirection: self.name } + raise ArgumentError, _("Could not find terminus %{terminus_class} for indirection %{indirection}") % { terminus_class: terminus_class, indirection: name } end klass.new diff --git a/lib/puppet/indirector/json.rb b/lib/puppet/indirector/json.rb index 892cc238c1d..658e14a9f39 100644 --- a/lib/puppet/indirector/json.rb +++ b/lib/puppet/indirector/json.rb @@ -18,14 +18,14 @@ def save(request) Puppet::FileSystem.replace_file(filename, 0o660) { |f| f.print to_json(request.instance).force_encoding(Encoding::BINARY) } rescue TypeError => detail - Puppet.log_exception(detail, _("Could not save %{json} %{request}: %{detail}") % { json: self.name, request: request.key, detail: detail }) + Puppet.log_exception(detail, _("Could not save %{json} %{request}: %{detail}") % { json: name, request: request.key, detail: detail }) end def destroy(request) Puppet::FileSystem.unlink(path(request.key)) rescue => detail unless detail.is_a? Errno::ENOENT - raise Puppet::Error, _("Could not destroy %{json} %{request}: %{detail}") % { json: self.name, request: request.key, detail: detail }, detail.backtrace + raise Puppet::Error, _("Could not destroy %{json} %{request}: %{detail}") % { json: name, request: request.key, detail: detail }, detail.backtrace end 1 # emulate success... @@ -66,7 +66,7 @@ def load_json_from_file(file, key) end begin - return from_json(json) + from_json(json) rescue => detail raise Puppet::Error, _("Could not parse JSON data for %{name} %{key}: %{detail}") % { name: indirection.name, key: key, detail: detail }, detail.backtrace end diff --git a/lib/puppet/indirector/msgpack.rb b/lib/puppet/indirector/msgpack.rb index 34c20348947..8ba5a8f2272 100644 --- a/lib/puppet/indirector/msgpack.rb +++ b/lib/puppet/indirector/msgpack.rb @@ -26,14 +26,14 @@ def save(request) Puppet::FileSystem.replace_file(filename, 0o660) { |f| f.print to_msgpack(request.instance) } rescue TypeError => detail - Puppet.log_exception(detail, _("Could not save %{name} %{request}: %{detail}") % { name: self.name, request: request.key, detail: detail }) + Puppet.log_exception(detail, _("Could not save %{name} %{request}: %{detail}") % { name: name, request: request.key, detail: detail }) end def destroy(request) Puppet::FileSystem.unlink(path(request.key)) rescue => detail unless detail.is_a? Errno::ENOENT - raise Puppet::Error, _("Could not destroy %{name} %{request}: %{detail}") % { name: self.name, request: request.key, detail: detail }, detail.backtrace + raise Puppet::Error, _("Could not destroy %{name} %{request}: %{detail}") % { name: name, request: request.key, detail: detail }, detail.backtrace end 1 # emulate success... @@ -71,7 +71,7 @@ def load_msgpack_from_file(file, key) end begin - return from_msgpack(msgpack) + from_msgpack(msgpack) rescue => detail raise Puppet::Error, _("Could not parse MessagePack data for %{indirection} %{key}: %{detail}") % { indirection: indirection.name, key: key, detail: detail }, detail.backtrace end diff --git a/lib/puppet/indirector/none.rb b/lib/puppet/indirector/none.rb index 3e51a26617c..0fd9f67906e 100644 --- a/lib/puppet/indirector/none.rb +++ b/lib/puppet/indirector/none.rb @@ -5,6 +5,6 @@ # A none terminus type, meant to always return nil class Puppet::Indirector::None < Puppet::Indirector::Terminus def find(request) - return nil + nil end end diff --git a/lib/puppet/indirector/report/json.rb b/lib/puppet/indirector/report/json.rb index c845752c77c..0aa7e5cb8cf 100644 --- a/lib/puppet/indirector/report/json.rb +++ b/lib/puppet/indirector/report/json.rb @@ -30,7 +30,7 @@ def save(request) fh.print JSON.dump(request.instance) end rescue TypeError => detail - Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: self.name, request: request.key, detail: detail } + Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: name, request: request.key, detail: detail } end end end diff --git a/lib/puppet/indirector/report/yaml.rb b/lib/puppet/indirector/report/yaml.rb index 3e5d9f7a4f4..340acb5ed87 100644 --- a/lib/puppet/indirector/report/yaml.rb +++ b/lib/puppet/indirector/report/yaml.rb @@ -30,7 +30,7 @@ def save(request) fh.print YAML.dump(request.instance) end rescue TypeError => detail - Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: self.name, request: request.key, detail: detail } + Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: name, request: request.key, detail: detail } end end end diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb index 121afcf5b13..f436450ca92 100644 --- a/lib/puppet/indirector/request.rb +++ b/lib/puppet/indirector/request.rb @@ -140,11 +140,11 @@ def to_hash end def description - return(uri || "/#{indirection_name}/#{key}") + uri || "/#{indirection_name}/#{key}" end def remote? - self.node or self.ip + node or ip end private diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb index ae3ca8fc736..85b900f7e36 100644 --- a/lib/puppet/indirector/yaml.rb +++ b/lib/puppet/indirector/yaml.rb @@ -11,7 +11,7 @@ def find(request) return nil unless Puppet::FileSystem.exist?(file) begin - return load_file(file) + load_file(file) rescue Puppet::Util::Yaml::YamlLoadError => detail raise Puppet::Error, _("Could not parse YAML data for %{indirection} %{request}: %{detail}") % { indirection: indirection.name, request: request.key, detail: detail }, detail.backtrace end @@ -31,7 +31,7 @@ def save(request) begin Puppet::Util::Yaml.dump(request.instance, file) rescue TypeError => detail - Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: self.name, request: request.key, detail: detail } + Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: name, request: request.key, detail: detail } end end diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb index 03f21c77137..0e26070de87 100644 --- a/lib/puppet/interface.rb +++ b/lib/puppet/interface.rb @@ -58,7 +58,7 @@ def register(instance) def define(name, version, &block) face = Puppet::Interface::FaceCollection[name, version] if face.nil? then - face = self.new(name, version) + face = new(name, version) Puppet::Interface::FaceCollection.register(face) # REVISIT: Shouldn't this be delayed until *after* we evaluate the # current block, not done before? --daniel 2011-04-07 @@ -67,7 +67,7 @@ def define(name, version, &block) face.instance_eval(&block) if block_given? - return face + face end # Retrieves a face by name and version. Use `:current` for the @@ -126,7 +126,7 @@ def find_action(name, action, version = :current) # @return [String] usage synopsis # @api private def synopsis - build_synopsis self.name, '' + build_synopsis name, '' end ######################################################################## @@ -219,7 +219,7 @@ def __invoke_decorations(type, action, passed_args = [], passed_options = {}) # Exceptions here should propagate up; this implements a hook we can use # reasonably for option validation. methods.each do |hook| - respond_to? hook and self.__send__(hook, action, passed_args, passed_options) + respond_to? hook and __send__(hook, action, passed_args, passed_options) end end diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb index e82a4c54176..c08090cc1eb 100644 --- a/lib/puppet/interface/action.rb +++ b/lib/puppet/interface/action.rb @@ -40,9 +40,9 @@ def initialize(face, name) # @return [void] # @api private def __dup_and_rebind_to(to) - bound_version = self.dup + bound_version = dup bound_version.instance_variable_set(:@face, to) - return bound_version + bound_version end def to_s() "#{@face}##{@name}" end @@ -88,7 +88,7 @@ def when_rendering(type) return @when_rendering[alt].bind(@face) if @when_rendering.has_key? alt # Guess not, nothing to run. - return nil + nil end # @api private @@ -394,7 +394,7 @@ def validate_and_clean(original) end # All done. - return result + result end ######################################################################## diff --git a/lib/puppet/interface/action_manager.rb b/lib/puppet/interface/action_manager.rb index f6fab05aeb5..13c1e13ec41 100644 --- a/lib/puppet/interface/action_manager.rb +++ b/lib/puppet/interface/action_manager.rb @@ -39,7 +39,7 @@ def actions @actions ||= {} result = @actions.keys - if self.is_a?(Class) and superclass.respond_to?(:actions) + if is_a?(Class) and superclass.respond_to?(:actions) result += superclass.actions elsif self.class.respond_to?(:actions) result += self.class.actions @@ -58,7 +58,7 @@ def get_action(name) @actions ||= {} result = @actions[name.to_sym] if result.nil? - if self.is_a?(Class) and superclass.respond_to?(:get_action) + if is_a?(Class) and superclass.respond_to?(:get_action) found = superclass.get_action(name) elsif self.class.respond_to?(:get_action) found = self.class.get_action(name) @@ -71,7 +71,7 @@ def get_action(name) result = @actions[name.to_sym] = found.__dup_and_rebind_to(self) end end - return result + result end # Retrieves the default action for the face diff --git a/lib/puppet/interface/documentation.rb b/lib/puppet/interface/documentation.rb index 8222af04bef..982dbd41a5b 100644 --- a/lib/puppet/interface/documentation.rb +++ b/lib/puppet/interface/documentation.rb @@ -258,8 +258,8 @@ def copyright(owner = nil, years = nil) self.copyright_owner = owner unless owner.nil? self.copyright_years = years unless years.nil? - if self.copyright_years or self.copyright_owner then - "Copyright #{self.copyright_years} by #{self.copyright_owner}" + if copyright_years or copyright_owner then + "Copyright #{copyright_years} by #{copyright_owner}" else "Unknown copyright owner and years." end diff --git a/lib/puppet/interface/face_collection.rb b/lib/puppet/interface/face_collection.rb index 3bf86cb7e9f..d131eb8ba23 100644 --- a/lib/puppet/interface/face_collection.rb +++ b/lib/puppet/interface/face_collection.rb @@ -40,7 +40,7 @@ def self.get_action_for_face(name, action_name, version) end end - return action + action end # get face from memory, without loading. @@ -51,7 +51,7 @@ def self.get_face(name, pattern) versions = @faces[name].keys - [:current] range = pattern.is_a?(SemanticPuppet::Version) ? SemanticPuppet::VersionRange.new(pattern, pattern) : SemanticPuppet::VersionRange.parse(pattern) found = find_matching(range, versions) - return @faces[name][found] + @faces[name][found] end def self.find_matching(range, versions) @@ -105,7 +105,7 @@ def self.load_face(name, version) safely_require name, version end - return get_face(name, version) + get_face(name, version) end def self.safely_require(name, version = nil) diff --git a/lib/puppet/interface/option_manager.rb b/lib/puppet/interface/option_manager.rb index 75ee85e2d2c..d1b22be2524 100644 --- a/lib/puppet/interface/option_manager.rb +++ b/lib/puppet/interface/option_manager.rb @@ -29,12 +29,12 @@ def all_display_global_options # @api private def walk_inheritance_tree(start, sym) result = start || [] - if self.is_a?(Class) and superclass.respond_to?(sym) + if is_a?(Class) and superclass.respond_to?(sym) result = superclass.send(sym) + result elsif self.class.respond_to?(sym) result = self.class.send(sym) + result end - return result + result end # Declare that this app can take a specific option, and provide the @@ -77,7 +77,7 @@ def add_option(option) @options_hash[name] = option end - return option + option end # @api private @@ -91,14 +91,14 @@ def get_option(name, with_inherited_options = true) result = @options_hash[name.to_sym] if result.nil? and with_inherited_options then - if self.is_a?(Class) and superclass.respond_to?(:get_option) + if is_a?(Class) and superclass.respond_to?(:get_option) result = superclass.get_option(name) elsif self.class.respond_to?(:get_option) result = self.class.get_option(name) end end - return result + result end # @api private diff --git a/lib/puppet/metatype/manager.rb b/lib/puppet/metatype/manager.rb index b9e65867144..d5e5d5c88ff 100644 --- a/lib/puppet/metatype/manager.rb +++ b/lib/puppet/metatype/manager.rb @@ -88,7 +88,7 @@ def newtype(name, options = {}, &block) selfobj = singleton_class if @types.include?(name) - if self.respond_to?(newmethod) + if respond_to?(newmethod) # Remove the old newmethod selfobj.send(:remove_method, newmethod) end @@ -106,7 +106,7 @@ def newtype(name, options = {}, &block) ) # Now define a "new" method for convenience. - if self.respond_to? newmethod + if respond_to? newmethod # Refuse to overwrite existing methods like 'newparam' or 'newtype'. # TRANSLATORS 'new%{method}' will become a method name, do not translate this string Puppet.warning(_("'new%{method}' method already exists; skipping") % { method: name.to_s }) diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb index ed71cddc335..0f6e600caa6 100644 --- a/lib/puppet/module.rb +++ b/lib/puppet/module.rb @@ -46,21 +46,21 @@ def self.is_module_directory?(name, path) fullpath = File.join(path, name) return false unless Puppet::FileSystem.directory?(fullpath) - return is_module_directory_name?(name) + is_module_directory_name?(name) end def self.is_module_directory_name?(name) # it must match an installed module name according to forge validator return true if name =~ /^[a-z][a-z0-9_]*$/ - return false + false end def self.is_module_namespaced_name?(name) # it must match the full module name according to forge validator return true if name =~ /^[a-zA-Z0-9]+-[a-z][a-z0-9_]*$/ - return false + false end # @api private @@ -96,7 +96,7 @@ def puppetversion=(something) # @deprecated The puppetversion module metadata field is no longer used. def validate_puppet_version - return + nil end def has_metadata? @@ -116,7 +116,7 @@ def has_metadata? return false end - return true + true end # A method for returning a given file of a given type. @@ -135,7 +135,7 @@ def has_metadata? return nil unless Puppet::FileSystem.exist?(full_path) - return full_path + full_path end # Return the base directory for the given type @@ -171,9 +171,9 @@ def task_file(name) end if Puppet::FileSystem.exist?(full_path) - return full_path + full_path else - return nil + nil end end @@ -204,9 +204,9 @@ def plan_file(name) end if Puppet::FileSystem.exist?(full_path) - return full_path + full_path else - return nil + nil end end @@ -250,11 +250,11 @@ def load_metadata [:source, :author, :version, :license, :dependencies].each do |attr| value = data[attr.to_s] - raise MissingMetadata, "No #{attr} module metadata provided for #{self.name}" if value.nil? + raise MissingMetadata, "No #{attr} module metadata provided for #{name}" if value.nil? if attr == :dependencies unless value.is_a?(Array) - raise MissingMetadata, "The value for the key dependencies in the file metadata.json of the module #{self.name} must be an array, not: '#{value}'" + raise MissingMetadata, "The value for the key dependencies in the file metadata.json of the module #{name} must be an array, not: '#{value}'" end value.each do |dep| @@ -336,7 +336,7 @@ def locale_directory # @return true if the module has a directory for the locale, false # false otherwise def has_translations?(locale) - return Puppet::FileSystem.exist?(File.join(locale_directory, locale)) + Puppet::FileSystem.exist?(File.join(locale_directory, locale)) end def has_external_facts? @@ -366,7 +366,7 @@ def dependencies_as_modules end def required_by - environment.module_requirements[self.forge_name] || {} + environment.module_requirements[forge_name] || {} end # Identify and mark unmet dependencies. A dependency will be marked unmet @@ -413,8 +413,8 @@ def unmet_dependencies :name => name, :version_constraint => version_string.gsub(/^(?=\d)/, "v"), :parent => { - :name => self.forge_name, - :version => self.version.gsub(/^(?=\d)/, "v") + :name => forge_name, + :version => version.gsub(/^(?=\d)/, "v") }, :mod_details => { :installed_version => dep_mod.nil? ? nil : dep_mod.version @@ -449,10 +449,10 @@ def unmet_dependencies end def ==(other) - self.name == other.name && - self.version == other.version && - self.path == other.path && - self.environment == other.environment + name == other.name && + version == other.version && + path == other.path && + environment == other.environment end private diff --git a/lib/puppet/module/plan.rb b/lib/puppet/module/plan.rb index ec8cf7ace28..c1a04eb6e04 100644 --- a/lib/puppet/module/plan.rb +++ b/lib/puppet/module/plan.rb @@ -59,7 +59,7 @@ def initialize(plan_name, module_name) def self.is_plan_name?(name) return true if name =~ /^[a-z][a-z0-9_]*$/ - return false + false end # Determine whether a plan file has a legal name and extension @@ -77,7 +77,7 @@ def self.is_plans_filename?(path) return [false, _("Plan name cannot be a Puppet data type, but was '%{name}'") % { name: name }] end - return [true] + [true] end # Executables list should contain the full path of all possible implementation files @@ -143,7 +143,7 @@ def validate end def ==(other) - self.name == other.name && + name == other.name && self.module == other.module end @@ -159,7 +159,7 @@ def self.new_with_files(pup_module, name, plan_files) # Abstracted here so we can add support for subdirectories later def self.plan_name_from_path(path) - return File.basename(path, '.*') + File.basename(path, '.*') end private_class_method :plan_name_from_path end diff --git a/lib/puppet/module/task.rb b/lib/puppet/module/task.rb index acc987c3e40..bc0d04d4fdc 100644 --- a/lib/puppet/module/task.rb +++ b/lib/puppet/module/task.rb @@ -55,7 +55,7 @@ def initialize(task_name, module_name) def self.is_task_name?(name) return true if name =~ /^[a-z][a-z0-9_]*$/ - return false + false end def self.is_tasks_file?(path) @@ -70,7 +70,7 @@ def self.is_tasks_filename?(path) FORBIDDEN_EXTENSIONS.each do |ext| return false if path.end_with?(ext) end - return true + true end def self.get_file_details(path, mod) @@ -264,7 +264,7 @@ def validate end def ==(other) - self.name == other.name && + name == other.name && self.module == other.module end @@ -281,7 +281,7 @@ def self.new_with_files(pup_module, name, task_files, module_executables) # Abstracted here so we can add support for subdirectories later def self.task_name_from_path(path) - return File.basename(path, '.*') + File.basename(path, '.*') end private_class_method :task_name_from_path end diff --git a/lib/puppet/module_tool.rb b/lib/puppet/module_tool.rb index 1d52cb3e5bf..ea1a0f204ad 100644 --- a/lib/puppet/module_tool.rb +++ b/lib/puppet/module_tool.rb @@ -35,7 +35,7 @@ def self.artifact?(path) def self.username_and_modname_from(full_module_name) matcher = full_module_name.match(FULL_MODULE_NAME_PATTERN) if matcher - return matcher.captures + matcher.captures else raise ArgumentError, _("Not a valid full name: %{full_module_name}") % { full_module_name: full_module_name } end @@ -87,7 +87,7 @@ def self.format_tree(nodes, level = 0) str << branch end - return str + str end def self.build_tree(mods, dir) diff --git a/lib/puppet/module_tool/applications/application.rb b/lib/puppet/module_tool/applications/application.rb index c04f1ddaff3..8ce2d28995a 100644 --- a/lib/puppet/module_tool/applications/application.rb +++ b/lib/puppet/module_tool/applications/application.rb @@ -64,7 +64,7 @@ def metadata(require_metadata = false) Puppet.warning _("A Modulefile was found in the root directory of the module. This file will be ignored and can safely be removed.") end - return @metadata + @metadata end def load_metadata! @@ -84,7 +84,7 @@ def parse_filename(filename) raise ArgumentError, _("Invalid version format: %{version} (Semantic Versions are acceptable: http://semver.org)") % { version: version } end - return { + { :module_name => module_name, :author => author, :dir_name => shortname, diff --git a/lib/puppet/module_tool/applications/installer.rb b/lib/puppet/module_tool/applications/installer.rb index 1d6d2f9da56..ff37ce2ff7f 100644 --- a/lib/puppet/module_tool/applications/installer.rb +++ b/lib/puppet/module_tool/applications/installer.rb @@ -290,7 +290,7 @@ def build_install_graph(release, installed, graphed = []) previous = installed_modules[release.name] previous = previous.version if previous - return { + { :release => release, :name => release.name, :path => release.install_dir.to_s, @@ -378,7 +378,7 @@ def resolve_install_conflicts(graph, is_dependency = false) :version => release[:version][:vstring] } dependency = is_dependency ? dependency_info : nil - all_versions = @versions["#{@module_name}"].sort_by { |h| h[:semver] } + all_versions = @versions[@module_name.to_s].sort_by { |h| h[:semver] } versions = all_versions.select { |x| x[:semver].special == '' } versions = all_versions if versions.empty? latest_version = versions.last[:vstring] diff --git a/lib/puppet/module_tool/applications/unpacker.rb b/lib/puppet/module_tool/applications/unpacker.rb index 443a87d59e7..49052690127 100644 --- a/lib/puppet/module_tool/applications/unpacker.rb +++ b/lib/puppet/module_tool/applications/unpacker.rb @@ -9,7 +9,7 @@ module Puppet::ModuleTool module Applications class Unpacker < Application def self.unpack(filename, target) - app = self.new(filename, :target_dir => target) + app = new(filename, :target_dir => target) app.unpack app.sanity_check app.move_into(target) @@ -38,7 +38,7 @@ def run # Return the Pathname object representing the directory where the # module release archive was unpacked the to. - return module_dir + module_dir end # @api private diff --git a/lib/puppet/module_tool/applications/upgrader.rb b/lib/puppet/module_tool/applications/upgrader.rb index 90af3094d2b..b4c4ef230dc 100644 --- a/lib/puppet/module_tool/applications/upgrader.rb +++ b/lib/puppet/module_tool/applications/upgrader.rb @@ -271,7 +271,7 @@ def build_install_graph(release, installed, graphed = []) end end - return { + { :release => release, :name => release.name, :path => release.install_dir, diff --git a/lib/puppet/module_tool/checksums.rb b/lib/puppet/module_tool/checksums.rb index a0b8bcfeee3..e447d515c04 100644 --- a/lib/puppet/module_tool/checksums.rb +++ b/lib/puppet/module_tool/checksums.rb @@ -19,7 +19,7 @@ def initialize(path) # Return checksum for the +Pathname+. def checksum(pathname) - return Digest::MD5.hexdigest(Puppet::FileSystem.binread(pathname)) + Digest::MD5.hexdigest(Puppet::FileSystem.binread(pathname)) end # Return checksums for object's +Pathname+, generate if it's needed. @@ -36,7 +36,7 @@ def data end end end - return @data + @data end alias :to_data_hash :data diff --git a/lib/puppet/module_tool/dependency.rb b/lib/puppet/module_tool/dependency.rb index 3db72987b59..9e9d2598413 100644 --- a/lib/puppet/module_tool/dependency.rb +++ b/lib/puppet/module_tool/dependency.rb @@ -23,7 +23,7 @@ def initialize(full_module_name, version_requirement = nil, repository = nil) # We override Object's ==, eql, and hash so we can more easily find identical # dependencies. def ==(o) - self.hash == o.hash + hash == o.hash end alias :eql? :== diff --git a/lib/puppet/module_tool/errors/base.rb b/lib/puppet/module_tool/errors/base.rb index d3f0f0768f5..82971a5a8a5 100644 --- a/lib/puppet/module_tool/errors/base.rb +++ b/lib/puppet/module_tool/errors/base.rb @@ -10,7 +10,7 @@ def vstring if @action == :upgrade "#{v(@installed_version)} -> #{v(@requested_version)}" else - "#{v(@installed_version || @requested_version)}" + v(@installed_version || @requested_version).to_s end end end diff --git a/lib/puppet/module_tool/metadata.rb b/lib/puppet/module_tool/metadata.rb index 6ca5ff45ce4..56eaa32ce38 100644 --- a/lib/puppet/module_tool/metadata.rb +++ b/lib/puppet/module_tool/metadata.rb @@ -58,7 +58,7 @@ def update(data) merge_dependencies(data) if data['dependencies'] @data.merge!(data) - return self + self end # Validates the name and version_requirement for a dependency, then creates @@ -156,7 +156,7 @@ def process_source(data) data['issues_url'] ||= @data['issues_url'] || source_uri.to_s.sub(%r{/*$}, '') + '/issues' end rescue URI::Error - return + nil end # Validates and parses the dependencies. diff --git a/lib/puppet/module_tool/shared_behaviors.rb b/lib/puppet/module_tool/shared_behaviors.rb index 4225676e9b6..cf582c54226 100644 --- a/lib/puppet/module_tool/shared_behaviors.rb +++ b/lib/puppet/module_tool/shared_behaviors.rb @@ -60,14 +60,14 @@ def implicit_version(mod) return :latest end - return :best + :best end def annotated_version(mod, versions) if versions.empty? - return implicit_version(mod) + implicit_version(mod) else - return "#{implicit_version(mod)}: #{versions.last}" + "#{implicit_version(mod)}: #{versions.last}" end end @@ -100,7 +100,7 @@ def resolve_constraints(dependencies, source = [{ :name => :you }], seen = {}, a next if range === seen[mod][:semver] req_module = @module_name - req_versions = @versions["#{@module_name}"].map { |v| v[:semver] } + req_versions = @versions[@module_name.to_s].map { |v| v[:semver] } raise InvalidDependencyCycleError, :module_name => mod, :source => (source + [{ :name => mod, :version => source.last[:dependency] }]), @@ -121,14 +121,14 @@ def resolve_constraints(dependencies, source = [{ :name => :you }], seen = {}, a @conditions.each { |_, conds| conds.delete_if { |c| c[:module] == mod } } end - versions = @versions["#{mod}"].select { |h| range === h[:semver] } + versions = @versions[mod.to_s].select { |h| range === h[:semver] } valid_versions = versions.select { |x| x[:semver].special == '' } valid_versions = versions if valid_versions.empty? version = valid_versions.last unless version req_module = @module_name - req_versions = @versions["#{@module_name}"].map { |v| v[:semver] } + req_versions = @versions[@module_name.to_s].map { |v| v[:semver] } raise NoVersionsSatisfyError, :requested_name => req_module, :requested_version => @version || annotated_version(req_module, req_versions), @@ -158,7 +158,7 @@ def resolve_constraints(dependencies, source = [{ :name => :you }], seen = {}, a deps = @remote["#{mod[:module]}@#{mod[:version][:vstring]}"].sort_by(&:first) mod[:dependencies] = resolve_constraints(deps, source + [{ :name => mod[:module], :version => mod[:version][:vstring] }], seen, :install) end unless @ignore_dependencies - return dependencies + dependencies end def download_tarballs(graph, default_path, forge) diff --git a/lib/puppet/network/client_request.rb b/lib/puppet/network/client_request.rb index f7ef57896c8..443d2bf6fb2 100644 --- a/lib/puppet/network/client_request.rb +++ b/lib/puppet/network/client_request.rb @@ -7,7 +7,7 @@ class ClientRequest attr_accessor :name, :ip, :authenticated, :handler, :method def authenticated? - self.authenticated + authenticated end # A common way of talking about the full call. Individual servers @@ -26,7 +26,7 @@ def initialize(name, ip, authenticated) end def to_s - "#{self.name}(#{self.ip})" + "#{name}(#{ip})" end end end diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb index 6fef4465f47..076eb932b85 100644 --- a/lib/puppet/network/format.rb +++ b/lib/puppet/network/format.rb @@ -14,7 +14,7 @@ def init_attribute(name, default) value = @options.delete(name) value = default if value.nil? - self.send(name.to_s + "=", value) + send(name.to_s + "=", value) end def initialize(name, options = {}, &block) @@ -111,6 +111,6 @@ def required_method_present?(name, klass, type) method = send(name) - return(type == :class ? klass.respond_to?(method) : klass.method_defined?(method)) + (type == :class ? klass.respond_to?(method) : klass.method_defined?(method)) end end diff --git a/lib/puppet/network/format_support.rb b/lib/puppet/network/format_support.rb index 1a6f15431f3..b59bbe7f808 100644 --- a/lib/puppet/network/format_support.rb +++ b/lib/puppet/network/format_support.rb @@ -68,7 +68,7 @@ def format_handler end def friendly_name - if self.respond_to? :indirection + if respond_to? :indirection indirection.name else self diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb index fc67e7d27d7..f3960256d0e 100644 --- a/lib/puppet/network/formats.rb +++ b/lib/puppet/network/formats.rb @@ -222,7 +222,7 @@ def flatten_array(array) a["#{i}.#{el_k}"] = el_v end else - a["#{i}"] = el + a[i.to_s] = el end end a diff --git a/lib/puppet/network/http/api/indirected_routes.rb b/lib/puppet/network/http/api/indirected_routes.rb index 36f95c1b892..3d0055ffb57 100644 --- a/lib/puppet/network/http/api/indirected_routes.rb +++ b/lib/puppet/network/http/api/indirected_routes.rb @@ -248,7 +248,7 @@ def indirection_method(http_method, indirection) end def self.pluralize(indirection) - return(indirection == "status" ? "statuses" : indirection + "s") + (indirection == "status" ? "statuses" : indirection + "s") end private_class_method :pluralize diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index 6ea626dd0a2..b90c62b2e62 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -107,14 +107,10 @@ def respond_with_http_error(response, exception) def find_route_or_raise(request) route = @routes.find { |r| r.matches?(request) } - if route - return route - else - raise Puppet::Network::HTTP::Error::HTTPNotFoundError.new( - _("No route for %{request} %{path}") % { request: request.method, path: request.path }, - HANDLER_NOT_FOUND - ) - end + route || raise(Puppet::Network::HTTP::Error::HTTPNotFoundError.new( + _("No route for %{request} %{path}") % { request: request.method, path: request.path }, + HANDLER_NOT_FOUND + )) end def set_puppet_version_header(response) diff --git a/lib/puppet/network/http/route.rb b/lib/puppet/network/http/route.rb index 47254f8faf5..aa9f8c57716 100644 --- a/lib/puppet/network/http/route.rb +++ b/lib/puppet/network/http/route.rb @@ -28,39 +28,39 @@ def initialize(path_matcher) def get(*handlers) @method_handlers[:GET] = handlers - return self + self end def head(*handlers) @method_handlers[:HEAD] = handlers - return self + self end def options(*handlers) @method_handlers[:OPTIONS] = handlers - return self + self end def post(*handlers) @method_handlers[:POST] = handlers - return self + self end def put(*handlers) @method_handlers[:PUT] = handlers - return self + self end def delete(*handlers) @method_handlers[:DELETE] = handlers - return self + self end def any(*handlers) @method_handlers.each do |method, _registered_handlers| @method_handlers[method] = handlers end - return self + self end def chain(*routes) @@ -69,14 +69,14 @@ def chain(*routes) end def matches?(request) - Puppet.debug { "Evaluating match for #{self.inspect}" } + Puppet.debug { "Evaluating match for #{inspect}" } if match(request.routing_path) return true else Puppet.debug { "Did not match path (#{request.routing_path.inspect})" } end - return false + false end def process(request, response) diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index c38c74d739d..b604b449db3 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -48,7 +48,7 @@ def to_data_hash 'environment' => environment.name.to_s, } result['classes'] = classes unless classes.empty? - serialized_params = self.serializable_parameters + serialized_params = serializable_parameters result['parameters'] = serialized_params unless serialized_params.empty? result end @@ -174,7 +174,7 @@ def add_extra_facts(extra_facts) def add_server_facts(facts) # Append the current environment to the list of server facts - @server_facts = facts.merge({ "environment" => self.environment.name.to_s }) + @server_facts = facts.merge({ "environment" => environment.name.to_s }) # Merge the server facts into the parameters for the node merge(facts) diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb index 976c5a5d8aa..54a3bc5fd7a 100644 --- a/lib/puppet/node/environment.rb +++ b/lib/puppet/node/environment.rb @@ -87,10 +87,10 @@ def initialize(name, modulepath, manifest, config_version) # parameters (:modulepath, :manifest, :config_version) # @return [Puppet::Node::Environment] def override_with(env_params) - return self.class.create(name, - env_params[:modulepath] || modulepath, - env_params[:manifest] || manifest, - env_params[:config_version] || config_version) + self.class.create(name, + env_params[:modulepath] || modulepath, + env_params[:manifest] || manifest, + env_params[:config_version] || config_version) end # Creates a new Puppet::Node::Environment instance, overriding :manifest, @@ -118,7 +118,7 @@ def override_from_commandline(settings) overrides.empty? ? self : - self.override_with(overrides) + override_with(overrides) end # @param [String] name Environment name to check for valid syntax. @@ -279,7 +279,7 @@ def rich_data? # @param param [String, Symbol] The environment setting to look up # @return [Object] The resolved setting value def [](param) - Puppet.settings.value(param, self.name) + Puppet.settings.value(param, name) end # @api public @@ -518,7 +518,7 @@ def to_s # @api public def inspect - %Q(<#{self.class}:#{self.object_id} @name="#{name}" @manifest="#{manifest}" @modulepath="#{full_modulepath.join(":")}" >) + %Q(<#{self.class}:#{object_id} @name="#{name}" @manifest="#{manifest}" @modulepath="#{full_modulepath.join(":")}" >) end # @return [Symbol] The `name` value, cast to a string, then cast to a symbol. @@ -537,10 +537,10 @@ def self.split_path(path_string) end def ==(other) - return true if other.is_a?(Puppet::Node::Environment) && - self.name == other.name && - self.full_modulepath == other.full_modulepath && - self.manifest == other.manifest + true if other.is_a?(Puppet::Node::Environment) && + name == other.name && + full_modulepath == other.full_modulepath && + manifest == other.manifest end alias eql? == @@ -587,7 +587,7 @@ def perform_initial_import parser.string = @parsed_code parser.parse else - file = self.manifest + file = manifest # if the manifest file is a reference to a directory, parse and combine # all .pp files in that directory if file == NO_MANIFEST @@ -608,7 +608,7 @@ def perform_initial_import end rescue Puppet::ParseErrorWithIssue => detail @known_resource_types.parse_failed = true - detail.environment = self.name + detail.environment = name raise rescue => detail @known_resource_types.parse_failed = true @@ -623,7 +623,7 @@ def perform_initial_import # # @return [Puppet::Parser::AST::Hostclass] def empty_parse_result - return Puppet::Parser::AST::Hostclass.new('') + Puppet::Parser::AST::Hostclass.new('') end # A None subclass to make it easier to trace the NONE environment when debugging. diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index fc0b572b90d..957df9bffa7 100644 --- a/lib/puppet/node/facts.rb +++ b/lib/puppet/node/facts.rb @@ -78,7 +78,7 @@ def sanitize end def ==(other) - return false unless self.name == other.name + return false unless name == other.name values == other.values end diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb index 6a73868c81e..9f4db03ec40 100644 --- a/lib/puppet/parameter.rb +++ b/lib/puppet/parameter.rb @@ -119,7 +119,7 @@ def doc @doc << "\n\n#{vals}" end - features = self.required_features + features = required_features if features @doc << "\n\nRequires features #{features.flatten.collect { |f| f.to_s }.join(" ")}." end @@ -385,7 +385,7 @@ def name # def noop @noop ||= false - @noop || self.resource.noop || Puppet[:noop] || false + @noop || resource.noop || Puppet[:noop] || false end # Returns an array of strings representing the containment hierarchy @@ -395,9 +395,9 @@ def noop # @api private def pathbuilder if @resource - return [@resource.pathbuilder, self.name] + [@resource.pathbuilder, name] else - return [self.name] + [name] end end @@ -446,7 +446,7 @@ def munge(value) Puppet.debug { "Reraising #{detail}" } raise rescue => detail - raise Puppet::DevError, _("Munging failed for value %{value} in class %{class_name}: %{detail}") % { value: value.inspect, class_name: self.name, detail: detail }, detail.backtrace + raise Puppet::DevError, _("Munging failed for value %{value} in class %{class_name}: %{detail}") % { value: value.inspect, class_name: name, detail: detail }, detail.backtrace end ret end @@ -482,7 +482,7 @@ def validate(value) rescue Puppet::Error, TypeError raise rescue => detail - raise Puppet::DevError, _("Validate method failed for class %{class_name}: %{detail}") % { class_name: self.name, detail: detail }, detail.backtrace + raise Puppet::DevError, _("Validate method failed for class %{class_name}: %{detail}") % { class_name: name, detail: detail }, detail.backtrace end end @@ -539,7 +539,7 @@ def tags @tags = [] # This might not be true in testing @tags = @resource.tags if @resource.respond_to? :tags - @tags << self.name.to_s + @tags << name.to_s end @tags end diff --git a/lib/puppet/parameter/value.rb b/lib/puppet/parameter/value.rb index c217d147db5..6ded772d7b8 100644 --- a/lib/puppet/parameter/value.rb +++ b/lib/puppet/parameter/value.rb @@ -57,9 +57,9 @@ def initialize(name) # def match?(value) if regex? - return true if name =~ value.to_s + true if name =~ value.to_s else - return(name == convert(value) ? true : @aliases.include?(convert(value))) + (name == convert(value) ? true : @aliases.include?(convert(value))) end end diff --git a/lib/puppet/parameter/value_collection.rb b/lib/puppet/parameter/value_collection.rb index cf27c80818b..8e25e3921f5 100644 --- a/lib/puppet/parameter/value_collection.rb +++ b/lib/puppet/parameter/value_collection.rb @@ -103,12 +103,12 @@ def munge(value) instance = match?(value) if instance if instance.regex? - return value + value else - return instance.name + instance.name end else - return value + value end end diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb index a389f13fdf7..be82a5339c9 100644 --- a/lib/puppet/parser/ast.rb +++ b/lib/puppet/parser/ast.rb @@ -29,7 +29,7 @@ def safeevaluate(scope) # We duplicate code here, rather than using exceptwrap, because this # is called so many times during parsing. - return self.evaluate(scope) + evaluate(scope) rescue Puppet::Pops::Evaluator::PuppetStopIteration => detail raise detail # # Only deals with StopIteration from the break() function as a general diff --git a/lib/puppet/parser/ast/block_expression.rb b/lib/puppet/parser/ast/block_expression.rb index f03aff242a2..8e7dc391bd8 100644 --- a/lib/puppet/parser/ast/block_expression.rb +++ b/lib/puppet/parser/ast/block_expression.rb @@ -8,7 +8,7 @@ def evaluate(scope) end def sequence_with(other) - Puppet::Parser::AST::BlockExpression.new(:children => self.children + other.children) + Puppet::Parser::AST::BlockExpression.new(:children => children + other.children) end def to_s diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb index 6119a01a258..6384829efad 100644 --- a/lib/puppet/parser/ast/hostclass.rb +++ b/lib/puppet/parser/ast/hostclass.rb @@ -20,7 +20,7 @@ def instantiate(modname) end end end - return all_types + all_types end def code diff --git a/lib/puppet/parser/ast/pops_bridge.rb b/lib/puppet/parser/ast/pops_bridge.rb index 3217afd002e..87ceab951e7 100644 --- a/lib/puppet/parser/ast/pops_bridge.rb +++ b/lib/puppet/parser/ast/pops_bridge.rb @@ -59,7 +59,7 @@ def children class ExpressionSupportingReturn < Expression def evaluate(scope) - return catch(:return) do + catch(:return) do return catch(:next) do return super(scope) end diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb index bf22f064817..234ad083be2 100644 --- a/lib/puppet/parser/ast/resource.rb +++ b/lib/puppet/parser/ast/resource.rb @@ -20,7 +20,7 @@ def evaluate(scope) # because sometimes the :virtual attribute is set *after* # :exported, in which case it clobbers :exported if :exported # is true. Argh, this was a very tough one to track down. - virt = self.virtual || self.exported + virt = virtual || exported # First level of implicit iteration: build a resource for each # instance. This handles things like: @@ -44,9 +44,9 @@ def evaluate(scope) resource = Puppet::Parser::Resource.new( fully_qualified_type, resource_title, :parameters => paramobjects, - :file => self.file, - :line => self.line, - :exported => self.exported, + :file => file, + :line => line, + :exported => exported, :virtual => virt, :source => scope.source, :scope => scope, diff --git a/lib/puppet/parser/ast/resourceparam.rb b/lib/puppet/parser/ast/resourceparam.rb index b1424daa4fd..868f4c35e5c 100644 --- a/lib/puppet/parser/ast/resourceparam.rb +++ b/lib/puppet/parser/ast/resourceparam.rb @@ -17,13 +17,13 @@ def each # Return the parameter and the value. def evaluate(scope) value = @value.safeevaluate(scope) - return Puppet::Parser::Resource::Param.new( + Puppet::Parser::Resource::Param.new( :name => @param, :value => value.nil? ? :undef : value, :source => scope.source, - :line => self.line, - :file => self.file, - :add => self.add + :line => line, + :file => file, + :add => add ) end diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index d5b0e265262..c22a1e710f4 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -215,7 +215,7 @@ def self.newfunction(name, options = {}, &block) raise ArgumentError, _("%{name}(): Wrong number of arguments given (%{arg_count} for minimum %{min_arg_count})") % { name: name, arg_count: args[0].size, min_arg_count: (arity + 1).abs } end - r = Puppet::Pops::Evaluator::Runtime3FunctionArgumentConverter.convert_return(self.send(real_fname, args[0])) + r = Puppet::Pops::Evaluator::Runtime3FunctionArgumentConverter.convert_return(send(real_fname, args[0])) # avoid leaking aribtrary value if not being an rvalue function options[:type] == :rvalue ? r : nil else diff --git a/lib/puppet/parser/functions/create_resources.rb b/lib/puppet/parser/functions/create_resources.rb index 9e0f1e03d4b..532e3a0cbac 100644 --- a/lib/puppet/parser/functions/create_resources.rb +++ b/lib/puppet/parser/functions/create_resources.rb @@ -105,7 +105,7 @@ Puppet::Parser::Resource::Param.new( :name => name, :value => value, # wide open to various data types, must be correct - :source => self.source, # TODO: support :line => line, :file => file, + :source => source, # TODO: support :line => line, :file => file, :add => false ) end diff --git a/lib/puppet/parser/functions/tag.rb b/lib/puppet/parser/functions/tag.rb index c4ae0ce3613..f65bf3a0609 100644 --- a/lib/puppet/parser/functions/tag.rb +++ b/lib/puppet/parser/functions/tag.rb @@ -11,5 +11,5 @@ ) end - self.resource.tag(*vals) + resource.tag(*vals) end diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index fd851456085..b623f3b7bf8 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -33,7 +33,7 @@ def evaluated?; !!@evaluated; end def [](param) param = param.intern if param == :title - return self.title + return title end if @parameters.has_key?(param) @@ -57,7 +57,7 @@ def environment # is drawn from the class to the stage. The stage for containment # defaults to main, if none is specified. def add_edge_to_stage - return unless self.class? + return unless class? stage = catalog.resource(:stage, self[:stage] || (scope && scope.resource && scope.resource[:stage]) || :main) unless stage @@ -138,7 +138,7 @@ def initialize(type, title, attributes, with_defaults = true) scope.lookupdefaults(self.type).each_pair do |name, param| next if @parameters.include?(name) - self.debug "Adding default for #{name}" + debug "Adding default for #{name}" param = param.dup @parameters[name] = param @@ -150,9 +150,9 @@ def initialize(type, title, attributes, with_defaults = true) # Is this resource modeling an isomorphic resource type? def isomorphic? if builtin_type? - return resource_type.isomorphic? + resource_type.isomorphic? else - return true + true end end @@ -161,7 +161,7 @@ def isomorphic? def merge(resource) # Test the resource scope, to make sure the resource is even allowed # to override. - unless self.source.equal?(resource.source) || resource.source.child_of?(self.source) + unless source.equal?(resource.source) || resource.source.child_of?(source) raise Puppet::ParseError.new(_("Only subclasses can override parameters"), resource.file, resource.line) end @@ -190,7 +190,7 @@ def merge(resource) end def name - self[:name] || self.title + self[:name] || title end # A temporary occasion, until I get paths in the scopes figured out. @@ -203,7 +203,7 @@ def set_parameter(param, value = nil) unless param.is_a?(Puppet::Parser::Resource::Param) param = param.name if param.is_a?(Puppet::Pops::Resource::Param) param = Puppet::Parser::Resource::Param.new( - :name => param, :value => value, :source => self.source + :name => param, :value => value, :source => source ) end diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb index 857d8efa526..cb4032219bd 100644 --- a/lib/puppet/parser/resource/param.rb +++ b/lib/puppet/parser/resource/param.rb @@ -26,12 +26,12 @@ def line_to_i end def to_s - "#{self.name} => #{self.value}" + "#{name} => #{value}" end def self.from_param(param, value) new_param = param.dup new_param.value = value - return new_param + new_param end end diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index ca7386e4f54..4d3436d264b 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -625,7 +625,7 @@ def lookup_qualified_variable(fqn, options) end end # report with leading '::' by using empty class_name - return handle_not_found('', fqn, options) + handle_not_found('', fqn, options) end # @api private diff --git a/lib/puppet/parser/script_compiler.rb b/lib/puppet/parser/script_compiler.rb index 7d82531ae6c..53f57b7edd7 100644 --- a/lib/puppet/parser/script_compiler.rb +++ b/lib/puppet/parser/script_compiler.rb @@ -118,6 +118,6 @@ def newscope(parent, options = {}) def evaluate_main @loaders.pre_load program = @loaders.load_main_manifest - return program.nil? ? nil : Puppet::Pops::Parser::EvaluatingParser.singleton.evaluator.evaluate(program, @topscope) + program.nil? ? nil : Puppet::Pops::Parser::EvaluatingParser.singleton.evaluator.evaluate(program, @topscope) end end diff --git a/lib/puppet/parser/type_loader.rb b/lib/puppet/parser/type_loader.rb index 874190bc91f..f4d0ff6b763 100644 --- a/lib/puppet/parser/type_loader.rb +++ b/lib/puppet/parser/type_loader.rb @@ -78,14 +78,14 @@ def try_load_fqname(type, fqname) # preserves existing behaviours. end # Nothing found. - return nil + nil end def parse_file(file) Puppet.debug { "importing '#{file}' in environment #{environment}" } parser = Puppet::Parser::ParserFactory.parser parser.file = file - return parser.parse + parser.parse end private diff --git a/lib/puppet/pops/adaptable.rb b/lib/puppet/pops/adaptable.rb index e5288653c3f..dabb91ee799 100644 --- a/lib/puppet/pops/adaptable.rb +++ b/lib/puppet/pops/adaptable.rb @@ -182,7 +182,7 @@ def self.instance_var_name(name) # Returns the name of the class, or the name of the type if the class represents an Object type # @return [String] the name of the class or type def self.type_name - self.name + name end # Returns a suitable instance variable name for the _name_ of this instance. The name is created by calling diff --git a/lib/puppet/pops/evaluator/access_operator.rb b/lib/puppet/pops/evaluator/access_operator.rb index fd34f448040..eb09455666a 100644 --- a/lib/puppet/pops/evaluator/access_operator.rb +++ b/lib/puppet/pops/evaluator/access_operator.rb @@ -665,7 +665,7 @@ def access_PResourceType(o, scope, keys) Types::PResourceType.new(type_name, t == :no_title ? nil : t) end # returns single type if request was for a single entity, else an array of types (possibly empty) - return result_type_array ? result : result.pop + result_type_array ? result : result.pop end NS = '::' @@ -725,7 +725,7 @@ def access_PClassType(o, scope, keys) end # returns single type as type, else an array of types - return result_type_array ? result : result.pop + result_type_array ? result : result.pop end end end diff --git a/lib/puppet/pops/evaluator/collector_transformer.rb b/lib/puppet/pops/evaluator/collector_transformer.rb index 61dae6df873..cbdf43fa202 100644 --- a/lib/puppet/pops/evaluator/collector_transformer.rb +++ b/lib/puppet/pops/evaluator/collector_transformer.rb @@ -182,19 +182,19 @@ def match_AccessExpression(o, scope) def match_AndExpression(o, scope) left_match = match(o.left_expr, scope) right_match = match(o.right_expr, scope) - return [left_match, 'and', right_match] + [left_match, 'and', right_match] end def match_OrExpression(o, scope) left_match = match(o.left_expr, scope) right_match = match(o.right_expr, scope) - return [left_match, 'or', right_match] + [left_match, 'or', right_match] end def match_ComparisonExpression(o, scope) left_match = match(o.left_expr, scope) right_match = match(o.right_expr, scope) - return [left_match, o.operator.to_s, right_match] + [left_match, o.operator.to_s, right_match] end def match_VariableExpression(o, scope) diff --git a/lib/puppet/pops/evaluator/compare_operator.rb b/lib/puppet/pops/evaluator/compare_operator.rb index c5f0dff3e60..5429581f3bd 100644 --- a/lib/puppet/pops/evaluator/compare_operator.rb +++ b/lib/puppet/pops/evaluator/compare_operator.rb @@ -183,15 +183,15 @@ def include_Array(a, b, scope) end # Always set match data, a "not found" should not keep old match data visible set_match_data(matched, scope) # creates ephemeral - return !!matched + !!matched when String, SemanticPuppet::Version a.any? { |element| match(b, element, scope) } when Types::PAnyType a.each { |element| return true if b.instance?(element) } - return false + false else a.each { |element| return true if equals(element, b) } - return false + false end end diff --git a/lib/puppet/pops/evaluator/evaluator_impl.rb b/lib/puppet/pops/evaluator/evaluator_impl.rb index 2b9baa6e64f..3c8a3562f03 100644 --- a/lib/puppet/pops/evaluator/evaluator_impl.rb +++ b/lib/puppet/pops/evaluator/evaluator_impl.rb @@ -747,7 +747,7 @@ def eval_Program(o, scope) file = o.locator.file line = 0 # Add stack frame for "top scope" logic. See Puppet::Pops::PuppetStack - return Puppet::Pops::PuppetStack.stack(file, line, self, 'evaluate', [o.body, scope]) + Puppet::Pops::PuppetStack.stack(file, line, self, 'evaluate', [o.body, scope]) # evaluate(o.body, scope) rescue Puppet::Pops::Evaluator::PuppetStopIteration => ex # breaking out of a file level program is not allowed diff --git a/lib/puppet/pops/evaluator/runtime3_converter.rb b/lib/puppet/pops/evaluator/runtime3_converter.rb index 745a91cb4a5..6eda49f549c 100644 --- a/lib/puppet/pops/evaluator/runtime3_converter.rb +++ b/lib/puppet/pops/evaluator/runtime3_converter.rb @@ -165,7 +165,7 @@ def initialize(inner = false) @convert_visitor = Puppet::Pops::Visitor.new(self, 'convert', 2, 2) end - @instance = self.new + @instance = new end # A Ruby function written for the 3.x API cannot be expected to handle extended data types. This @@ -220,6 +220,6 @@ def self.convert_return(val3x) end end - @instance = self.new + @instance = new end end diff --git a/lib/puppet/pops/functions/function.rb b/lib/puppet/pops/functions/function.rb index c8cf5a574be..bbf76dac77b 100644 --- a/lib/puppet/pops/functions/function.rb +++ b/lib/puppet/pops/functions/function.rb @@ -43,7 +43,7 @@ def call(scope, *args, &block) result = catch(:return) do return self.class.dispatcher.dispatch(self, scope, args, &block) end - return result.value + result.value rescue Puppet::Pops::Evaluator::Next => jumper begin throw :next, jumper.value diff --git a/lib/puppet/pops/loader/loader.rb b/lib/puppet/pops/loader/loader.rb index acdc94c9219..e28b61f4e8e 100644 --- a/lib/puppet/pops/loader/loader.rb +++ b/lib/puppet/pops/loader/loader.rb @@ -54,7 +54,7 @@ def initialize(loader_name, environment) # @yieldreturn [Boolean] `true` to keep the entry, `false` to discard it. # @return [Array] the list of names of discovered values def discover(type, error_collector = nil, name_authority = Pcore::RUNTIME_NAME_AUTHORITY, &block) - return EMPTY_ARRAY + EMPTY_ARRAY end # Produces the value associated with the given name if already loaded, or available for loading @@ -199,7 +199,7 @@ def to_s # at this point to inspect (ie children would print out `loader_name` # rather than their version of to_s if they chose to implement it). def inspect - self.to_s + to_s end # An entry for one entity loaded by the loader. diff --git a/lib/puppet/pops/loader/module_loaders.rb b/lib/puppet/pops/loader/module_loaders.rb index 1a3dd37bb31..1c635a37985 100644 --- a/lib/puppet/pops/loader/module_loaders.rb +++ b/lib/puppet/pops/loader/module_loaders.rb @@ -82,7 +82,7 @@ def self.pcore_resource_type_loader_from(parent_loader, loaders, environment_pat class EmptyLoader < BaseLoader def find(typed_name) - return nil + nil end def private_loader diff --git a/lib/puppet/pops/loaders.rb b/lib/puppet/pops/loaders.rb index 5699bf41006..f47afb79851 100644 --- a/lib/puppet/pops/loaders.rb +++ b/lib/puppet/pops/loaders.rb @@ -28,7 +28,7 @@ def self.new(environment, for_agent = false, load_from_pcore = true) environment.lock.synchronize do obj = environment.loaders if obj.nil? - obj = self.allocate + obj = allocate obj.send(:initialize, environment, for_agent, load_from_pcore) end obj diff --git a/lib/puppet/pops/lookup/data_dig_function_provider.rb b/lib/puppet/pops/lookup/data_dig_function_provider.rb index 937b273ed16..d2abe6c8e92 100644 --- a/lib/puppet/pops/lookup/data_dig_function_provider.rb +++ b/lib/puppet/pops/lookup/data_dig_function_provider.rb @@ -92,7 +92,7 @@ def instantiate_backend(lookup_invocation) require 'hiera/backend' require "hiera/backend/#{backend_name.downcase}_backend" backend = Hiera::Backend.const_get("#{backend_name.capitalize}_backend").new - return backend.method(:lookup).arity == 4 ? Hiera::Backend::Backend1xWrapper.new(backend) : backend + backend.method(:lookup).arity == 4 ? Hiera::Backend::Backend1xWrapper.new(backend) : backend rescue LoadError => e lookup_invocation.report_text { "Unable to load backend '#{backend_name}': #{e.message}" } throw :no_such_key diff --git a/lib/puppet/pops/lookup/key_recorder.rb b/lib/puppet/pops/lookup/key_recorder.rb index d41fa4df0f4..4149aa85d88 100644 --- a/lib/puppet/pops/lookup/key_recorder.rb +++ b/lib/puppet/pops/lookup/key_recorder.rb @@ -9,7 +9,7 @@ def initialize # rubocop:disable Naming/MemoizedInstanceVariableName def self.singleton - @null_recorder ||= self.new + @null_recorder ||= new end # rubocop:enable Naming/MemoizedInstanceVariableName diff --git a/lib/puppet/pops/lookup/lookup_adapter.rb b/lib/puppet/pops/lookup/lookup_adapter.rb index 972abe472b6..e2766ccf348 100644 --- a/lib/puppet/pops/lookup/lookup_adapter.rb +++ b/lib/puppet/pops/lookup/lookup_adapter.rb @@ -411,7 +411,7 @@ def env_provider(lookup_invocation) def module_provider(lookup_invocation, module_name) # Test if the key is present for the given module_name. It might be there even if the # value is nil (which indicates that no module provider is configured for the given name) - unless self.include?(module_name) + unless include?(module_name) self[module_name] = initialize_module_provider(lookup_invocation, module_name) end self[module_name] diff --git a/lib/puppet/pops/merge_strategy.rb b/lib/puppet/pops/merge_strategy.rb index 1d992e02500..c79d445e051 100644 --- a/lib/puppet/pops/merge_strategy.rb +++ b/lib/puppet/pops/merge_strategy.rb @@ -208,7 +208,7 @@ def assert_type(param, type, value) # Simple strategy that returns the first value found. It never merges any values. # class FirstFoundStrategy < MergeStrategy - INSTANCE = self.new(EMPTY_HASH) + INSTANCE = new(EMPTY_HASH) def self.key :first @@ -238,7 +238,7 @@ def value_t # Same as {FirstFoundStrategy} but used when no strategy has been explicitly given class DefaultMergeStrategy < FirstFoundStrategy - INSTANCE = self.new(EMPTY_HASH) + INSTANCE = new(EMPTY_HASH) def self.key :default @@ -251,7 +251,7 @@ def self.key # will be those of e1 # class HashMergeStrategy < MergeStrategy - INSTANCE = self.new(EMPTY_HASH) + INSTANCE = new(EMPTY_HASH) def self.key :hash @@ -281,7 +281,7 @@ def value_t # first contributor of elements and e2 the second. # class UniqueMergeStrategy < MergeStrategy - INSTANCE = self.new(EMPTY_HASH) + INSTANCE = new(EMPTY_HASH) def self.key :unique @@ -363,7 +363,7 @@ def value_t # Results: {:x => [{:y => 1, :z => 2}]} # class DeepMergeStrategy < MergeStrategy - INSTANCE = self.new(EMPTY_HASH) + INSTANCE = new(EMPTY_HASH) def self.key :deep @@ -432,7 +432,7 @@ def self.options_t # Same as {UnconstrainedDeepMergeStrategy} but with reverse priority of merged elements. # (needed for backward compatibility with Hiera v3) class ReverseDeepMergeStrategy < UnconstrainedDeepMergeStrategy - INSTANCE = self.new(EMPTY_HASH) + INSTANCE = new(EMPTY_HASH) def self.key :reverse_deep diff --git a/lib/puppet/pops/migration/migration_checker.rb b/lib/puppet/pops/migration/migration_checker.rb index 040213189d0..469a8788a18 100644 --- a/lib/puppet/pops/migration/migration_checker.rb +++ b/lib/puppet/pops/migration/migration_checker.rb @@ -9,7 +9,7 @@ def initialize # rubocop:disable Naming/MemoizedInstanceVariableName def self.singleton - @null_checker ||= self.new + @null_checker ||= new end # rubocop:enable Naming/MemoizedInstanceVariableName diff --git a/lib/puppet/pops/model/ast_transformer.rb b/lib/puppet/pops/model/ast_transformer.rb index 9ccb275b877..c79fc10dacc 100644 --- a/lib/puppet/pops/model/ast_transformer.rb +++ b/lib/puppet/pops/model/ast_transformer.rb @@ -91,11 +91,11 @@ def hostname_Array(o) end def hostname_LiteralValue(o) - return o.value + o.value end def hostname_QualifiedName(o) - return o.value + o.value end def hostname_LiteralNumber(o) @@ -103,7 +103,7 @@ def hostname_LiteralNumber(o) end def hostname_LiteralDefault(o) - return 'default' + 'default' end def hostname_LiteralRegularExpression(o) diff --git a/lib/puppet/pops/model/factory.rb b/lib/puppet/pops/model/factory.rb index 081c99bebfb..11032163d4e 100644 --- a/lib/puppet/pops/model/factory.rb +++ b/lib/puppet/pops/model/factory.rb @@ -648,7 +648,7 @@ def self.set_resource_form(expr, form) return false unless expr.instance_of?(self) && expr.model_class <= AbstractResource expr['form'] = form - return true + true end # Returns symbolic information about an expected shape of a resource expression given the LHS of a resource expr. @@ -1061,7 +1061,7 @@ def interpolate_Factory(c) def interpolate_LiteralInteger(c) # convert number to a variable - self.var + var end def interpolate_Object(c) @@ -1069,7 +1069,7 @@ def interpolate_Object(c) end def interpolate_QualifiedName(c) - self.var + var end # rewrite left expression to variable if it is name, number, and recurse if it is an access expression diff --git a/lib/puppet/pops/parser/epp_parser.rb b/lib/puppet/pops/parser/epp_parser.rb index e70899920af..804f34c5e09 100644 --- a/lib/puppet/pops/parser/epp_parser.rb +++ b/lib/puppet/pops/parser/epp_parser.rb @@ -43,7 +43,7 @@ def _parse # rescue => except # raise Puppet::ParseError.new(except.message, @lexer.file, @lexer.line, @lexer.pos, except) end - return main + main ensure @lexer.clear @namestack = [] diff --git a/lib/puppet/pops/parser/locator.rb b/lib/puppet/pops/parser/locator.rb index b91e4fb6e1d..0d469a33a36 100644 --- a/lib/puppet/pops/parser/locator.rb +++ b/lib/puppet/pops/parser/locator.rb @@ -163,7 +163,7 @@ def ary_bsearch_i(ary, value) return nil if low == ary.length return nil unless satisfied - return low + low end def hash @@ -192,7 +192,7 @@ def line_for_offset(offset) # If not found it is after last # clear cache @prev_offset = @prev_line = nil - return line_index.size + line_index.size end end diff --git a/lib/puppet/pops/parser/parser_support.rb b/lib/puppet/pops/parser/parser_support.rb index 0f6bdca2687..4dbf04f7948 100644 --- a/lib/puppet/pops/parser/parser_support.rb +++ b/lib/puppet/pops/parser/parser_support.rb @@ -241,7 +241,7 @@ def _parse @yydebug = false main = yyparse(@lexer, :scan) end - return main + main ensure @lexer.clear @namestack = [] diff --git a/lib/puppet/pops/resource/resource_type_impl.rb b/lib/puppet/pops/resource/resource_type_impl.rb index 144145438d3..df45cac4c5e 100644 --- a/lib/puppet/pops/resource/resource_type_impl.rb +++ b/lib/puppet/pops/resource/resource_type_impl.rb @@ -75,7 +75,7 @@ def <=>(other) return nil unless other.is_a?(Puppet::CompilableResourceType) # against other type instances. - self.ref <=> other.ref + ref <=> other.ref end METAPARAMS = [ diff --git a/lib/puppet/pops/serialization/abstract_writer.rb b/lib/puppet/pops/serialization/abstract_writer.rb index 7f3ebf2dfc4..66daf0a3cbe 100644 --- a/lib/puppet/pops/serialization/abstract_writer.rb +++ b/lib/puppet/pops/serialization/abstract_writer.rb @@ -213,7 +213,7 @@ def register_types end def to_s - "#{self.class.name}" + self.class.name.to_s end def inspect diff --git a/lib/puppet/pops/types/iterable.rb b/lib/puppet/pops/types/iterable.rb index a1883daaa10..bfaf7ea8f99 100644 --- a/lib/puppet/pops/types/iterable.rb +++ b/lib/puppet/pops/types/iterable.rb @@ -32,7 +32,7 @@ module Iterable # @raise [ArgumentError] In case an `Iterable` cannot be produced # @api public def self.asserted_iterable(my_caller, obj, infer_elements = false) - iter = self.on(obj, nil, infer_elements) + iter = on(obj, nil, infer_elements) raise ArgumentError, "#{my_caller.class}(): wrong argument type (#{obj.class}; is not Iterable." if iter.nil? iter diff --git a/lib/puppet/pops/types/p_binary_type.rb b/lib/puppet/pops/types/p_binary_type.rb index 8bbf8815a09..cc29ff3d8eb 100644 --- a/lib/puppet/pops/types/p_binary_type.rb +++ b/lib/puppet/pops/types/p_binary_type.rb @@ -122,7 +122,7 @@ def eql?(o) end def ==(o) - self.eql?(o) + eql?(o) end def length diff --git a/lib/puppet/pops/types/p_object_type.rb b/lib/puppet/pops/types/p_object_type.rb index 7d46279ea39..38f576543df 100644 --- a/lib/puppet/pops/types/p_object_type.rb +++ b/lib/puppet/pops/types/p_object_type.rb @@ -170,7 +170,7 @@ def assert_override(parent_members) # @raises [Puppet::ParseError] if the assertion fails # @api private def assert_can_be_overridden(member) - unless self.instance_of?(member.class) + unless instance_of?(member.class) raise Puppet::ParseError, _("%{member} attempts to override %{label}") % { member: member.label, label: label } end if @final && !(constant? && member.constant?) diff --git a/lib/puppet/pops/types/p_sensitive_type.rb b/lib/puppet/pops/types/p_sensitive_type.rb index 8f0ddba2e82..556f30d5e01 100644 --- a/lib/puppet/pops/types/p_sensitive_type.rb +++ b/lib/puppet/pops/types/p_sensitive_type.rb @@ -72,7 +72,7 @@ def from_sensitive(value) private def _assignable?(o, guard) - self.instance_of?(o.class) && @type.assignable?(o.type, guard) + instance_of?(o.class) && @type.assignable?(o.type, guard) end DEFAULT = PSensitiveType.new diff --git a/lib/puppet/pops/types/p_timespan_type.rb b/lib/puppet/pops/types/p_timespan_type.rb index b59ad356799..43d2c15ae7f 100644 --- a/lib/puppet/pops/types/p_timespan_type.rb +++ b/lib/puppet/pops/types/p_timespan_type.rb @@ -17,7 +17,7 @@ def initialize(from, to = nil) # @return [Boolean] `true` if this range intersects with the other range # @api public def intersect?(o) - self.instance_of?(o.class) && !(@to < o.numeric_from || o.numeric_to < @from) + instance_of?(o.class) && !(@to < o.numeric_from || o.numeric_to < @from) end # Returns the lower bound of the numeric range or `nil` if no lower bound is set. @@ -94,7 +94,7 @@ def merge(o) end def _assignable?(o, guard) - self.instance_of?(o.class) && numeric_from <= o.numeric_from && numeric_to >= o.numeric_to + instance_of?(o.class) && numeric_from <= o.numeric_from && numeric_to >= o.numeric_to end end diff --git a/lib/puppet/pops/types/p_type_set_type.rb b/lib/puppet/pops/types/p_type_set_type.rb index 1dfebd989e3..7c07497ab09 100644 --- a/lib/puppet/pops/types/p_type_set_type.rb +++ b/lib/puppet/pops/types/p_type_set_type.rb @@ -359,20 +359,20 @@ def instance?(o, guard = nil) end DEFAULT = - self - .new({ - KEY_NAME => 'DefaultTypeSet', - KEY_NAME_AUTHORITY => Pcore::RUNTIME_NAME_AUTHORITY, - Pcore::KEY_PCORE_URI => Pcore::PCORE_URI, - Pcore::KEY_PCORE_VERSION => Pcore::PCORE_VERSION, - KEY_VERSION => SemanticPuppet::Version.new(0, 0, 0) - }) + + new({ + KEY_NAME => 'DefaultTypeSet', + KEY_NAME_AUTHORITY => Pcore::RUNTIME_NAME_AUTHORITY, + Pcore::KEY_PCORE_URI => Pcore::PCORE_URI, + Pcore::KEY_PCORE_VERSION => Pcore::PCORE_VERSION, + KEY_VERSION => SemanticPuppet::Version.new(0, 0, 0) + }) protected # @api_private def _assignable?(o, guard) - self.instance_of?(o.class) && (self == DEFAULT || eql?(o)) + instance_of?(o.class) && (self == DEFAULT || eql?(o)) end private diff --git a/lib/puppet/pops/types/ruby_generator.rb b/lib/puppet/pops/types/ruby_generator.rb index e3cc3a10797..861e92fbe99 100644 --- a/lib/puppet/pops/types/ruby_generator.rb +++ b/lib/puppet/pops/types/ruby_generator.rb @@ -64,7 +64,7 @@ def create_class(obj) class_body(key, EMPTY_ARRAY, class_def) cls = Class.new(parent_class) cls.class_eval(class_def) - cls.define_singleton_method(:_pcore_type) { return key } + cls.define_singleton_method(:_pcore_type) { key } key.implementation_class = cls end hash[key] = cls diff --git a/lib/puppet/pops/types/string_converter.rb b/lib/puppet/pops/types/string_converter.rb index a2f18d60f95..f633a986e8e 100644 --- a/lib/puppet/pops/types/string_converter.rb +++ b/lib/puppet/pops/types/string_converter.rb @@ -47,7 +47,7 @@ def breaks? end def padding - return ' ' * 2 * level + ' ' * 2 * level end end @@ -1136,7 +1136,7 @@ def get_format(val_t, format_options) fmt = format_options.find { |k, _| k.assignable?(val_t) } return fmt[1] unless fmt.nil? - return Format.new("%s") + Format.new("%s") end private :get_format end diff --git a/lib/puppet/pops/types/type_factory.rb b/lib/puppet/pops/types/type_factory.rb index 7cc44253b0c..b76698a9f83 100644 --- a/lib/puppet/pops/types/type_factory.rb +++ b/lib/puppet/pops/types/type_factory.rb @@ -313,7 +313,7 @@ def self.scalar_data # @api public # def self.all_callables - return PCallableType::DEFAULT + PCallableType::DEFAULT end # Produces a Callable type with one signature without support for a block diff --git a/lib/puppet/pops/types/type_mismatch_describer.rb b/lib/puppet/pops/types/type_mismatch_describer.rb index 854b2098207..19c97cdee69 100644 --- a/lib/puppet/pops/types/type_mismatch_describer.rb +++ b/lib/puppet/pops/types/type_mismatch_describer.rb @@ -131,7 +131,7 @@ def chop_path(element_index) chopped_path = @path.clone chopped_path.delete_at(element_index) - copy = self.clone + copy = clone copy.instance_variable_set(:@path, chopped_path) copy end diff --git a/lib/puppet/pops/types/types.rb b/lib/puppet/pops/types/types.rb index 9d3bbafe61d..41885f2d006 100644 --- a/lib/puppet/pops/types/types.rb +++ b/lib/puppet/pops/types/types.rb @@ -131,7 +131,7 @@ def assignable?(o, guard = nil) end when PVariantType # Assignable if all contained types are assignable, or if this is exactly Any - return true if self.instance_of?(PAnyType) + return true if instance_of?(PAnyType) # An empty variant may be assignable to NotUndef[T] if T is assignable to empty variant return _assignable?(o, guard) if is_a?(PNotUndefType) && o.types.empty? @@ -737,7 +737,7 @@ def self.register_ptype(loader, ir) end def instance?(o, guard = nil) - return o.instance_of?(String) || o.is_a?(Integer) || o.is_a?(Float) || o.is_a?(TrueClass) || o.is_a?(FalseClass) + o.instance_of?(String) || o.is_a?(Integer) || o.is_a?(Float) || o.is_a?(TrueClass) || o.is_a?(FalseClass) end DEFAULT = PScalarDataType.new @@ -952,7 +952,7 @@ def initialize(from, to = Float::INFINITY) # @return [Boolean] `true` if this range intersects with the other range # @api public def intersect?(o) - self.instance_of?(o.class) && !(@to < o.numeric_from || o.numeric_to < @from) + instance_of?(o.class) && !(@to < o.numeric_from || o.numeric_to < @from) end # Returns the lower bound of the numeric range or `nil` if no lower bound is set. @@ -1967,7 +1967,7 @@ def resolve(loader) end def <=>(o) - self.name <=> o.name + name <=> o.name end def eql?(o) diff --git a/lib/puppet/pops/validation/checker4_0.rb b/lib/puppet/pops/validation/checker4_0.rb index 472e7ade9ca..691a6ce629c 100644 --- a/lib/puppet/pops/validation/checker4_0.rb +++ b/lib/puppet/pops/validation/checker4_0.rb @@ -620,7 +620,7 @@ def namespace_for_file(file) # If a file comes from a module, but isn't in the right place, always error names = dir_to_names(relative_path) - return adapter.file_to_namespace[file] = (names == BAD_MODULE_FILE ? BAD_MODULE_FILE : names.join("::").freeze) + adapter.file_to_namespace[file] = (names == BAD_MODULE_FILE ? BAD_MODULE_FILE : names.join("::").freeze) end def initial_manifest?(path, manifest_setting) @@ -647,7 +647,7 @@ def is_parent_dir_of?(parent_dir, child_dir) parent_dir_path = Pathname.new(parent_dir) clean_parent = parent_dir_path.cleanpath.to_s + File::SEPARATOR - return child_dir.start_with?(clean_parent) + child_dir.start_with?(clean_parent) end private :is_parent_dir_of? diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb index 41dc566423d..f5f50db26df 100644 --- a/lib/puppet/property.rb +++ b/lib/puppet/property.rb @@ -204,11 +204,11 @@ def call_provider(value) # def change_to_s(current_value, newvalue) if current_value == :absent - return "defined '#{name}' as #{should_to_s(newvalue)}" + "defined '#{name}' as #{should_to_s(newvalue)}" elsif newvalue == :absent or newvalue == [:absent] - return "undefined '#{name}' from #{is_to_s(current_value)}" + "undefined '#{name}' from #{is_to_s(current_value)}" else - return "#{name} changed #{is_to_s(current_value)} to #{should_to_s(newvalue)}" + "#{name} changed #{is_to_s(current_value)} to #{should_to_s(newvalue)}" end rescue Puppet::Error raise @@ -225,17 +225,17 @@ def change_to_s(current_value, newvalue) # @return [String] the name of the event that describes the change # def event_name - value = self.should + value = should event_name = self.class.value_option(value, :event) and return event_name name == :ensure or return (name.to_s + "_changed").to_sym - return (resource.type.to_s + case value - when :present; "_created" - when :absent; "_removed" - else "_changed" - end).to_sym + (resource.type.to_s + case value + when :present; "_created" + when :absent; "_removed" + else "_changed" + end).to_sym end # Produces an event describing a change of this property. @@ -306,7 +306,7 @@ def self.method_added(sym) # @api public # def insync?(is) - self.devfail "#{self.class.name}'s should is not array" unless @should.is_a?(Array) + devfail "#{self.class.name}'s should is not array" unless @should.is_a?(Array) # an empty array is analogous to no should values return true if @should.empty? @@ -331,14 +331,14 @@ def insync?(is) # # This does mean that property equality is not commutative, and will not # work unless the `is` value is carefully arranged to match the should. - return (is == @should or is == @should.map(&:to_s)) + (is == @should or is == @should.map(&:to_s)) # When we stop being idiots about this, and actually have meaningful # semantics, this version is the thing we actually want to do. # # return is.zip(@should).all? {|a, b| property_matches?(a, b) } else - return @should.any? { |want| property_matches?(is, want) } + @should.any? { |want| property_matches?(is, want) } end end @@ -369,7 +369,7 @@ def insync_values?(should, is) # avoid it # TRANSLATORS 'insync_values?' should not be translated msg = _("Unknown failure using insync_values? on type: %{type} / property: %{name} to compare values %{should} and %{is}") % - { type: self.resource.ref, name: self.name, should: should, is: is } + { type: resource.ref, name: name, should: should, is: is } Puppet.info(msg) # Return nil, ie. unknown @@ -484,9 +484,9 @@ def set(value) # Set a name for looking up associated options like the event. name = self.class.value_name(value) method = self.class.value_option(name, :method) - if method && self.respond_to?(method) + if method && respond_to?(method) begin - self.send(method) + send(method) rescue Puppet::Error raise rescue => detail @@ -501,7 +501,7 @@ def set(value) if block # FIXME It'd be better here to define a method, so that # the blocks could return values. - self.instance_eval(&block) + instance_eval(&block) else call_provider(value) end @@ -524,12 +524,12 @@ def set(value) def should return nil unless defined?(@should) - self.devfail "should for #{self.class.name} on #{resource.name} is not an array" unless @should.is_a?(Array) + devfail "should for #{self.class.name} on #{resource.name} is not an array" unless @should.is_a?(Array) if match_all? - return @should.collect { |val| self.unmunge(val) } + @should.collect { |val| unmunge(val) } else - return self.unmunge(@should[0]) + unmunge(@should[0]) end end @@ -547,7 +547,7 @@ def should=(values) @shouldorig = values values.each { |val| validate(val) } - @should = values.collect { |val| self.munge(val) } + @should = values.collect { |val| munge(val) } end # Produces a pretty printing string for the given value. @@ -600,7 +600,7 @@ def validate_features_per_value(value) # @return [Object, nil] Returns the wanted _(should)_ value of this property. def value - self.should + should end # (see #should=) diff --git a/lib/puppet/property/ensure.rb b/lib/puppet/property/ensure.rb index 18c0a4fc04a..a227145916c 100644 --- a/lib/puppet/property/ensure.rb +++ b/lib/puppet/property/ensure.rb @@ -53,16 +53,16 @@ def self.inherited(sub) def change_to_s(currentvalue, newvalue) if currentvalue == :absent || currentvalue.nil? - return _("created") + _("created") elsif newvalue == :absent - return _("removed") + _("removed") else - return _('%{name} changed %{is} to %{should}') % { name: name, is: is_to_s(currentvalue), should: should_to_s(newvalue) } + _('%{name} changed %{is} to %{should}') % { name: name, is: is_to_s(currentvalue), should: should_to_s(newvalue) } end rescue Puppet::Error raise rescue => detail - raise Puppet::DevError, _("Could not convert change %{name} to string: %{detail}") % { name: self.name, detail: detail }, detail.backtrace + raise Puppet::DevError, _("Could not convert change %{name} to string: %{detail}") % { name: name, detail: detail }, detail.backtrace end # Retrieves the _is_ value for the ensure property. @@ -88,9 +88,9 @@ def retrieve raise Puppet::DevError, _("No ability to determine if %{name} exists") % { name: @resource.class.name } end if result - return :present + :present else - return :absent + :absent end end diff --git a/lib/puppet/property/keyvalue.rb b/lib/puppet/property/keyvalue.rb index fc6adcae74e..28933aae67b 100644 --- a/lib/puppet/property/keyvalue.rb +++ b/lib/puppet/property/keyvalue.rb @@ -110,9 +110,9 @@ def retrieve # ok, some 'convention' if the keyvalue property is named properties, provider should implement a properties method key_hash = provider.send(name) if provider if key_hash && key_hash != :absent - return key_hash + key_hash else - return :absent + :absent end end @@ -121,7 +121,7 @@ def retrieve def insync?(is) return true unless is - (is == self.should) + (is == should) end # We only accept an array of key/value pairs (strings), a single @@ -135,7 +135,7 @@ def insync?(is) next if value.is_a?(Hash) - unless value.include?("#{separator}") + unless value.include?(separator.to_s) raise ArgumentError, _("Key/value pairs must be separated by '%{separator}'") % { separator: separator } end end diff --git a/lib/puppet/property/list.rb b/lib/puppet/property/list.rb index 31c522e4f91..ded51d0bb01 100644 --- a/lib/puppet/property/list.rb +++ b/lib/puppet/property/list.rb @@ -48,9 +48,9 @@ def retrieve # ok, some 'convention' if the list property is named groups, provider should implement a groups method tmp = provider.send(name) if provider if tmp && tmp != :absent - return tmp.instance_of?(Array) ? tmp : tmp.split(delimiter) + tmp.instance_of?(Array) ? tmp : tmp.split(delimiter) else - return :absent + :absent end end @@ -64,7 +64,7 @@ def prepare_is_for_comparison(is) def insync?(is) return true unless is - (prepare_is_for_comparison(is) == self.should) + (prepare_is_for_comparison(is) == should) end end end diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb index c22eac57b8f..a0996576f51 100644 --- a/lib/puppet/provider.rb +++ b/lib/puppet/provider.rb @@ -290,7 +290,7 @@ def self.some_default_match(defaultlist) def self.fact_match(fact, values) fact_val = Puppet.runtime[:facter].value(fact).to_s.downcase if fact_val.empty? - return false + false else values = [values] unless values.is_a?(Array) values.any? do |value| @@ -380,7 +380,7 @@ def self.initvars # @raise [Puppet::DevError] Error indicating that the method should have been implemented by subclass. # @see prefetch def self.instances - raise Puppet::DevError, _("To support listing resources of this type the '%{provider}' provider needs to implement an 'instances' class method returning the current set of resources. We recommend porting your module to the simpler Resource API instead: https://puppet.com/search/docs?keys=resource+api") % { provider: self.name } + raise Puppet::DevError, _("To support listing resources of this type the '%{provider}' provider needs to implement an 'instances' class method returning the current set of resources. We recommend porting your module to the simpler Resource API instead: https://puppet.com/search/docs?keys=resource+api") % { provider: name } end # Creates getter- and setter- methods for each property supported by the resource type. @@ -415,7 +415,7 @@ def self.mk_resource_methods end end - self.initvars + initvars # This method is used to generate a method for a command. # @return [void] @@ -437,7 +437,7 @@ def self.create_class_and_instance_method(name, &block) # @return [String] Returns the data source, which is the provider name if no other source has been set. # @todo Unclear what "the source" is used for? def self.source - @source ||= self.name + @source ||= name end # Returns true if the given attribute/parameter is supported by the provider. @@ -536,8 +536,8 @@ def initialize(resource = nil) def name n = @property_hash[:name] if n - return n - elsif self.resource + n + elsif resource resource.name else raise Puppet::DevError, _("No resource and no name in property hash in %{class_name} instance") % { class_name: self.class.name } @@ -579,7 +579,7 @@ def <=>(other) return nil unless other.is_a? Puppet::Provider # Otherwise, order by the providers class name. - return self.class.name <=> other.class.name + self.class.name <=> other.class.name end # @comment Document prefetch here as it does not exist anywhere else (called from transaction if implemented) diff --git a/lib/puppet/provider/exec.rb b/lib/puppet/provider/exec.rb index 85137f8a90e..a0e28750adc 100644 --- a/lib/puppet/provider/exec.rb +++ b/lib/puppet/provider/exec.rb @@ -82,7 +82,7 @@ def run(command, check = false) # Return output twice as processstatus was returned before, but only exitstatus was ever called. # Output has the exitstatus on it so it is returned instead. This is here twice as changing this # would result in a change to the underlying API. - return output, output + [output, output] end def extractexe(command) diff --git a/lib/puppet/provider/file/posix.rb b/lib/puppet/provider/file/posix.rb index 2b3de8d3d4d..445dbb13cbf 100644 --- a/lib/puppet/provider/file/posix.rb +++ b/lib/puppet/provider/file/posix.rb @@ -27,9 +27,9 @@ def uid2name(id) end if user.uid == "" - return nil + nil else - return user.name + user.name end end @@ -51,9 +51,9 @@ def gid2name(id) end if group.gid == "" - return nil + nil else - return group.name + group.name end end @@ -75,7 +75,7 @@ def owner # large UIDs instead of negative ones. This isn't a Ruby bug, # it's an OS X bug, since it shows up in perl, too. if currentvalue > Puppet[:maximum_uid].to_i - self.warning _("Apparently using negative UID (%{currentvalue}) on a platform that does not consistently handle them") % { currentvalue: currentvalue } + warning _("Apparently using negative UID (%{currentvalue}) on a platform that does not consistently handle them") % { currentvalue: currentvalue } currentvalue = :silly end @@ -107,7 +107,7 @@ def group # large GIDs instead of negative ones. This isn't a Ruby bug, # it's an OS X bug, since it shows up in perl, too. if currentvalue > Puppet[:maximum_uid].to_i - self.warning _("Apparently using negative GID (%{currentvalue}) on a platform that does not consistently handle them") % { currentvalue: currentvalue } + warning _("Apparently using negative GID (%{currentvalue}) on a platform that does not consistently handle them") % { currentvalue: currentvalue } currentvalue = :silly end @@ -132,9 +132,9 @@ def group=(should) def mode stat = resource.stat if stat - return (stat.mode & 0o07777).to_s(8).rjust(4, '0') + (stat.mode & 0o07777).to_s(8).rjust(4, '0') else - return :absent + :absent end end diff --git a/lib/puppet/provider/group/directoryservice.rb b/lib/puppet/provider/group/directoryservice.rb index becbf1cfca7..25ca91027e4 100644 --- a/lib/puppet/provider/group/directoryservice.rb +++ b/lib/puppet/provider/group/directoryservice.rb @@ -14,10 +14,11 @@ def members_insync?(current, should) return false unless current + if current == :absent - return should.empty? + should.empty? else - return current.sort.uniq == should.sort.uniq + current.sort.uniq == should.sort.uniq end end end diff --git a/lib/puppet/provider/group/windows_adsi.rb b/lib/puppet/provider/group/windows_adsi.rb index 0125e3347ba..2e169b8ed05 100644 --- a/lib/puppet/provider/group/windows_adsi.rb +++ b/lib/puppet/provider/group/windows_adsi.rb @@ -57,7 +57,7 @@ def members_to_s(users) resource.debug("#{sid.domain}\\#{account} (#{sid.sid})") sid.domain ? "#{sid.domain}\\#{account}" : account end - return users.join(',') + users.join(',') end def member_valid?(user_name) diff --git a/lib/puppet/provider/nameservice.rb b/lib/puppet/provider/nameservice.rb index 1efce56b939..382494b9e8b 100644 --- a/lib/puppet/provider/nameservice.rb +++ b/lib/puppet/provider/nameservice.rb @@ -108,15 +108,15 @@ def autogen(field) field = field.intern id_generators = { :user => :uid, :group => :gid } if id_generators[@resource.class.name] == field - return self.class.autogen_id(field, @resource.class.name) + self.class.autogen_id(field, @resource.class.name) else value = self.class.autogen_default(field) if value - return value + value elsif respond_to?("autogen_#{field}") - return send("autogen_#{field}") + send("autogen_#{field}") else - return nil + nil end end end @@ -160,7 +160,7 @@ def create begin sensitive = has_sensitive_data? - execute(self.addcmd, { :failonfail => true, :combine => true, :custom_environment => @custom_environment, :sensitive => sensitive }) + execute(addcmd, { :failonfail => true, :combine => true, :custom_environment => @custom_environment, :sensitive => sensitive }) if feature?(:manages_password_age) && (cmd = passcmd) execute(cmd, { :failonfail => true, :combine => true, :custom_environment => @custom_environment, :sensitive => sensitive }) end @@ -177,7 +177,7 @@ def delete end begin - execute(self.deletecmd, { :failonfail => true, :combine => true, :custom_environment => @custom_environment }) + execute(deletecmd, { :failonfail => true, :combine => true, :custom_environment => @custom_environment }) rescue Puppet::ExecutionFailure => detail raise Puppet::Error, _("Could not delete %{resource} %{name}: %{detail}") % { resource: @resource.class.name, name: @resource.name, detail: detail }, detail.backtrace end diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb index c7bcf5efc21..3b3f8804617 100644 --- a/lib/puppet/provider/nameservice/directoryservice.rb +++ b/lib/puppet/provider/nameservice/directoryservice.rb @@ -79,7 +79,7 @@ def self.instances # Create a new instance of this Puppet::Type for each object present # on the system. list_all_present.collect do |name_string| - self.new(single_report(name_string, *type_property_array)) + new(single_report(name_string, *type_property_array)) end end @@ -144,7 +144,7 @@ def self.generate_attribute_hash(input_hash, *type_properties) # stored in the user record. It is stored at a path that involves the # UUID of the user record for non-Mobile local accounts. # Mobile Accounts are out of scope for this provider for now - attribute_hash[:password] = self.get_password(attribute_hash[:guid], attribute_hash[:name]) if @resource_type.validproperties.include?(:password) and Puppet.features.root? + attribute_hash[:password] = get_password(attribute_hash[:guid], attribute_hash[:name]) if @resource_type.validproperties.include?(:password) and Puppet.features.root? attribute_hash end @@ -168,9 +168,9 @@ def self.single_report(resource_name, *type_properties) fail(_("Could not get report. command execution failed.")) end - dscl_plist = self.parse_dscl_plist_data(dscl_output) + dscl_plist = parse_dscl_plist_data(dscl_output) - self.generate_attribute_hash(dscl_plist, *type_properties) + generate_attribute_hash(dscl_plist, *type_properties) end def self.get_exec_preamble(ds_action, resource_name = nil) @@ -325,7 +325,7 @@ def ensure=(ensure_value) else value = autogen(name) if value - self.send(name.to_s + "=", value) + send(name.to_s + "=", value) else next end diff --git a/lib/puppet/provider/package/aix.rb b/lib/puppet/provider/package/aix.rb index eee60e39135..2f046fd20ca 100644 --- a/lib/puppet/provider/package/aix.rb +++ b/lib/puppet/provider/package/aix.rb @@ -53,7 +53,7 @@ def self.prefetch(packages) updates = {} sources.each do |source| - execute(self.srclistcmd(source)).each_line do |line| + execute(srclistcmd(source)).each_line do |line| next unless line =~ /^[^#][^:]*:([^:]*):([^:]*)/ current = {} @@ -137,9 +137,9 @@ def self.pkglist(hash = {}) end if hash[:pkgname] - return list.shift + list.shift else - return list + list end end @@ -153,11 +153,11 @@ def latest upd = latest_info unless upd.nil? - return "#{upd[:version]}" + (upd[:version]).to_s else raise Puppet::DevError, _("Tried to get latest on a missing package") if properties[:ensure] == :absent - return properties[:ensure] + properties[:ensure] end end @@ -166,6 +166,6 @@ def query end def update - self.install(false) + install(false) end end diff --git a/lib/puppet/provider/package/apple.rb b/lib/puppet/provider/package/apple.rb index ccbf2538bcb..44f2839ffcd 100644 --- a/lib/puppet/provider/package/apple.rb +++ b/lib/puppet/provider/package/apple.rb @@ -15,7 +15,7 @@ def self.instances instance_by_name.collect do |name| - self.new( + new( :name => name, :provider => :apple, :ensure => :installed diff --git a/lib/puppet/provider/package/apt.rb b/lib/puppet/provider/package/apt.rb index f08ad339b90..4da9ed3f9d2 100644 --- a/lib/puppet/provider/package/apt.rb +++ b/lib/puppet/provider/package/apt.rb @@ -117,7 +117,7 @@ def best_version(should_range) # Install a package using 'apt-get'. This function needs to support # installing a specific version. def install - self.run_preseed if @resource[:responsefile] + run_preseed if @resource[:responsefile] should = @resource[:ensure] if should.is_a?(String) @@ -165,17 +165,17 @@ def install end # rubocop:enable Style/RedundantCondition - self.unhold if self.properties[:mark] == :hold + unhold if properties[:mark] == :hold begin aptget(*cmd) ensure - self.hold if @resource[:mark] == :hold + hold if @resource[:mark] == :hold end # If a source file was specified, we must make sure the expected version was installed from specified file if source && !%i[present installed].include?(should) - is = self.query - raise Puppet::Error, _("Could not find package %{name}") % { name: self.name } unless is + is = query + raise Puppet::Error, _("Could not find package %{name}") % { name: name } unless is version = is[:ensure] @@ -189,10 +189,10 @@ def latest output = aptcache :policy, @resource[:name] if output =~ /Candidate:\s+(\S+)\s/ - return Regexp.last_match(1) + Regexp.last_match(1) else - self.err _("Could not find latest version") - return nil + err _("Could not find latest version") + nil end end @@ -202,26 +202,26 @@ def latest def run_preseed response = @resource[:responsefile] if response && Puppet::FileSystem.exist?(response) - self.info(_("Preseeding %{response} to debconf-set-selections") % { response: response }) + info(_("Preseeding %{response} to debconf-set-selections") % { response: response }) preseed response else - self.info _("No responsefile specified or non existent, not preseeding anything") + info _("No responsefile specified or non existent, not preseeding anything") end end def uninstall - self.run_preseed if @resource[:responsefile] + run_preseed if @resource[:responsefile] args = ['-y', '-q'] - args << '--allow-change-held-packages' if self.properties[:mark] == :hold + args << '--allow-change-held-packages' if properties[:mark] == :hold args << :remove << @resource[:name] aptget(*args) end def purge - self.run_preseed if @resource[:responsefile] + run_preseed if @resource[:responsefile] args = ['-y', '-q'] - args << '--allow-change-held-packages' if self.properties[:mark] == :hold + args << '--allow-change-held-packages' if properties[:mark] == :hold args << :remove << '--purge' << @resource[:name] aptget(*args) # workaround a "bug" in apt, that already removed packages are not purged diff --git a/lib/puppet/provider/package/aptitude.rb b/lib/puppet/provider/package/aptitude.rb index 161e1cbd709..2bb8d16b554 100644 --- a/lib/puppet/provider/package/aptitude.rb +++ b/lib/puppet/provider/package/aptitude.rb @@ -19,7 +19,7 @@ def aptget(*args) # Yay, stupid aptitude doesn't throw an error when the package is missing. if args.include?(:install) and output.to_s =~ /Couldn't find any package/ - raise Puppet::Error, _("Could not find package %{name}") % { name: self.name } + raise Puppet::Error, _("Could not find package %{name}") % { name: name } end end diff --git a/lib/puppet/provider/package/aptrpm.rb b/lib/puppet/provider/package/aptrpm.rb index 78b5a110c17..81edfaa1e06 100644 --- a/lib/puppet/provider/package/aptrpm.rb +++ b/lib/puppet/provider/package/aptrpm.rb @@ -56,25 +56,25 @@ def latest if version =~ /^([^(]+)\(/ Regexp.last_match(1) else - self.warning _("Could not match version '%{version}'") % { version: version } + warning _("Could not match version '%{version}'") % { version: version } nil end }.sort { |a, b| versioncmp(a, b) } if available_versions.length == 0 - self.debug "No latest version" + debug "No latest version" print output if Puppet[:debug] end # Get the latest and greatest version number - return available_versions.pop + available_versions.pop else - self.err _("Could not match string") + err _("Could not match string") end end def update - self.install + install end def uninstall diff --git a/lib/puppet/provider/package/blastwave.rb b/lib/puppet/provider/package/blastwave.rb index 9847682dbec..8eec34e2873 100644 --- a/lib/puppet/provider/package/blastwave.rb +++ b/lib/puppet/provider/package/blastwave.rb @@ -50,12 +50,12 @@ def self.blastlist(hash) end if hash[:justme] - return list[0] + list[0] else list.reject! { |h| h[:ensure] == :absent } - return list + list end end @@ -74,12 +74,12 @@ def self.blastsplit(line) hash[:avail] = hash[:ensure] if hash[:avail] == "SAME" # Use the name method, so it works with subclasses. - hash[:provider] = self.name + hash[:provider] = name - return hash + hash else Puppet.warning _("Cannot match %{line}") % { line: line } - return nil + nil end end diff --git a/lib/puppet/provider/package/dnfmodule.rb b/lib/puppet/provider/package/dnfmodule.rb index 22eaea7cdee..8d58d2fdd8f 100644 --- a/lib/puppet/provider/package/dnfmodule.rb +++ b/lib/puppet/provider/package/dnfmodule.rb @@ -113,7 +113,7 @@ def insync?(is) end return true if pkg end - return false + false end def enable(args = @resource[:name]) diff --git a/lib/puppet/provider/package/dpkg.rb b/lib/puppet/provider/package/dpkg.rb index 581c1645dd6..f91b5df5cc0 100644 --- a/lib/puppet/provider/package/dpkg.rb +++ b/lib/puppet/provider/package/dpkg.rb @@ -69,7 +69,7 @@ def self.parse_line(line, regex = self::FIELDS_REGEX) hash[field] = value end - hash[:provider] = self.name + hash[:provider] = name if hash[:status] == 'not-installed' hash[:ensure] = :purged @@ -81,7 +81,7 @@ def self.parse_line(line, regex = self::FIELDS_REGEX) Puppet.debug("Failed to match dpkg-query line #{line.inspect}") end - return hash + hash end public @@ -101,16 +101,16 @@ def install end args << '-i' << file - self.unhold if self.properties[:mark] == :hold + unhold if properties[:mark] == :hold begin dpkg(*args) ensure - self.hold if @resource[:mark] == :hold + hold if @resource[:mark] == :hold end end def update - self.install + install end # Return the version from the package. diff --git a/lib/puppet/provider/package/fink.rb b/lib/puppet/provider/package/fink.rb index d7579fed69b..b4e857ba3dd 100644 --- a/lib/puppet/provider/package/fink.rb +++ b/lib/puppet/provider/package/fink.rb @@ -24,7 +24,7 @@ def finkcmd(*args) # Install a package using 'apt-get'. This function needs to support # installing a specific version. def install - self.run_preseed if @resource[:responsefile] + run_preseed if @resource[:responsefile] should = @resource.should(:ensure) str = @resource[:name] @@ -39,11 +39,11 @@ def install cmd << :install << str - self.unhold if self.properties[:mark] == :hold + unhold if properties[:mark] == :hold begin finkcmd(cmd) ensure - self.hold if @resource[:mark] == :hold + hold if @resource[:mark] == :hold end end @@ -52,10 +52,10 @@ def latest output = aptcache :policy, @resource[:name] if output =~ /Candidate:\s+(\S+)\s/ - return Regexp.last_match(1) + Regexp.last_match(1) else - self.err _("Could not find latest version") - return nil + err _("Could not find latest version") + nil end end @@ -65,34 +65,34 @@ def latest def run_preseed response = @resource[:responsefile] if response && Puppet::FileSystem.exist?(response) - self.info(_("Preseeding %{response} to debconf-set-selections") % { response: response }) + info(_("Preseeding %{response} to debconf-set-selections") % { response: response }) preseed response else - self.info _("No responsefile specified or non existent, not preseeding anything") + info _("No responsefile specified or non existent, not preseeding anything") end end def update - self.install + install end def uninstall - self.unhold if self.properties[:mark] == :hold + unhold if properties[:mark] == :hold begin finkcmd "-y", "-q", :remove, @model[:name] rescue StandardError, LoadError => e - self.hold if self.properties[:mark] == :hold + hold if properties[:mark] == :hold raise e end end def purge - self.unhold if self.properties[:mark] == :hold + unhold if properties[:mark] == :hold begin aptget '-y', '-q', 'remove', '--purge', @resource[:name] rescue StandardError, LoadError => e - self.hold if self.properties[:mark] == :hold + hold if properties[:mark] == :hold raise e end end diff --git a/lib/puppet/provider/package/gem.rb b/lib/puppet/provider/package/gem.rb index c3521eaacc6..c0a46c1a4e9 100644 --- a/lib/puppet/provider/package/gem.rb +++ b/lib/puppet/provider/package/gem.rb @@ -126,9 +126,9 @@ def self.gemlist(options) end if options[:justme] - return list.shift + list.shift else - return list + list end end @@ -243,7 +243,7 @@ def install(useversion = true) command_options << source else # interpret it as a gem repository - command_options << "--source" << "#{source}" << resource[:name] + command_options << "--source" << source.to_s << resource[:name] end end else @@ -282,7 +282,7 @@ def uninstall end def update - self.install(false) + install(false) end def install_options diff --git a/lib/puppet/provider/package/macports.rb b/lib/puppet/provider/package/macports.rb index ee41756f1c2..79e904d9b3f 100644 --- a/lib/puppet/provider/package/macports.rb +++ b/lib/puppet/provider/package/macports.rb @@ -44,7 +44,7 @@ def self.hash_from_line(line, regex, fields) fields.zip(match.captures) { |field, value| hash[field] = value } - hash[:provider] = self.name + hash[:provider] = name return hash end nil @@ -76,7 +76,7 @@ def query result = self.class.parse_installed_query_line(execute([command(:port), "-q", :installed, @resource[:name]], :failonfail => false, :combine => false)) return {} if result.nil? - return result + result end def latest diff --git a/lib/puppet/provider/package/nim.rb b/lib/puppet/provider/package/nim.rb index da2eef685f0..6c84a3a5e85 100644 --- a/lib/puppet/provider/package/nim.rb +++ b/lib/puppet/provider/package/nim.rb @@ -271,11 +271,11 @@ def determine_latest_version(showres_output, package_name) if packages[package_name].count == 1 version = packages[package_name].keys[0] - return packages[package_name][version], nil + [packages[package_name][version], nil] else versions = packages[package_name].keys latest_version = (versions.sort { |a, b| Puppet::Util::Package.versioncmp(b, a) })[0] - return packages[package_name][latest_version], latest_version + [packages[package_name][latest_version], latest_version] end end diff --git a/lib/puppet/provider/package/openbsd.rb b/lib/puppet/provider/package/openbsd.rb index 5ecd73b58b5..6e05ef03934 100644 --- a/lib/puppet/provider/package/openbsd.rb +++ b/lib/puppet/provider/package/openbsd.rb @@ -42,7 +42,7 @@ def self.instances hash[field] = value } - hash[:provider] = self.name + hash[:provider] = name packages << new(hash) hash = {} @@ -56,9 +56,9 @@ def self.instances } end - return packages + packages rescue Puppet::ExecutionFailure - return nil + nil end end @@ -95,7 +95,7 @@ def latest if output =~ /^#{resource[:name]}-(\d[^-]*)-?(\w*) \(installed\)$/ debug "Package is already the latest available" - return version + version else match = /^(.*)-(\d[^-]*)-?(\w*)$/.match(output) debug "Latest available for #{resource[:name]}: #{match[2]}" @@ -109,15 +109,15 @@ def latest # The locally installed package may actually be newer than what a mirror # has. Log it at debug, but ignore it otherwise. debug "Package #{resource[:name]} #{version} newer then available #{match[2]}" - return version + version else - return match[2] + match[2] end end end def update - self.install(true) + install(true) end def parse_pkgconf @@ -222,15 +222,15 @@ def get_version raise Puppet::Error, _("%{version} is not available for this package") % { version: version } end rescue Puppet::ExecutionFailure - return nil + nil end def query # Search for the version info if pkginfo(@resource[:name]) =~ /Information for (inst:)?#{@resource[:name]}-(\S+)/ - return { :ensure => Regexp.last_match(2) } + { :ensure => Regexp.last_match(2) } else - return nil + nil end end diff --git a/lib/puppet/provider/package/opkg.rb b/lib/puppet/provider/package/opkg.rb index 44bae199e01..e2524ba6673 100644 --- a/lib/puppet/provider/package/opkg.rb +++ b/lib/puppet/provider/package/opkg.rb @@ -21,7 +21,7 @@ def self.instances match = regex.match(line) if match fields.zip(match.captures) { |field, value| hash[field] = value } - hash[:provider] = self.name + hash[:provider] = name packages << new(hash) hash = {} else @@ -31,7 +31,7 @@ def self.instances end packages rescue Puppet::ExecutionFailure - return nil + nil end def latest @@ -57,7 +57,7 @@ def uninstall end def update - self.install + install end def query @@ -69,7 +69,7 @@ def query nil rescue Puppet::ExecutionFailure - return { + { :ensure => :purged, :status => 'missing', :name => @resource[:name], diff --git a/lib/puppet/provider/package/pacman.rb b/lib/puppet/provider/package/pacman.rb index 324f0182bb8..abfa24849cf 100644 --- a/lib/puppet/provider/package/pacman.rb +++ b/lib/puppet/provider/package/pacman.rb @@ -44,7 +44,7 @@ def install install_from_repo end - unless self.query + unless query fail(_("Could not find package '%{name}'") % { name: @resource[:name] }) end end @@ -125,7 +125,7 @@ def self.get_installed_groups(installed_packages, filter = nil) # should always result in the newest release. def update # Install in pacman can be used for update, too - self.install + install end # We rescue the main check from Pacman with a check on the AUR using yaourt, if installed @@ -141,7 +141,7 @@ def latest begin if pacman_check output = pacman "-Sp", "--print-format", "%v", resource_name - return output.chomp + output.chomp else output = yaourt "-Qma", resource_name output.split("\n").each do |line| diff --git a/lib/puppet/provider/package/pip.rb b/lib/puppet/provider/package/pip.rb index 9319db1af48..7c00c73b7b7 100644 --- a/lib/puppet/provider/package/pip.rb +++ b/lib/puppet/provider/package/pip.rb @@ -32,7 +32,7 @@ def self.specificity # Required by Puppet::Provider::Package::Targetable::resource_or_provider_command def self.provider_command # Ensure pip can upgrade pip, which usually puts pip into a new path /usr/local/bin/pip (compared to /usr/bin/pip) - self.cmd.map { |c| which(c) }.find { |c| !c.nil? } + cmd.map { |c| which(c) }.find { |c| !c.nil? } end def self.cmd @@ -65,7 +65,7 @@ def self.pip_version(command) def self.instances(target_command = nil) if target_command command = target_command - self.validate_command(command) + validate_command(command) else command = provider_command end @@ -74,7 +74,7 @@ def self.instances(target_command = nil) return packages unless command command_options = ['freeze'] - command_version = self.pip_version(command) + command_version = pip_version(command) if compare_pip_versions(command_version, '8.1.0') >= 0 command_options << '--all' end @@ -116,7 +116,7 @@ def query self.class.instances(command).each do |pkg| return pkg.properties if @resource[:name].casecmp(pkg.name).zero? end - return nil + nil end # Return latest version available for current package @@ -180,7 +180,7 @@ def available_versions_with_old_pip self.class.validate_command(command) Dir.mktmpdir("puppet_pip") do |dir| - command_and_options = [self.class.quote(command), 'install', "#{@resource[:name]}", '-d', "#{dir}", '-v'] + command_and_options = [self.class.quote(command), 'install', (@resource[:name]).to_s, '-d', dir.to_s, '-v'] command_and_options << install_options if @resource[:install_options] execpipe command_and_options do |process| process.collect do |line| diff --git a/lib/puppet/provider/package/pkg.rb b/lib/puppet/provider/package/pkg.rb index e01607c1760..7dacfcbbff7 100644 --- a/lib/puppet/provider/package/pkg.rb +++ b/lib/puppet/provider/package/pkg.rb @@ -53,7 +53,7 @@ def self.ifo_flag(flags) { :status => 'known' } else raise ArgumentError, _('Unknown format %{resource_name}: %{full_flags}[%{bad_flag}]') % - { resource_name: self.name, full_flags: flags, bad_flag: flags[0..0] } + { resource_name: name, full_flags: flags, bad_flag: flags[0..0] } end ).merge( case flags[1..1] @@ -63,7 +63,7 @@ def self.ifo_flag(flags) {} else raise ArgumentError, _('Unknown format %{resource_name}: %{full_flags}[%{bad_flag}]') % - { resource_name: self.name, full_flags: flags, bad_flag: flags[1..1] } + { resource_name: name, full_flags: flags, bad_flag: flags[1..1] } end ) end @@ -93,7 +93,7 @@ def self.pkg_state(state) when /known/ { :status => 'known' } else - raise ArgumentError, _('Unknown format %{resource_name}: %{state}') % { resource_name: self.name, state: state } + raise ArgumentError, _('Unknown format %{resource_name}: %{state}') % { resource_name: name, state: state } end end @@ -112,8 +112,8 @@ def self.parse_line(line) { :publisher => Regexp.last_match(1), :name => Regexp.last_match(2), :ensure => Regexp.last_match(3) }.merge pkg_state(Regexp.last_match(4)).merge(ufoxi_flag(Regexp.last_match(5))) else - raise ArgumentError, _('Unknown line format %{resource_name}: %{parse_line}') % { resource_name: self.name, parse_line: line } - end).merge({ :provider => self.name }) + raise ArgumentError, _('Unknown line format %{resource_name}: %{parse_line}') % { resource_name: name, parse_line: line } + end).merge({ :provider => name }) end def hold @@ -223,7 +223,7 @@ def latest def install(nofail = false) name = @resource[:name] should = @resource[:ensure] - is = self.query + is = query if is[:ensure].to_sym == :absent command = 'install' else @@ -237,7 +237,7 @@ def install(nofail = false) unless should.is_a? Symbol name += "@#{should}" end - self.unhold if self.properties[:mark] == :hold + unhold if properties[:mark] == :hold begin tries = 1 # pkg install exits with code 7 when the image is currently in use by another process and cannot be modified @@ -252,7 +252,7 @@ def install(nofail = false) r = exec_cmd(command(:pkg), command, *args, name) end ensure - self.hold if @resource[:mark] == :hold + hold if @resource[:mark] == :hold end return r if nofail raise Puppet::Error, _("Unable to update %{package}") % { package: r[:out] } if r[:exit] != 0 @@ -267,11 +267,11 @@ def uninstall cmd << '-r' end cmd << @resource[:name] - self.unhold if self.properties[:mark] == :hold + unhold if properties[:mark] == :hold begin pkg cmd rescue StandardError, LoadError => e - self.hold if self.properties[:mark] == :hold + hold if properties[:mark] == :hold raise e end end diff --git a/lib/puppet/provider/package/pkgdmg.rb b/lib/puppet/provider/package/pkgdmg.rb index 5127a793e77..ec9bfb29f5d 100644 --- a/lib/puppet/provider/package/pkgdmg.rb +++ b/lib/puppet/provider/package/pkgdmg.rb @@ -137,9 +137,9 @@ def self.installpkgdmg(source, name) def query if Puppet::FileSystem.exist?("/var/db/.puppet_pkgdmg_installed_#{@resource[:name]}") Puppet.debug "/var/db/.puppet_pkgdmg_installed_#{@resource[:name]} found" - return { :name => @resource[:name], :ensure => :present } + { :name => @resource[:name], :ensure => :present } else - return nil + nil end end diff --git a/lib/puppet/provider/package/pkgin.rb b/lib/puppet/provider/package/pkgin.rb index f3e1d2408e7..97f50312a57 100644 --- a/lib/puppet/provider/package/pkgin.rb +++ b/lib/puppet/provider/package/pkgin.rb @@ -79,7 +79,7 @@ def latest package = parse_pkgsearch_line.detect { |p| p[:status] == '<' } return properties[:ensure] unless package - return package[:ensure] + package[:ensure] end def update diff --git a/lib/puppet/provider/package/pkgng.rb b/lib/puppet/provider/package/pkgng.rb index a4d24fe5b69..0abc5a12ea4 100644 --- a/lib/puppet/provider/package/pkgng.rb +++ b/lib/puppet/provider/package/pkgng.rb @@ -64,7 +64,7 @@ def self.parse_pkg_query_line(line) def self.instances packages = [] begin - info = self.get_query + info = get_query get_version_list unless info @@ -76,9 +76,9 @@ def self.instances packages << new(hash) end - return packages + packages rescue Puppet::ExecutionFailure - return [] + [] end end diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb index 75aa5dd5090..8ca4809da66 100644 --- a/lib/puppet/provider/package/pkgutil.rb +++ b/lib/puppet/provider/package/pkgutil.rb @@ -105,11 +105,11 @@ def self.parse_pkglist(output, hash = {}) # Single queries may have been for an alias so return the name requested if list.any? list[-1][:name] = hash[:justme] - return list[-1] + list[-1] end else list.reject! { |h| h[:ensure] == :absent } - return list + list end end @@ -140,12 +140,12 @@ def self.pkgsplit(line) end # Use the name method, so it works with subclasses. - hash[:provider] = self.name + hash[:provider] = name - return hash + hash else Puppet.warning _("Cannot match %{line}") % { line: line } - return nil + nil end end diff --git a/lib/puppet/provider/package/portage.rb b/lib/puppet/provider/package/portage.rb index c8e40b20119..b7b273b6187 100644 --- a/lib/puppet/provider/package/portage.rb +++ b/lib/puppet/provider/package/portage.rb @@ -27,21 +27,21 @@ defaultfor 'os.family' => :gentoo def self.instances - result_format = self.eix_result_format - result_fields = self.eix_result_fields - - limit = self.eix_limit - version_format = self.eix_version_format - slot_versions_format = self.eix_slot_versions_format - installed_versions_format = self.eix_installed_versions_format - installable_versions_format = self.eix_install_versions_format + result_format = eix_result_format + result_fields = eix_result_fields + + limit = eix_limit + version_format = eix_version_format + slot_versions_format = eix_slot_versions_format + installed_versions_format = eix_installed_versions_format + installable_versions_format = eix_install_versions_format begin eix_file = File.directory?('/var/cache/eix') ? '/var/cache/eix/portage.eix' : '/var/cache/eix' update_eix unless FileUtils.uptodate?(eix_file, %w[/usr/bin/eix /usr/portage/metadata/timestamp]) search_output = nil Puppet::Util.withenv :EIX_LIMIT => limit, :LASTVERSION => version_format, :LASTSLOTVERSIONS => slot_versions_format, :INSTALLEDVERSIONS => installed_versions_format, :STABLEVERSIONS => installable_versions_format do - search_output = eix(*(self.eix_search_arguments + ['--installed'])) + search_output = eix(*(eix_search_arguments + ['--installed'])) end packages = [] @@ -58,7 +58,7 @@ def self.instances packages << new(package) end - return packages + packages rescue Puppet::ExecutionFailure => detail raise Puppet::Error, detail end @@ -98,17 +98,17 @@ def uninstall end def reinstall - self.install + install end def update - self.install + install end def qatom - output_format = self.qatom_output_format - result_format = self.qatom_result_format - result_fields = self.qatom_result_fields + output_format = qatom_output_format + result_format = qatom_result_format + result_fields = qatom_result_fields @atom ||= begin package_info = {} # do the search @@ -119,7 +119,7 @@ def qatom when true, false, Symbol search = @resource[:name] else - search = '=' + @resource[:name] + '-' + "#{should}" + search = '=' + @resource[:name] + '-' + should.to_s end search_output = qatom_bin(*[search, '--format', output_format]) # verify if the search found anything @@ -179,7 +179,7 @@ def query if @resource[:name] =~ /^@/ if package_sets.include?(@resource[:name][1..].to_s) - return({ :name => "#{@resource[:name]}", :ensure => '9999', :version_available => nil, :installed_versions => nil, :installable_versions => "9999," }) + return({ :name => (@resource[:name]).to_s, :ensure => '9999', :version_available => nil, :installed_versions => nil, :installable_versions => "9999," }) end end @@ -234,7 +234,7 @@ def query end def latest - self.query[:version_available] + query[:version_available] end private @@ -301,7 +301,7 @@ def self.eix_limit end def self.eix_search_arguments - ['--nocolor', '--pure-packages', '--format', self.eix_search_format] + ['--nocolor', '--pure-packages', '--format', eix_search_format] end def install_options diff --git a/lib/puppet/provider/package/portupgrade.rb b/lib/puppet/provider/package/portupgrade.rb index cb4cfeeafe7..763866bd6b5 100644 --- a/lib/puppet/provider/package/portupgrade.rb +++ b/lib/puppet/provider/package/portupgrade.rb @@ -64,7 +64,7 @@ def self.instances # populate the actual :name field from the :portorigin # Set :provider to this object name hash[:name] = hash[:portorigin] - hash[:provider] = self.name + hash[:provider] = name # Add to the full packages listing packages << new(hash) @@ -75,7 +75,7 @@ def self.instances } # return the packages array of hashes - return packages + packages end ######## Installation sub command @@ -97,7 +97,7 @@ def install end # No return code required, so do nil to be clean - return nil + nil end ######## Latest subcommand (returns the latest version available, or current version if installed is latest) @@ -126,24 +126,24 @@ def latest case comparison when "=", ">" Puppet.debug "portupgrade.latest() - Installed package is latest (#{installedversion})" - return installedversion + installedversion when "<" # "portpkg-1.7_5 < needs updating (port has 1.14)" # "portpkg-1.7_5 < needs updating (port has 1.14) (=> 'newport/pkg') if otherdata =~ /\(port has (\S+)\)/ newversion = Regexp.last_match(1) Puppet.debug "portupgrade.latest() - Installed version needs updating to (#{newversion})" - return newversion + newversion else Puppet.debug "portupgrade.latest() - Unable to determine new version from (#{otherdata})" - return installedversion + installedversion end when "?", "!", "#" Puppet.debug "portupgrade.latest() - Comparison Error reported from portversion (#{output})" - return installedversion + installedversion else Puppet.debug "portupgrade.latest() - Unknown code from portversion output (#{output})" - return installedversion + installedversion end elsif output =~ /^\*\* No matching package / @@ -174,17 +174,17 @@ def query if output =~ /^(\S+)-([^-\s]+)/ # Fill in the details hash = Hash.new - hash[:portorigin] = self.name + hash[:portorigin] = name hash[:portname] = Regexp.last_match(1) hash[:ensure] = Regexp.last_match(2) # If more details are required, then we can do another pkg_info # query here and parse out that output and add to the hash # return the hash to the caller - return hash + hash else Puppet.debug "portupgrade.query() - package (#{@resource[:name]}) not installed" - return nil + nil end end diff --git a/lib/puppet/provider/package/puppetserver_gem.rb b/lib/puppet/provider/package/puppetserver_gem.rb index 9958dd33960..1482d2e9993 100644 --- a/lib/puppet/provider/package/puppetserver_gem.rb +++ b/lib/puppet/provider/package/puppetserver_gem.rb @@ -74,9 +74,9 @@ def self.gemlist(options) .map { |set| gemsplit(set) } if options[:justme] - return gem_list.shift + gem_list.shift else - return gem_list + gem_list end end @@ -106,7 +106,7 @@ def install(useversion = true) raise Puppet::Error, _('puppet:// URLs are not supported as gem sources') else # interpret it as a gem repository - command_options << '--source' << "#{resource[:source]}" << resource[:name] + command_options << '--source' << resource[:source].to_s << resource[:name] end else command_options << resource[:name] diff --git a/lib/puppet/provider/package/rpm.rb b/lib/puppet/provider/package/rpm.rb index 33b1b8a8ea8..6065f72983d 100644 --- a/lib/puppet/provider/package/rpm.rb +++ b/lib/puppet/provider/package/rpm.rb @@ -85,7 +85,7 @@ def query # NOTE: Prior to a fix for issue 1243, this method potentially returned a cached value # IF YOU CALL THIS METHOD, IT WILL CALL RPM # Use get(:property) to check if cached values are available - cmd = ["-q", @resource[:name], "#{self.class.nosignature}", "#{self.class.nodigest}", "--qf", "#{self.class::NEVRA_FORMAT}"] + cmd = ["-q", @resource[:name], self.class.nosignature.to_s, self.class.nodigest.to_s, "--qf", self.class::NEVRA_FORMAT.to_s] begin output = rpm(*cmd) @@ -114,7 +114,7 @@ def latest @resource.fail _("RPMs must specify a package source") end - cmd = [command(:rpm), "-q", "--qf", "#{self.class::NEVRA_FORMAT}", "-p", source] + cmd = [command(:rpm), "-q", "--qf", self.class::NEVRA_FORMAT.to_s, "-p", source] h = self.class.nevra_to_multiversion_hash(execute(cmd)) h[:ensure] rescue Puppet::ExecutionFailure => e @@ -175,7 +175,7 @@ def uninstall end def update - self.install + install end def install_options @@ -209,14 +209,14 @@ def self.nevra_to_hash(line) match = self::NEVRA_REGEX.match(line) if match self::NEVRA_FIELDS.zip(match.captures) { |f, v| hash[f] = v } - hash[:provider] = self.name + hash[:provider] = name hash[:ensure] = "#{hash[:version]}-#{hash[:release]}" hash[:ensure].prepend("#{hash[:epoch]}:") if hash[:epoch] != '0' else Puppet.debug("Failed to match rpm line #{line}") end - return hash + hash end # @param line [String] multiple lines of rpm package query information @@ -227,7 +227,7 @@ def self.nevra_to_multiversion_hash(multiline) list = [] multiversion_hash = {} multiline.each_line do |line| - hash = self.nevra_to_hash(line) + hash = nevra_to_hash(line) next if hash.empty? if multiversion_hash.empty? @@ -250,6 +250,6 @@ def self.nevra_to_multiversion_hash(multiline) return list[0] end - return list + list end end diff --git a/lib/puppet/provider/package/rug.rb b/lib/puppet/provider/package/rug.rb index ac666718f15..fed8816b1cd 100644 --- a/lib/puppet/provider/package/rug.rb +++ b/lib/puppet/provider/package/rug.rb @@ -12,7 +12,7 @@ # Install a package using 'rug'. def install should = @resource.should(:ensure) - self.debug "Ensuring => #{should}" + debug "Ensuring => #{should}" wanted = @resource[:name] # XXX: We don't actually deal with epochs here. @@ -25,8 +25,8 @@ def install end rug "--quiet", :install, "-y", wanted - unless self.query - raise Puppet::ExecutionFailure, _("Could not find package %{name}") % { name: self.name } + unless query + raise Puppet::ExecutionFailure, _("Could not find package %{name}") % { name: name } end end @@ -36,16 +36,16 @@ def latest output = rug "list-updates" if output =~ /#{Regexp.escape @resource[:name]}\s*\|\s*([^\s|]+)/ - return Regexp.last_match(1) + Regexp.last_match(1) else # rug didn't find updates, pretend the current # version is the latest - return @property_hash[:ensure] + @property_hash[:ensure] end end def update # rug install can be used for update, too - self.install + install end end diff --git a/lib/puppet/provider/package/sun.rb b/lib/puppet/provider/package/sun.rb index 6a3b0d67e83..f2d20393fea 100644 --- a/lib/puppet/provider/package/sun.rb +++ b/lib/puppet/provider/package/sun.rb @@ -81,7 +81,7 @@ def info2hash(device = nil) # so even though pkginfo passed, we have to check the actual output raise Puppet::Error, _("Unable to get information about package %{name} because of: %{errmsg}") % { name: @resource[:name], errmsg: errmsg } rescue Puppet::ExecutionFailure - return { :ensure => :absent } + { :ensure => :absent } end end @@ -115,8 +115,8 @@ def uninstall # Remove the old package, and install the new one. This will probably # often fail. def update - self.uninstall if (@property_hash[:ensure] || info2hash[:ensure]) != :absent - self.install + uninstall if (@property_hash[:ensure] || info2hash[:ensure]) != :absent + install end def prepare_cmd(opt) diff --git a/lib/puppet/provider/package/up2date.rb b/lib/puppet/provider/package/up2date.rb index bc7a719ef6d..69d5fca0a40 100644 --- a/lib/puppet/provider/package/up2date.rb +++ b/lib/puppet/provider/package/up2date.rb @@ -14,8 +14,8 @@ def install up2date "-u", @resource[:name] - unless self.query - raise Puppet::ExecutionFailure, _("Could not find package %{name}") % { name: self.name } + unless query + raise Puppet::ExecutionFailure, _("Could not find package %{name}") % { name: name } end end @@ -25,16 +25,16 @@ def latest output = up2date "--showall" if output =~ /^#{Regexp.escape @resource[:name]}-(\d+.*)\.\w+/ - return Regexp.last_match(1) + Regexp.last_match(1) else # up2date didn't find updates, pretend the current # version is the latest - return @property_hash[:ensure] + @property_hash[:ensure] end end def update # Install in up2date can be used for update, too - self.install + install end end diff --git a/lib/puppet/provider/package/urpmi.rb b/lib/puppet/provider/package/urpmi.rb index bcb8db1e20a..cb1a88c3228 100644 --- a/lib/puppet/provider/package/urpmi.rb +++ b/lib/puppet/provider/package/urpmi.rb @@ -10,7 +10,7 @@ def install should = @resource.should(:ensure) - self.debug "Ensuring => #{should}" + debug "Ensuring => #{should}" wanted = @resource[:name] # XXX: We don't actually deal with epochs here. @@ -24,8 +24,8 @@ def install urpmi "--auto", wanted - unless self.query - raise Puppet::Error, _("Package %{name} was not present after trying to install it") % { name: self.name } + unless query + raise Puppet::Error, _("Package %{name} was not present after trying to install it") % { name: name } end end @@ -34,17 +34,17 @@ def latest output = urpmq "-S", @resource[:name] if output =~ /^#{Regexp.escape @resource[:name]}\s+:\s+.*\(\s+(\S+)\s+\)/ - return Regexp.last_match(1) + Regexp.last_match(1) else # urpmi didn't find updates, pretend the current # version is the latest - return @resource[:ensure] + @resource[:ensure] end end def update # Install in urpmi can be used for update, too - self.install + install end # For normal package removal the urpmi provider will delegate to the RPM diff --git a/lib/puppet/provider/package/windows/exe_package.rb b/lib/puppet/provider/package/windows/exe_package.rb index ef56a9800af..b927b8480f9 100644 --- a/lib/puppet/provider/package/windows/exe_package.rb +++ b/lib/puppet/provider/package/windows/exe_package.rb @@ -80,7 +80,7 @@ def self.install_command(resource) rescue => detail raise Puppet::Error.new(_("Error when installing %{package}: %{detail}") % { package: resource[:name], detail: detail.message }, detail) ensure - self.register(tempfile.path) + register(tempfile.path) tempfile.close() file_location = tempfile.path end diff --git a/lib/puppet/provider/package/yum.rb b/lib/puppet/provider/package/yum.rb index 3d44e44c07c..7b2b206514c 100644 --- a/lib/puppet/provider/package/yum.rb +++ b/lib/puppet/provider/package/yum.rb @@ -124,9 +124,9 @@ def self.check_updates(disablerepo, enablerepo, disableexcludes) when 100 updates = parse_updates(output) when 0 - self.debug "#{command(:cmd)} check-update exited with 0; no package updates available." + debug "#{command(:cmd)} check-update exited with 0; no package updates available." else - self.warning _("Could not check for updates, '%{cmd} check-update' exited with %{status}") % { cmd: command(:cmd), status: output.exitstatus } + warning _("Could not check for updates, '%{cmd} check-update' exited with %{status}") % { cmd: command(:cmd), status: output.exitstatus } end updates end @@ -251,17 +251,17 @@ def install end should = @resource.should(:ensure) - self.debug "Ensuring => #{should}" + debug "Ensuring => #{should}" operation = :install case should when :latest - current_package = self.query + current_package = query if current_package && !current_package[:ensure].to_s.empty? operation = update_command - self.debug "Ensuring latest, so using #{operation}" + debug "Ensuring latest, so using #{operation}" else - self.debug "Ensuring latest, but package is absent, so using install" + debug "Ensuring latest, but package is absent, so using install" operation = :install end should = nil @@ -270,7 +270,7 @@ def install # version feed it to yum directly if @resource[:source] wanted = @resource[:source] - self.debug "Installing directly from #{wanted}" + debug "Installing directly from #{wanted}" end should = nil when false, :absent @@ -282,26 +282,26 @@ def install # version, and also supplying the path to a package that supplies that # version. wanted = @resource[:source] - self.debug "Installing directly from #{wanted}" + debug "Installing directly from #{wanted}" else # No explicit source was specified, so add the package version should = best_version(should) wanted += "-#{should}" if wanted.scan(self.class::ARCH_REGEX) - self.debug "Detected Arch argument in package! - Moving arch to end of version string" + debug "Detected Arch argument in package! - Moving arch to end of version string" wanted.gsub!(/(.+)(#{self.class::ARCH_REGEX})(.+)/, '\1\3\2') end end - current_package = self.query + current_package = query if current_package if @resource[:install_only] - self.debug "Updating package #{@resource[:name]} from version #{current_package[:ensure]} to #{should} as install_only packages are never downgraded" + debug "Updating package #{@resource[:name]} from version #{current_package[:ensure]} to #{should} as install_only packages are never downgraded" operation = update_command elsif rpm_compare_evr(should, current_package[:ensure]) < 0 - self.debug "Downgrading package #{@resource[:name]} from version #{current_package[:ensure]} to #{should}" + debug "Downgrading package #{@resource[:name]} from version #{current_package[:ensure]} to #{should}" operation = :downgrade elsif rpm_compare_evr(should, current_package[:ensure]) > 0 - self.debug "Upgrading package #{@resource[:name]} from version #{current_package[:ensure]} to #{should}" + debug "Upgrading package #{@resource[:name]} from version #{current_package[:ensure]} to #{should}" operation = update_command end end @@ -319,8 +319,8 @@ def install # If a version was specified, query again to see if it is a matching version if should - is = self.query - raise Puppet::Error, _("Could not find package %{name}") % { name: self.name } unless is + is = query + raise Puppet::Error, _("Could not find package %{name}") % { name: name } unless is version = is[:ensure] # FIXME: Should we raise an exception even if should == :latest @@ -336,20 +336,20 @@ def latest unless upd.nil? # FIXME: there could be more than one update for a package # because of multiarch - return "#{upd[:epoch]}:#{upd[:version]}-#{upd[:release]}" + "#{upd[:epoch]}:#{upd[:version]}-#{upd[:release]}" else # Yum didn't find updates, pretend the current version is the latest - self.debug "Yum didn't find updates, current version (#{properties[:ensure]}) is the latest" + debug "Yum didn't find updates, current version (#{properties[:ensure]}) is the latest" version = properties[:ensure] raise Puppet::DevError, _("Tried to get latest on a missing package") if version == :absent || version == :purged - return version + version end end def update # Install in yum can be used for update, too - self.install + install end def purge diff --git a/lib/puppet/provider/package/zypper.rb b/lib/puppet/provider/package/zypper.rb index 91f8ef91b8a..f5690d31c8b 100644 --- a/lib/puppet/provider/package/zypper.rb +++ b/lib/puppet/provider/package/zypper.rb @@ -92,7 +92,7 @@ def best_version(should) # Install a package using 'zypper'. def install should = @resource.should(:ensure) - self.debug "Ensuring => #{should}" + debug "Ensuring => #{should}" wanted = @resource[:name] # XXX: We don't actually deal with epochs here. @@ -113,7 +113,7 @@ def install # extract version numbers and convert to integers major, minor, patch = zypper_version.scan(/\d+/).map { |x| x.to_i } - self.debug "Detected zypper version #{major}.#{minor}.#{patch}" + debug "Detected zypper version #{major}.#{minor}.#{patch}" # zypper version < 1.0 does not support --quiet flag if major < 1 @@ -144,22 +144,22 @@ def install zypper(*options) - unless self.query - raise Puppet::ExecutionFailure, _("Could not find package %{name}") % { name: self.name } + unless query + raise Puppet::ExecutionFailure, _("Could not find package %{name}") % { name: name } end end # What's the latest package version available? def latest - return self.class.latest_package_version(@resource[:name]) || - # zypper didn't find updates, pretend the current - # version is the latest - @property_hash[:ensure] + self.class.latest_package_version(@resource[:name]) || + # zypper didn't find updates, pretend the current + # version is the latest + @property_hash[:ensure] end def update # zypper install can be used for update, too - self.install + install end def uninstall diff --git a/lib/puppet/provider/package_targetable.rb b/lib/puppet/provider/package_targetable.rb index 452a3cdf7ac..4b9892a11a8 100644 --- a/lib/puppet/provider/package_targetable.rb +++ b/lib/puppet/provider/package_targetable.rb @@ -34,7 +34,7 @@ def self.prefetch(packages) catalog_packages.each do |catalog_package| if catalog_package[:name] == instance.name && catalog_package.original_parameters[:command] == command catalog_package.provider = instance - self.debug "Prefetched instance: %{name} via command: %{cmd}" % { name: instance.name, cmd: command || :default } + debug "Prefetched instance: %{name} via command: %{cmd}" % { name: instance.name, cmd: command || :default } end end end diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index ef55400f7e9..09e9dfa6093 100644 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -282,7 +282,7 @@ def self.prefetch_target(target) begin target_records = retrieve(target) unless target_records - raise Puppet::DevError, _("Prefetching %{target} for provider %{name} returned nil") % { target: target, name: self.name } + raise Puppet::DevError, _("Prefetching %{target} for provider %{name} returned nil") % { target: target, name: name } end rescue Puppet::Util::FileType::FileReadError => detail if @raise_prefetch_errors @@ -292,7 +292,7 @@ def self.prefetch_target(target) @failed_prefetch_targets[target] = detail.to_s else puts detail.backtrace if Puppet[:trace] - Puppet.err _("Could not prefetch %{resource} provider '%{name}' target '%{target}': %{detail}. Treating as empty") % { resource: self.resource_type.name, name: self.name, target: target, detail: detail } + Puppet.err _("Could not prefetch %{resource} provider '%{name}' target '%{target}': %{detail}. Treating as empty") % { resource: resource_type.name, name: name, target: target, detail: detail } end target_records = [] @@ -306,7 +306,7 @@ def self.prefetch_target(target) target_records = prefetch_hook(target_records) if respond_to?(:prefetch_hook) - raise Puppet::DevError, _("Prefetching %{target} for provider %{name} returned nil") % { target: target, name: self.name } unless target_records + raise Puppet::DevError, _("Prefetching %{target} for provider %{name} returned nil") % { target: target, name: name } unless target_records target_records end @@ -325,13 +325,13 @@ def self.retrieve(path) text = target_object(path).read if text.nil? or text == "" # there is no file - return [] + [] else # Set the target, for logging. old = @target begin @target = path - return self.parse(text) + parse(text) rescue Puppet::Error => detail detail.file = @target if detail.respond_to?(:file=) raise detail @@ -380,9 +380,9 @@ def self.target_records(target) def self.targets(resources = nil) targets = [] # First get the default target - raise Puppet::DevError, _("Parsed Providers must define a default target") unless self.default_target + raise Puppet::DevError, _("Parsed Providers must define a default target") unless default_target - targets << self.default_target + targets << default_target # Then get each of the file objects targets += @target_objects.keys diff --git a/lib/puppet/provider/service/base.rb b/lib/puppet/provider/service/base.rb index 546067549bc..796e1135369 100644 --- a/lib/puppet/provider/service/base.rb +++ b/lib/puppet/provider/service/base.rb @@ -35,7 +35,7 @@ def getpid regex = Regexp.new(@resource[:pattern]) ps = getps - self.debug "Executing '#{ps}'" + debug "Executing '#{ps}'" table = Puppet::Util::Execution.execute(ps) # The output of the PS command can be a mashup of several different @@ -53,7 +53,7 @@ def getpid table.each_line { |line| next unless regex.match(line) - self.debug "Process matched: #{line}" + debug "Process matched: #{line}" ary = line.sub(/^[[:space:]]+/u, '').split(/[[:space:]]+/u) return ary[1] } @@ -74,17 +74,17 @@ def status # Explicitly calling exitstatus to facilitate testing if status.exitstatus == 0 - return :running + :running else - return :stopped + :stopped end else pid = getpid if pid - self.debug "PID is #{pid}" - return :running + debug "PID is #{pid}" + :running else - return :stopped + :stopped end end end @@ -102,12 +102,7 @@ def start # The command used to start. Generated if the 'binary' argument # is passed. def startcmd - if @resource[:binary] - return @resource[:binary] - else - raise Puppet::Error, - "Services must specify a start command or a binary" - end + @resource[:binary] || raise(Puppet::Error, "Services must specify a start command or a binary") end # Stop the service. If a 'stop' parameter is specified, it @@ -122,15 +117,15 @@ def stop else pid = getpid unless pid - self.info _("%{name} is not running") % { name: self.name } + info _("%{name} is not running") % { name: name } return false end begin output = kill pid rescue Puppet::ExecutionFailure - @resource.fail Puppet::Error, "Could not kill #{self.name}, PID #{pid}: #{output}", $! + @resource.fail Puppet::Error, "Could not kill #{name}, PID #{pid}: #{output}", $! end - return true + true end end diff --git a/lib/puppet/provider/service/bsd.rb b/lib/puppet/provider/service/bsd.rb index d9ba6a8b17c..58581a0bc42 100644 --- a/lib/puppet/provider/service/bsd.rb +++ b/lib/puppet/provider/service/bsd.rb @@ -44,10 +44,10 @@ def enable # Override stop/start commands to use one's and the avoid race condition # where provider tries to stop/start the service before it is enabled def startcmd - [self.initscript, :onestart] + [initscript, :onestart] end def stopcmd - [self.initscript, :onestop] + [initscript, :onestop] end end diff --git a/lib/puppet/provider/service/daemontools.rb b/lib/puppet/provider/service/daemontools.rb index 57b8357a564..046ce959a7d 100644 --- a/lib/puppet/provider/service/daemontools.rb +++ b/lib/puppet/provider/service/daemontools.rb @@ -60,9 +60,9 @@ def defpath # returns all providers for all existing services in @defpath # ie enabled or not def self.instances - path = self.defpath + path = defpath unless path - Puppet.info("#{self.name} is unsuitable because service directory is nil") + Puppet.info("#{name} is unsuitable because service directory is nil") return end unless FileTest.directory?(path) @@ -82,7 +82,7 @@ def self.instances # returns the daemon dir on this node def self.daemondir - self.defpath + defpath end # find the service dir on this node @@ -102,7 +102,7 @@ def servicedir # returns the full path of this service when enabled # (ie in the service directory) def service - File.join(self.servicedir, resource[:name]) + File.join(servicedir, resource[:name]) end # returns the full path to the current daemon directory @@ -117,7 +117,7 @@ def daemon def status begin - output = svstat self.service + output = svstat service if output =~ /:\s+up \(/ return :running end @@ -131,66 +131,66 @@ def setupservice if resource[:manifest] Puppet.notice "Configuring #{resource[:name]}" command = [resource[:manifest], resource[:name]] - system("#{command}") + system(command.to_s) end rescue Puppet::ExecutionFailure => detail - raise Puppet::Error.new("Cannot config #{self.service} to enable it: #{detail}", detail) + raise Puppet::Error.new("Cannot config #{service} to enable it: #{detail}", detail) end def enabled? - case self.status + case status when :running # obviously if the daemon is running then it is enabled - return :true + :true else # the service is enabled if it is linked - return Puppet::FileSystem.symlink?(self.service) ? :true : :false + Puppet::FileSystem.symlink?(service) ? :true : :false end end def enable - unless FileTest.directory?(self.daemon) + unless FileTest.directory?(daemon) Puppet.notice "No daemon dir, calling setupservice for #{resource[:name]}" - self.setupservice + setupservice end - if self.daemon - unless Puppet::FileSystem.symlink?(self.service) - Puppet.notice "Enabling #{self.service}: linking #{self.daemon} -> #{self.service}" - Puppet::FileSystem.symlink(self.daemon, self.service) + if daemon + unless Puppet::FileSystem.symlink?(service) + Puppet.notice "Enabling #{service}: linking #{daemon} -> #{service}" + Puppet::FileSystem.symlink(daemon, service) end end rescue Puppet::ExecutionFailure - raise Puppet::Error.new("No daemon directory found for #{self.service}", $!) + raise Puppet::Error.new("No daemon directory found for #{service}", $!) end def disable begin - unless FileTest.directory?(self.daemon) + unless FileTest.directory?(daemon) Puppet.notice "No daemon dir, calling setupservice for #{resource[:name]}" - self.setupservice + setupservice end - if self.daemon - if Puppet::FileSystem.symlink?(self.service) - Puppet.notice "Disabling #{self.service}: removing link #{self.daemon} -> #{self.service}" - Puppet::FileSystem.unlink(self.service) + if daemon + if Puppet::FileSystem.symlink?(service) + Puppet.notice "Disabling #{service}: removing link #{daemon} -> #{service}" + Puppet::FileSystem.unlink(service) end end rescue Puppet::ExecutionFailure - raise Puppet::Error.new("No daemon directory found for #{self.service}", $!) + raise Puppet::Error.new("No daemon directory found for #{service}", $!) end - self.stop + stop end def restart - svc "-t", self.service + svc "-t", service end def start enable unless enabled? == :true - svc "-u", self.service + svc "-u", service end def stop - svc "-d", self.service + svc "-d", service end end diff --git a/lib/puppet/provider/service/debian.rb b/lib/puppet/provider/service/debian.rb index d9466904115..013f41c6dc8 100644 --- a/lib/puppet/provider/service/debian.rb +++ b/lib/puppet/provider/service/debian.rb @@ -42,7 +42,7 @@ def enabled? # 106 is the exit status when the policy layer supplies a fallback action # See x-man-page://invoke-rc.d if [104, 106].include?(status.exitstatus) - return :true + :true elsif [101, 105].include?(status.exitstatus) # 101 is action not allowed, which means we have to do the check manually. # 105 is unknown, which generally means the initscript does not support query @@ -50,12 +50,12 @@ def enabled? # For those that do not, perform the checks manually # http://www.debian.org/doc/debian-policy/ch-opersys.html if get_start_link_count >= 4 - return :true + :true else - return :false + :false end else - return :false + :false end end diff --git a/lib/puppet/provider/service/freebsd.rb b/lib/puppet/provider/service/freebsd.rb index f0d1642e64a..ae4e91bfdde 100644 --- a/lib/puppet/provider/service/freebsd.rb +++ b/lib/puppet/provider/service/freebsd.rb @@ -21,7 +21,7 @@ def error(msg) # Executing an init script with the 'rcvar' argument returns # the service name, rcvar name and whether it's enabled/disabled def rcvar - rcvar = execute([self.initscript, :rcvar], :failonfail => true, :combine => false, :squelch => false) + rcvar = execute([initscript, :rcvar], :failonfail => true, :combine => false, :squelch => false) rcvar = rcvar.split("\n") rcvar.delete_if { |str| str =~ /^#\s*$/ } rcvar[1] = rcvar[1].gsub(/^\$/, '') @@ -30,11 +30,11 @@ def rcvar # Extract value name from service or rcvar def extract_value_name(name, rc_index, regex, regex_index) - value_name = self.rcvar[rc_index] - self.error("No #{name} name found in rcvar") if value_name.nil? + value_name = rcvar[rc_index] + error("No #{name} name found in rcvar") if value_name.nil? value_name = value_name.gsub!(regex, regex_index) - self.error("#{name} name is empty") if value_name.nil? - self.debug("#{name} name is #{value_name}") + error("#{name} name is empty") if value_name.nil? + debug("#{name} name is #{value_name}") value_name end @@ -50,20 +50,20 @@ def rcvar_name # Extract rcvar value def rcvar_value - value = self.rcvar[1] - self.error("No rcvar value found in rcvar") if value.nil? + value = rcvar[1] + error("No rcvar value found in rcvar") if value.nil? value = value.gsub!(/(.*)(_enable)?="?(\w+)"?/, '\3') - self.error("rcvar value is empty") if value.nil? - self.debug("rcvar value is #{value}") + error("rcvar value is empty") if value.nil? + debug("rcvar value is #{value}") value end # Edit rc files and set the service to yes/no def rc_edit(yesno) - service = self.service_name - rcvar = self.rcvar_name - self.debug("Editing rc files: setting #{rcvar} to #{yesno} for #{service}") - self.rc_add(service, rcvar, yesno) unless self.rc_replace(service, rcvar, yesno) + service = service_name + rcvar = rcvar_name + debug("Editing rc files: setting #{rcvar} to #{yesno} for #{service}") + rc_add(service, rcvar, yesno) unless rc_replace(service, rcvar, yesno) end # Try to find an existing setting in the rc files @@ -78,7 +78,7 @@ def rc_replace(service, rcvar, yesno) next unless s.gsub!(/^(#{rcvar}(_enable)?)="?(YES|NO)"?/, "\\1=\"#{yesno}\"") Puppet::FileSystem.replace_file(filename) { |f| f << s } - self.debug("Replaced in #{filename}") + debug("Replaced in #{filename}") success = true end success @@ -91,51 +91,51 @@ def rc_add(service, rcvar, yesno) if Puppet::FileSystem.exist?(rcconf_dir) File.open(rcconf_dir + "/#{service}", File::WRONLY | File::APPEND | File::CREAT, 0o644) { |f| f << append - self.debug("Appended to #{f.path}") + debug("Appended to #{f.path}") } elsif Puppet::FileSystem.exist?(rcconf_local) # Else, check the local rc file first, but don't create it File.open(rcconf_local, File::WRONLY | File::APPEND) { |f| f << append - self.debug("Appended to #{f.path}") + debug("Appended to #{f.path}") } else # At last use the standard rc.conf file File.open(rcconf, File::WRONLY | File::APPEND | File::CREAT, 0o644) { |f| f << append - self.debug("Appended to #{f.path}") + debug("Appended to #{f.path}") } end end def enabled? - if /YES$/ =~ self.rcvar_value - self.debug("Is enabled") + if /YES$/ =~ rcvar_value + debug("Is enabled") return :true end - self.debug("Is disabled") + debug("Is disabled") :false end def enable - self.debug("Enabling") - self.rc_edit("YES") + debug("Enabling") + rc_edit("YES") end def disable - self.debug("Disabling") - self.rc_edit("NO") + debug("Disabling") + rc_edit("NO") end def startcmd - [self.initscript, :onestart] + [initscript, :onestart] end def stopcmd - [self.initscript, :onestop] + [initscript, :onestop] end def statuscmd - [self.initscript, :onestatus] + [initscript, :onestatus] end end diff --git a/lib/puppet/provider/service/gentoo.rb b/lib/puppet/provider/service/gentoo.rb index 77a1390034b..c787484eafa 100644 --- a/lib/puppet/provider/service/gentoo.rb +++ b/lib/puppet/provider/service/gentoo.rb @@ -17,7 +17,7 @@ def disable output = update :del, @resource[:name], :default rescue Puppet::ExecutionFailure - raise Puppet::Error, "Could not disable #{self.name}: #{output}", $!.backtrace + raise Puppet::Error, "Could not disable #{name}: #{output}", $!.backtrace end def enabled? @@ -33,15 +33,15 @@ def enabled? # If it's enabled then it will print output showing service | runlevel if output =~ /^\s*#{@resource[:name]}\s*\|\s*(boot|default)/ - return :true + :true else - return :false + :false end end def enable output = update :add, @resource[:name], :default rescue Puppet::ExecutionFailure - raise Puppet::Error, "Could not enable #{self.name}: #{output}", $!.backtrace + raise Puppet::Error, "Could not enable #{name}: #{output}", $!.backtrace end end diff --git a/lib/puppet/provider/service/init.rb b/lib/puppet/provider/service/init.rb index 65efef13a4a..5929f52a636 100644 --- a/lib/puppet/provider/service/init.rb +++ b/lib/puppet/provider/service/init.rb @@ -76,10 +76,10 @@ def self.excludes # List all services of this type. def self.instances - get_services(self.defpath) + get_services(defpath) end - def self.get_services(defpath, exclude = self.excludes) + def self.get_services(defpath, exclude = excludes) defpath = [defpath] unless defpath.is_a? Array instances = [] defpath.each do |path| @@ -118,7 +118,7 @@ def hasstatus=(value) # Where is our init script? def initscript - @initscript ||= self.search(@resource[:name]) + @initscript ||= search(@resource[:name]) end def paths @@ -127,9 +127,9 @@ def paths true else if Puppet::FileSystem.exist?(path) - self.debug "Search path #{path} is not a directory" + debug "Search path #{path} is not a directory" else - self.debug "Search path #{path} does not exist" + debug "Search path #{path} does not exist" end false end @@ -142,7 +142,7 @@ def search(name) if Puppet::FileSystem.exist? fqname return fqname else - self.debug("Could not find #{name} in #{path}") + debug("Could not find #{name} in #{path}") end end @@ -151,7 +151,7 @@ def search(name) if Puppet::FileSystem.exist? fqname_sh return fqname_sh else - self.debug("Could not find #{name}.sh in #{path}") + debug("Could not find #{name}.sh in #{path}") end end raise Puppet::Error, "Could not find init script for '#{name}'" diff --git a/lib/puppet/provider/service/launchd.rb b/lib/puppet/provider/service/launchd.rb index be8c83d2b4d..7a40868cea7 100644 --- a/lib/puppet/provider/service/launchd.rb +++ b/lib/puppet/provider/service/launchd.rb @@ -84,7 +84,7 @@ def self.get_os_version # # @api private def self.launchd_overrides - if self.get_os_version < 14 + if get_os_version < 14 "/var/db/launchd.db/com.apple.launchd/overrides.plist" else "/var/db/com.apple.xpc.launchd/disabled.plist" @@ -107,8 +107,8 @@ def self.prefetch(resources) # containing the name, provider, path, and status of each service on the # system. def self.instances - jobs = self.jobsearch - @job_list ||= self.job_list + jobs = jobsearch + @job_list ||= job_list jobs.keys.collect do |job| job_status = @job_list.has_key?(job) ? :running : :stopped new(:name => job, :provider => :launchd, :path => jobs[job], :status => job_status) @@ -165,12 +165,12 @@ def self.jobsearch(label = nil) if label if by_label.has_key? label - return { label => by_label[label] } + { label => by_label[label] } else # try refreshing the map, in case a plist has been added in the interim by_label = make_label_to_path_map(true) if by_label.has_key? label - return { label => by_label[label] } + { label => by_label[label] } else raise Puppet::Error, "Unable to find launchd plist for job: #{label}" end @@ -248,7 +248,7 @@ def plist_from_label(label) # status mechanism and fall back to the base provider status method. def status if @resource && ((@resource[:hasstatus] == :false) || (@resource[:status])) - return super + super elsif @property_hash[:status].nil? # property_hash was flushed so the service changed status service_name = @resource[:name] @@ -281,7 +281,7 @@ def start # always add -w so it always starts the job, it is a noop if it is not needed, this means we do # not have to rescan all launchd plists. cmds << "-w" - if self.enabled? == :false || self.status == :stopped # launchctl won't load disabled jobs + if enabled? == :false || status == :stopped # launchctl won't load disabled jobs did_enable_job = true end cmds << job_path @@ -291,7 +291,7 @@ def start raise Puppet::Error.new("Unable to start service: #{resource[:name]} at path: #{job_path}", $!) end # As load -w clears the Disabled flag, we need to add it in after - self.disable if did_enable_job and resource[:enable] == :false + disable if did_enable_job and resource[:enable] == :false end def stop @@ -303,7 +303,7 @@ def stop did_disable_job = false cmds = [] cmds << :launchctl << :unload - if self.enabled? == :true # keepalive jobs can't be stopped without disabling + if enabled? == :true # keepalive jobs can't be stopped without disabling cmds << "-w" did_disable_job = true end @@ -314,15 +314,15 @@ def stop raise Puppet::Error.new("Unable to stop service: #{resource[:name]} at path: #{job_path}", $!) end # As unload -w sets the Disabled flag, we need to add it in after - self.enable if did_disable_job and resource[:enable] == :true + enable if did_disable_job and resource[:enable] == :true end def restart Puppet.debug("A restart has been triggered for the #{resource[:name]} service") Puppet.debug("Stopping the #{resource[:name]} service") - self.stop + stop Puppet.debug("Starting the #{resource[:name]} service") - self.start + start end # launchd jobs are enabled by default. They are only disabled if the key diff --git a/lib/puppet/provider/service/openbsd.rb b/lib/puppet/provider/service/openbsd.rb index 83e105fc4c6..616b61ccc66 100644 --- a/lib/puppet/provider/service/openbsd.rb +++ b/lib/puppet/provider/service/openbsd.rb @@ -47,7 +47,7 @@ def self.instances end instances rescue Puppet::ExecutionFailure - return nil + nil end end @@ -56,16 +56,16 @@ def enabled? :failonfail => false, :combine => false, :squelch => false) if output.exitstatus == 1 - self.debug("Is disabled") - return :false + debug("Is disabled") + :false else - self.debug("Is enabled") - return :true + debug("Is enabled") + :true end end def enable - self.debug("Enabling") + debug("Enabling") rcctl(:enable, @resource[:name]) if @resource[:flags] rcctl(:set, @resource[:name], :flags, @resource[:flags]) @@ -73,14 +73,14 @@ def enable end def disable - self.debug("Disabling") + debug("Disabling") rcctl(:disable, @resource[:name]) end def running? output = execute([command(:rcctl), "check", @resource[:name]], :failonfail => false, :combine => false, :squelch => false).chomp - return true if output =~ /\(ok\)/ + true if output =~ /\(ok\)/ end # Uses the wrapper to prevent failure when the service is not running; @@ -88,12 +88,12 @@ def running? def flags output = execute([command(:rcctl), "get", @resource[:name], "flags"], :failonfail => false, :combine => false, :squelch => false).chomp - self.debug("Flags are: \"#{output}\"") + debug("Flags are: \"#{output}\"") output end def flags=(value) - self.debug("Changing flags from #{flags} to #{value}") + debug("Changing flags from #{flags} to #{value}") rcctl(:set, @resource[:name], :flags, value) # If the service is already running, force a restart as the flags have been changed. rcctl(:restart, @resource[:name]) if running? diff --git a/lib/puppet/provider/service/openwrt.rb b/lib/puppet/provider/service/openwrt.rb index f1396dbd639..ce73a137479 100644 --- a/lib/puppet/provider/service/openwrt.rb +++ b/lib/puppet/provider/service/openwrt.rb @@ -18,16 +18,16 @@ def self.defpath end def enable - system(self.initscript, 'enable') + system(initscript, 'enable') end def disable - system(self.initscript, 'disable') + system(initscript, 'disable') end def enabled? # We can't define the "command" for the init script, so we call system? - system(self.initscript, 'enabled') ? (return :true) : (return :false) + system(initscript, 'enabled') ? (return :true) : (return :false) end # Purposely leave blank so we fail back to ps based status detection diff --git a/lib/puppet/provider/service/redhat.rb b/lib/puppet/provider/service/redhat.rb index f660cf8f730..535c13a2fe7 100644 --- a/lib/puppet/provider/service/redhat.rb +++ b/lib/puppet/provider/service/redhat.rb @@ -23,7 +23,7 @@ def disable # and --del removes the service from chkconfig management chkconfig("--level", "0123456", @resource[:name], :off) rescue Puppet::ExecutionFailure => detail - raise Puppet::Error, "Could not disable #{self.name}: #{detail}", detail.backtrace + raise Puppet::Error, "Could not disable #{name}: #{detail}", detail.backtrace end def enabled? @@ -49,7 +49,7 @@ def enable chkconfig("--add", @resource[:name]) chkconfig(@resource[:name], :on) rescue Puppet::ExecutionFailure => detail - raise Puppet::Error, "Could not enable #{self.name}: #{detail}", detail.backtrace + raise Puppet::Error, "Could not enable #{name}: #{detail}", detail.backtrace end def initscript diff --git a/lib/puppet/provider/service/runit.rb b/lib/puppet/provider/service/runit.rb index 236fc6289fe..9bd820df3d2 100644 --- a/lib/puppet/provider/service/runit.rb +++ b/lib/puppet/provider/service/runit.rb @@ -65,7 +65,7 @@ def servicedir def status begin - output = sv "status", self.daemon + output = sv "status", daemon return :running if output =~ /^run: / rescue Puppet::ExecutionFailure => detail unless detail.message =~ /(warning: |runsv not running$)/ @@ -76,7 +76,7 @@ def status end def stop - sv "stop", self.service + sv "stop", service end def start @@ -86,14 +86,14 @@ def start # runsvdir takes up to 5 seconds to recognize # the symlink created by this call to enable # TRANSLATORS 'runsvdir' is a linux service name and should not be translated - Puppet.info _("Waiting 5 seconds for runsvdir to discover service %{service}") % { service: self.service } + Puppet.info _("Waiting 5 seconds for runsvdir to discover service %{service}") % { service: service } sleep 5 end - sv "start", self.service + sv "start", service end def restart - sv "restart", self.service + sv "restart", service end # disable by removing the symlink so that runit @@ -102,6 +102,6 @@ def restart # before a disable def disable # unlink the daemon symlink to disable it - Puppet::FileSystem.unlink(self.service) if Puppet::FileSystem.symlink?(self.service) + Puppet::FileSystem.unlink(service) if Puppet::FileSystem.symlink?(service) end end diff --git a/lib/puppet/provider/service/service.rb b/lib/puppet/provider/service/service.rb index 72409e9911b..45ae40025c9 100644 --- a/lib/puppet/provider/service/service.rb +++ b/lib/puppet/provider/service/service.rb @@ -13,8 +13,8 @@ def restart service_command(:restart) nil else - self.stop - self.start + stop + start end end diff --git a/lib/puppet/provider/service/smf.rb b/lib/puppet/provider/service/smf.rb index 2090b160ec3..1d03f0607d5 100644 --- a/lib/puppet/provider/service/smf.rb +++ b/lib/puppet/provider/service/smf.rb @@ -63,7 +63,7 @@ def initialize(*args) end def service_exists? - self.service_fmri + service_fmri true rescue Puppet::ExecutionFailure false @@ -71,7 +71,7 @@ def service_exists? def setup_service return unless @resource[:manifest] - return if self.service_exists? + return if service_exists? Puppet.notice("Importing #{@resource[:manifest]} for #{@resource[:name]}") svccfg(:import, @resource[:manifest]) @@ -132,7 +132,7 @@ def enable def enabled? return :false unless service_exists? - _property, _type, value = svccfg("-s", self.service_fmri, "listprop", "general/enabled").split(' ') + _property, _type, value = svccfg("-s", service_fmri, "listprop", "general/enabled").split(' ') value == 'true' ? :true : :false end @@ -142,10 +142,10 @@ def disable def restartcmd if Puppet::Util::Package.versioncmp(Puppet.runtime[:facter].value('os.release.full'), '11.2') >= 0 - [command(:adm), :restart, "-s", self.service_fmri] + [command(:adm), :restart, "-s", service_fmri] else # Synchronous restart only supported in Solaris 11.2 and above - [command(:adm), :restart, self.service_fmri] + [command(:adm), :restart, service_fmri] end end @@ -153,7 +153,7 @@ def service_states # Gets the current and next state of the service. We have a next state because SMF # manages services asynchronously. If there is no 'next' state, svcs will put a '-' # to indicate as such. - current_state, next_state = svcs("-H", "-o", "state,nstate", self.service_fmri).chomp.split(' ') + current_state, next_state = svcs("-H", "-o", "state,nstate", service_fmri).chomp.split(' ') { :current => current_state, @@ -168,7 +168,7 @@ def service_states def wait(*desired_states) Timeout.timeout(60) do loop do - states = self.service_states + states = service_states break if desired_states.include?(states[:current]) && states[:next].nil? Kernel.sleep(1) @@ -189,7 +189,7 @@ def stop def restart # Wait for the service to actually start before returning. super - self.wait('online') + wait('online') end def status @@ -206,29 +206,29 @@ def status # Get the current state and the next state. If there is a next state, # use that for the state comparison. - states = self.service_states + states = service_states state = states[:next] || states[:current] rescue Puppet::ExecutionFailure # TODO (PUP-8957): Should this be set back to INFO ? - debug "Could not get status on service #{self.name} #{$!}" + debug "Could not get status on service #{name} #{$!}" return :stopped end case state when "online" - return :running + :running when "offline", "disabled", "uninitialized" - return :stopped + :stopped when "maintenance" - return :maintenance + :maintenance when "degraded" - return :degraded + :degraded when "legacy_run" raise Puppet::Error, "Cannot manage legacy services through SMF" else raise Puppet::Error, - "Unmanageable state '#{state}' on service #{self.name}" + "Unmanageable state '#{state}' on service #{name}" end end @@ -238,8 +238,8 @@ def status def maybe_clear_service_then_svcadm(cur_state, subcmd, flags) # If the cur_state is maint or degraded, then we need to clear the service # before we enable or disable it. - adm('clear', self.service_fmri) if [:maintenance, :degraded].include?(cur_state) - adm(subcmd, flags, self.service_fmri) + adm('clear', service_fmri) if [:maintenance, :degraded].include?(cur_state) + adm(subcmd, flags, service_fmri) end # The flush method is necessary for the SMF provider because syncing the enable and ensure @@ -259,13 +259,13 @@ def flush # simplifies the code. For a nonexistent service, one of enable or ensure will be true # here (since we're syncing them), so we can fail early if setup_service fails. setup_service - fmri = self.service_fmri + fmri = service_fmri # Useful constants for operations involving multiple states stopped = ['offline', 'disabled', 'uninitialized'] # Get the current state of the service. - cur_state = self.status + cur_state = status if enable_.nil? # Only ensure needs to be syncd. The -t flag tells svcadm to temporarily @@ -273,10 +273,10 @@ def flush # reboot. This is exactly what we want, because we do not want to touch # the enable property. if ensure_ == :stopped - self.maybe_clear_service_then_svcadm(cur_state, 'disable', '-st') + maybe_clear_service_then_svcadm(cur_state, 'disable', '-st') wait(*stopped) else # ensure == :running - self.maybe_clear_service_then_svcadm(cur_state, 'enable', '-rst') + maybe_clear_service_then_svcadm(cur_state, 'enable', '-rst') wait('online') end @@ -300,9 +300,9 @@ def flush final_state = :running if final_state == :degraded if enable_ - self.maybe_clear_service_then_svcadm(cur_state, 'enable', '-rs') + maybe_clear_service_then_svcadm(cur_state, 'enable', '-rs') else - self.maybe_clear_service_then_svcadm(cur_state, 'disable', '-s') + maybe_clear_service_then_svcadm(cur_state, 'disable', '-s') end # We're safe with 'whens' here since self.status already errors on any diff --git a/lib/puppet/provider/service/src.rb b/lib/puppet/provider/service/src.rb index b044a55a9f2..60c090b884e 100644 --- a/lib/puppet/provider/service/src.rb +++ b/lib/puppet/provider/service/src.rb @@ -84,12 +84,12 @@ def wait(desired_state) def start super - self.wait(:running) + wait(:running) end def stop super - self.wait(:stopped) + wait(:stopped) end def restart @@ -111,8 +111,8 @@ def restart if do_refresh == :true execute([command(:refresh), "-s", @resource[:name]]) else - self.stop - self.start + stop + start end return :true rescue Puppet::ExecutionFailure => detail @@ -141,7 +141,7 @@ def status return state end rescue Puppet::ExecutionFailure => detail - self.debug(detail.message) - return :stopped + debug(detail.message) + :stopped end end diff --git a/lib/puppet/provider/service/systemd.rb b/lib/puppet/provider/service/systemd.rb index 3e15770d97a..932bf6dd927 100644 --- a/lib/puppet/provider/service/systemd.rb +++ b/lib/puppet/provider/service/systemd.rb @@ -39,9 +39,9 @@ def self.instances Puppet.debug("#{m[0]} marked as bad by `systemctl`. It is recommended to be further checked.") if m[1] == "bad" i << new(:name => m[0]) end - return i + i rescue Puppet::ExecutionFailure - return [] + [] end # Static services cannot be enabled or disabled manually. Indirect services @@ -55,11 +55,11 @@ def enabled_insync?(current) current == @resource[:enable] else Puppet.debug("Unable to enable or disable static service #{@resource[:name]}") - return true + true end when 'indirect' Puppet.debug("Service #{@resource[:name]} is in 'indirect' state and cannot be enabled/disabled") - return true + true else current == @resource[:enable] end @@ -73,7 +73,7 @@ def enabled_insync?(current) def systemctl_change_enable(action) output = systemctl(action, '--', @resource[:name]) rescue - raise Puppet::Error, "Could not #{action} #{self.name}: #{output}", $!.backtrace + raise Puppet::Error, "Could not #{action} #{name}: #{output}", $!.backtrace ensure @cached_enabled = nil end @@ -122,7 +122,7 @@ def enabled? return ret if ret end - return :false + :false end # This method is required for Debian systems due to the way the SysVInit-Systemd @@ -133,7 +133,7 @@ def enabled? def debian_enabled? status = execute(["/usr/sbin/invoke-rc.d", "--quiet", "--query", @resource[:name], "start"], :failonfail => false) if [104, 106].include?(status.exitstatus) - return :true + :true elsif [101, 105].include?(status.exitstatus) # 101 is action not allowed, which means we have to do the check manually. # 105 is unknown, which generally means the initscript does not support query @@ -141,12 +141,12 @@ def debian_enabled? # For those that do not, perform the checks manually # http://www.debian.org/doc/debian-policy/ch-opersys.html if get_start_link_count >= 4 - return :true + :true else - return :false + :false end else - return :false + :false end end @@ -166,7 +166,7 @@ def daemon_reload? end def enable - self.unmask + unmask systemctl_change_enable(:enable) end @@ -189,7 +189,7 @@ def restartcmd end def startcmd - self.unmask + unmask [command(:systemctl), "start", '--', @resource[:name]] end diff --git a/lib/puppet/provider/service/upstart.rb b/lib/puppet/provider/service/upstart.rb index 6222dfe4b5f..39597b3544c 100644 --- a/lib/puppet/provider/service/upstart.rb +++ b/lib/puppet/provider/service/upstart.rb @@ -54,7 +54,7 @@ def self.has_initctl? has_feature :enableable def self.instances - self.get_services(self.excludes) # Take exclude list from init provider + get_services(excludes) # Take exclude list from init provider end def self.excludes @@ -117,7 +117,7 @@ def search(name) return fqname end - self.debug("Could not find #{name}#{suffix} in #{path}") + debug("Could not find #{name}#{suffix} in #{path}") end end @@ -186,9 +186,9 @@ def status output = status_exec(@resource[:name].split) if output =~ %r{start/} - return :running + :running else - return :stopped + :stopped end end @@ -213,9 +213,9 @@ def version_is_post_0_9_0 def enabled_pre_0_6_7?(script_text) # Upstart version < 0.6.7 means no manual stanza. if script_text.match(START_ON) - return :true + :true else - return :false + :false end end diff --git a/lib/puppet/provider/user/aix.rb b/lib/puppet/provider/user/aix.rb index 43eb9f6ba6e..287f32bd06f 100644 --- a/lib/puppet/provider/user/aix.rb +++ b/lib/puppet/provider/user/aix.rb @@ -75,7 +75,7 @@ def expires_to_expiry(provider, expires) month = match_obj[1] day = match_obj[2] year = match_obj[-1] - return "20#{year}-#{month}-#{day}" + "20#{year}-#{month}-#{day}" end # We do some validation before-hand to ensure the value's an Array, diff --git a/lib/puppet/provider/user/directoryservice.rb b/lib/puppet/provider/user/directoryservice.rb index 76f2d9e3367..006083fa1e4 100644 --- a/lib/puppet/provider/user/directoryservice.rb +++ b/lib/puppet/provider/user/directoryservice.rb @@ -87,7 +87,7 @@ def self.prefetch(resources) # display its output. def self.instances get_all_users.collect do |user| - self.new(generate_attribute_hash(user)) + new(generate_attribute_hash(user)) end end diff --git a/lib/puppet/provider/user/hpux.rb b/lib/puppet/provider/user/hpux.rb index 6d982e30c7f..ff3358a321a 100644 --- a/lib/puppet/provider/user/hpux.rb +++ b/lib/puppet/provider/user/hpux.rb @@ -40,7 +40,7 @@ def modifycmd(param, value) cmd << "/usr/lbin/modprpw" cmd << "-v" cmd << "-l" - cmd << "#{resource.name}" + cmd << resource.name.to_s end cmd end @@ -76,7 +76,7 @@ def password debug "No trusted computing user file #{file_name} found." end else - return ent.passwd + ent.passwd end end @@ -84,11 +84,7 @@ def trusted # Check to see if the HP-UX box is running in trusted compute mode # UID for root should always be 0 trusted_sys = exec_getprpw('root', '-m uid') - if trusted_sys.chomp == "uid=0" - return true - else - return false - end + trusted_sys.chomp == "uid=0" end def exec_getprpw(user, opts) diff --git a/lib/puppet/provider/user/pw.rb b/lib/puppet/provider/user/pw.rb index 3685d5945f8..3fb5e04e99a 100644 --- a/lib/puppet/provider/user/pw.rb +++ b/lib/puppet/provider/user/pw.rb @@ -96,7 +96,7 @@ def has_sensitive_data?(property = nil) # Get expiry from system and convert to Puppet-style date def expiry - expiry = self.get(:expiry) + expiry = get(:expiry) expiry = :absent if expiry == 0 if expiry != :absent diff --git a/lib/puppet/provider/user/useradd.rb b/lib/puppet/provider/user/useradd.rb index 8cf8cfde222..ee349f2a444 100644 --- a/lib/puppet/provider/user/useradd.rb +++ b/lib/puppet/provider/user/useradd.rb @@ -401,7 +401,7 @@ def create end super if @resource.forcelocal? - set(:groups, @resource[:groups]) if self.groups? + set(:groups, @resource[:groups]) if groups? set(:expiry, @resource[:expiry]) if @resource[:expiry] end set(:password, @resource[:password]) if @resource[:password] diff --git a/lib/puppet/provider/user/windows_adsi.rb b/lib/puppet/provider/user/windows_adsi.rb index 3b985fca0c3..07424eb7d85 100644 --- a/lib/puppet/provider/user/windows_adsi.rb +++ b/lib/puppet/provider/user/windows_adsi.rb @@ -81,7 +81,7 @@ def groups_to_s(groups) resource.debug("#{sid.domain}\\#{account} (#{sid.sid})") "#{sid.domain}\\#{account}" end - return groups.join(',') + groups.join(',') end def create diff --git a/lib/puppet/relationship.rb b/lib/puppet/relationship.rb index 4c7bb40a3a3..be3cc93a51c 100644 --- a/lib/puppet/relationship.rb +++ b/lib/puppet/relationship.rb @@ -48,11 +48,9 @@ def initialize(source, target, options = {}) # of :NONE comes from. def match?(event) if self.event.nil? or event == :NONE or self.event == :NONE - return false - elsif self.event == :ALL_EVENTS or event == self.event - return true + false else - return false + self.event == :ALL_EVENTS or event == self.event end end diff --git a/lib/puppet/reports.rb b/lib/puppet/reports.rb index e9b50da0124..24240b951fb 100644 --- a/lib/puppet/reports.rb +++ b/lib/puppet/reports.rb @@ -77,7 +77,7 @@ def self.reportdocs # Use this method so they all get loaded instance_loader(:report).loadall(Puppet.lookup(:current_environment)) loaded_instances(:report).sort_by(&:to_s).each do |name| - mod = self.report(name) + mod = report(name) docs << "#{name}\n#{"-" * name.to_s.length}\n" docs << Puppet::Util::Docs.scrub(mod.doc) << "\n\n" diff --git a/lib/puppet/reports/http.rb b/lib/puppet/reports/http.rb index cce417225b3..27fcc6af753 100644 --- a/lib/puppet/reports/http.rb +++ b/lib/puppet/reports/http.rb @@ -36,7 +36,7 @@ def process end client = Puppet.runtime[:http] - client.post(url, self.to_yaml, headers: headers, options: options) do |response| + client.post(url, to_yaml, headers: headers, options: options) do |response| unless response.success? Puppet.err _("Unable to submit report to %{url} [%{code}] %{message}") % { url: Puppet[:reporturl].to_s, code: response.code, message: response.reason } end diff --git a/lib/puppet/reports/log.rb b/lib/puppet/reports/log.rb index 3b680ae6546..c5fa7ae1338 100644 --- a/lib/puppet/reports/log.rb +++ b/lib/puppet/reports/log.rb @@ -7,8 +7,8 @@ the log destination is syslog." def process - self.logs.each do |log| - log.source = "//#{self.host}/#{log.source}" + logs.each do |log| + log.source = "//#{host}/#{log.source}" Puppet::Util::Log.newmessage(log) end end diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index e94285efa97..3e907a61137 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -44,7 +44,7 @@ class Puppet::Resource VALUE_KEY = 'value' def self.from_data_hash(data) - resource = self.allocate + resource = allocate resource.initialize_from_hash(data) resource end @@ -116,7 +116,7 @@ def to_data_hash converter = stringify ? Puppet::Pops::Serialization::ToStringifiedConverter.new : nil params = {} - self.to_hash.each_pair do |param, value| + to_hash.each_pair do |param, value| # Don't duplicate the title as the namevar unless param == namevar && value == title if stringify @@ -162,7 +162,7 @@ def self.value_to_json_data(value) end def yaml_property_munge(x) - self.value.to_json_data(x) + value.to_json_data(x) end # Proxy these methods to the parameters hash. It's likely they'll @@ -187,7 +187,7 @@ def [](param) end def ==(other) - return false unless other.respond_to?(:title) and self.type == other.type and self.title == other.title + return false unless other.respond_to?(:title) and type == other.type and title == other.title return false unless to_hash == other.to_hash @@ -229,7 +229,7 @@ def include?(parameter) %w[exported virtual strict].each do |m| define_method(m + "?") do - self.send(m) + send(m) end end @@ -275,7 +275,7 @@ def initialize(type, title = nil, attributes = EMPTY_HASH) self.kind = src.kind self.exported = src.exported self.virtual = src.virtual - self.set_tags(src) + set_tags(src) self.environment = src.environment @rstype = src.resource_type @type = src.type @@ -343,7 +343,7 @@ def initialize(type, title = nil, attributes = EMPTY_HASH) self.kind = self.class.to_kind(rt) unless kind if strict? && rt.nil? - if self.class? + if class? raise ArgumentError, _("Could not find declared class %{title}") % { title: title } else raise ArgumentError, _("Invalid resource type %{type}") % { type: type } @@ -428,7 +428,7 @@ def to_s def uniqueness_key # Temporary kludge to deal with inconsistent use patterns; ensure we don't return nil for namevar/:name - h = self.to_hash + h = to_hash name = h[namevar] || h[:name] || self.name h[namevar] ||= name h[:name] ||= name @@ -460,7 +460,7 @@ def to_hierayaml }.join # rubocop:enable Lint/FormatParameterMismatch - " %s:\n%s" % [self.title, attributes] + " %s:\n%s" % [title, attributes] end # Convert our resource to a hiera hash suitable for serialization. @@ -475,7 +475,7 @@ def to_hiera_hash res['ensure'] = value if value res.merge!(params.sort.to_h) - return { h['title'] => res } + { h['title'] => res } end # Convert our resource to Puppet code. @@ -497,8 +497,8 @@ def to_manifest }.join # rubocop:enable Lint/FormatParameterMismatch - escaped = self.title.gsub(/'/, "\\\\'") - "%s { '%s':\n%s}" % [self.type.to_s.downcase, escaped, attributes] + escaped = title.gsub(/'/, "\\\\'") + "%s { '%s':\n%s}" % [type.to_s.downcase, escaped, attributes] end def to_ref @@ -513,15 +513,15 @@ def to_ref # must check its kind before deciding whether the catalog format is of an older # version or not. def to_ral - if self.kind == COMPILABLE_TYPE_STRING - typeklass = Puppet::Type.type(self.type) - elsif self.catalog && self.catalog.catalog_format >= 2 + if kind == COMPILABLE_TYPE_STRING + typeklass = Puppet::Type.type(type) + elsif catalog && catalog.catalog_format >= 2 typeklass = Puppet::Type.type(:component) else - typeklass = Puppet::Type.type(self.type) || Puppet::Type.type(:component) + typeklass = Puppet::Type.type(type) || Puppet::Type.type(:component) end - raise(Puppet::Error, "Resource type '#{self.type}' was not found") unless typeklass + raise(Puppet::Error, "Resource type '#{type}' was not found") unless typeklass typeklass.new(self) end @@ -671,7 +671,7 @@ def parse_title # resource should fail here. raise Puppet::Error, _("No set of title patterns matched the title \"%{title}\".") % { title: title } else - return { :name => title.to_s } + { :name => title.to_s } end end end diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb index 4909a593844..12cc6e72b53 100644 --- a/lib/puppet/resource/catalog.rb +++ b/lib/puppet/resource/catalog.rb @@ -93,7 +93,7 @@ def title_key_for_ref(ref) else a = [nil, nil] end - return a + a end def add_resource_before(other, *resources) @@ -539,7 +539,7 @@ def write_resource_file to_print = resources.filter_map do |resource| next unless resource.managed? - "#{resource.ref.downcase}" + resource.ref.downcase.to_s end f.puts to_print.join("\n") end @@ -590,14 +590,14 @@ def fail_on_duplicate_type_and_title(resource, title_key) # This pretty much just converts all of the resources from one class to another, using # a conversion method. def to_catalog(convert) - result = self.class.new(self.name, self.environment_instance) + result = self.class.new(name, environment_instance) - result.version = self.version - result.code_id = self.code_id - result.catalog_uuid = self.catalog_uuid - result.catalog_format = self.catalog_format - result.metadata = self.metadata - result.recursive_metadata = self.recursive_metadata + result.version = version + result.code_id = code_id + result.catalog_uuid = catalog_uuid + result.catalog_format = catalog_format + result.metadata = metadata + result.recursive_metadata = recursive_metadata map = {} resources.each do |resource| @@ -643,7 +643,7 @@ def to_catalog(convert) map.clear - result.add_class(*self.classes) + result.add_class(*classes) result.merge_tags_from(self) result diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb index b80be7656b2..08cfde9c0b1 100644 --- a/lib/puppet/resource/status.rb +++ b/lib/puppet/resource/status.rb @@ -102,7 +102,7 @@ def dependency_failed? end def self.from_data_hash(data) - obj = self.allocate + obj = allocate obj.initialize_from_hash(data) obj end @@ -216,7 +216,7 @@ def to_data_hash 'tags' => @tags.to_a, 'time' => @time.iso8601(9), 'failed' => @failed, - 'failed_to_restart' => self.failed_to_restart?, + 'failed_to_restart' => failed_to_restart?, 'changed' => @changed, 'out_of_sync' => @out_of_sync, 'skipped' => @skipped, diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index 1f2a471276c..4129ef4e5de 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -47,7 +47,7 @@ class Puppet::Resource::Type attr_reader :type RESOURCE_KINDS.each do |t| - define_method("#{t}?") { self.type == t } + define_method("#{t}?") { type == t } end # Are we a child of the passed class? Do a recursive search up our @@ -56,7 +56,7 @@ def child_of?(klass) return true if override return false unless parent - return(klass == parent_type ? true : parent_type.child_of?(klass)) + (klass == parent_type ? true : parent_type.child_of?(klass)) end # Now evaluate the code associated with this class or definition. @@ -140,7 +140,7 @@ def merge(other) # This might just be an empty, stub class. return unless other.code - unless self.code + unless code self.code = other.code return end @@ -237,7 +237,7 @@ def set_resource_parameters(resource, scope) scope[TITLE] = resource.title scope[NAME] = resource.name end - scope.class_set(self.name, scope) if hostclass? || node? + scope.class_set(name, scope) if hostclass? || node? param_hash = scope.with_parameter_scope(resource.to_s, arguments.keys) do |param_scope| # Assign directly to the parameter scope to avoid scope parameter validation at this point. It @@ -376,7 +376,7 @@ def namesplit(fullname) ary = fullname.split(DOUBLE_COLON) n = ary.pop || "" ns = ary.join(DOUBLE_COLON) - return ns, n + [ns, n] end def parent_scope(scope, klass) @@ -401,9 +401,9 @@ def warn_if_metaparam(param, default) return unless Puppet::Type.metaparamclass(param) if default - warnonce _("%{param} is a metaparam; this value will inherit to all contained resources in the %{name} definition") % { param: param, name: self.name } + warnonce _("%{param} is a metaparam; this value will inherit to all contained resources in the %{name} definition") % { param: param, name: name } else - raise Puppet::ParseError, _("%{param} is a metaparameter; please choose another parameter name in the %{name} definition") % { param: param, name: self.name } + raise Puppet::ParseError, _("%{param} is a metaparameter; please choose another parameter name in the %{name} definition") % { param: param, name: name } end end diff --git a/lib/puppet/settings.rb b/lib/puppet/settings.rb index b9ef2a95af1..f1b48bc3753 100644 --- a/lib/puppet/settings.rb +++ b/lib/puppet/settings.rb @@ -220,7 +220,7 @@ def override_default(param, value) # understand, and add them to the passed option list. def addargs(options) # Add all of the settings as valid options. - self.each { |_name, setting| + each { |_name, setting| setting.getopt_args.each { |args| options << args } } @@ -231,7 +231,7 @@ def addargs(options) # understand, and add them to the passed option list. def optparse_addargs(options) # Add all of the settings as valid options. - self.each { |_name, setting| + each { |_name, setting| options << setting.optparse_args } @@ -344,7 +344,7 @@ def parse_global_options(args) option_parser.ignore_invalid_options = true # Add all global options to it. - self.optparse_addargs([]).each do |option| + optparse_addargs([]).each do |option| option_parser.on(*option) do |arg| opt, val = Puppet::Settings.clean_opt(option[0], arg) handlearg(opt, val) @@ -429,7 +429,7 @@ def create_ancestors(dir) def call_hooks_deferred_to_application_initialization(options = {}) @hooks_to_call_on_application_initialization.each do |setting| - setting.handle(self.value(setting.name)) + setting.handle(value(setting.name)) rescue InterpolationError => err raise InterpolationError, err.message, err.backtrace unless options[:ignore_interpolation_dependency_errors] # swallow. We're not concerned if we can't call hooks because dependencies don't exist yet @@ -620,7 +620,7 @@ def parse_config(text, file = "text") # Determine our environment, if we have one. if @config[:environment] - env = self.value(:environment).to_sym + env = value(:environment).to_sym else env = NONE end @@ -679,15 +679,15 @@ def parse_config_files(require_config = true) def main_config_file if explicit_config_file? - return self[:config] + self[:config] else - return File.join(Puppet::Util::RunMode[:server].conf_dir, config_file_name) + File.join(Puppet::Util::RunMode[:server].conf_dir, config_file_name) end end private :main_config_file def user_config_file - return File.join(Puppet::Util::RunMode[:user].conf_dir, config_file_name) + File.join(Puppet::Util::RunMode[:user].conf_dir, config_file_name) end private :user_config_file @@ -706,7 +706,7 @@ def config_file_name # This just means that the setting wasn't explicitly set on the command line, so we will ignore it and # fall through to the default name. end - return self.class.default_config_file_name + self.class.default_config_file_name end private :config_file_name @@ -790,7 +790,7 @@ def newsetting(hash) # Iterate across all of the objects in a given section. def persection(section) section = section.to_sym - self.each { |_name, obj| + each { |_name, obj| if obj.section == section yield obj end @@ -838,7 +838,7 @@ def reuse new = @used @used = [] - self.use(*new) + use(*new) end class SearchPathElement < Struct.new(:name, :type); end @@ -1056,7 +1056,7 @@ def define_settings(section, defs) end call.each do |setting| - setting.handle(self.value(setting.name)) + setting.handle(value(setting.name)) end end @@ -1109,7 +1109,7 @@ def to_config end end - return str + str end # Convert to a parseable manifest @@ -1247,9 +1247,9 @@ def value_sym(param, environment = nil, bypass_interpolation = false) # in {https://projects.puppetlabs.com/issues/16637 #16637} def which_configuration_file if explicit_config_file? or Puppet.features.root? then - return main_config_file + main_config_file else - return user_config_file + user_config_file end end @@ -1379,7 +1379,7 @@ def value_sets_for(environment, mode) # Read the file in. # @api private def read_file(file) - return Puppet::FileSystem.read(file, :encoding => 'utf-8') + Puppet::FileSystem.read(file, :encoding => 'utf-8') end # Private method for internal test use only; allows to do a comprehensive clear of all settings between tests. @@ -1407,12 +1407,12 @@ def explicit_config_file? # get an exception. # - return true if self[:config] + true if self[:config] rescue InterpolationError # This means we failed to interpolate, which means that they didn't # explicitly specify either :config or :confdir... so we'll fall out to # the default value. - return false + false end private :explicit_config_file? @@ -1583,7 +1583,7 @@ def set(name, value) end def inspect - %Q(<#{self.class}:#{self.object_id} @name="#{@name}" @values="#{@values}">) + %Q(<#{self.class}:#{object_id} @name="#{@name}" @values="#{@values}">) end end @@ -1607,7 +1607,7 @@ def lookup(name) end def inspect - %Q(<#{self.class}:#{self.object_id} @name="#{@name}" @section="#{@section}">) + %Q(<#{self.class}:#{object_id} @name="#{@name}" @section="#{@section}">) end end @@ -1644,7 +1644,7 @@ def conf end def inspect - %Q(<#{self.class}:#{self.object_id} @environment_name="#{@environment_name}" @conf="#{@conf}">) + %Q(<#{self.class}:#{object_id} @environment_name="#{@environment_name}" @conf="#{@conf}">) end end end diff --git a/lib/puppet/settings/base_setting.rb b/lib/puppet/settings/base_setting.rb index e509db51bae..ebbdf09df7c 100644 --- a/lib/puppet/settings/base_setting.rb +++ b/lib/puppet/settings/base_setting.rb @@ -107,15 +107,15 @@ def initialize(args = {}) args.each do |param, value| method = param.to_s + "=" - unless self.respond_to? method + unless respond_to? method raise ArgumentError, _("%{class_name} (setting '%{setting}') does not accept %{parameter}") % { class_name: self.class, setting: args[:name], parameter: param } end - self.send(method, value) + send(method, value) end - unless self.desc - raise ArgumentError, _("You must provide a description for the %{class_name} config option") % { class_name: self.name } + unless desc + raise ArgumentError, _("You must provide a description for the %{class_name} config option") % { class_name: name } end end @@ -146,7 +146,7 @@ def default(check_application_defaults_first = false) end return default_value unless check_application_defaults_first - return @settings.value(name, :application_defaults, true) || default_value + @settings.value(name, :application_defaults, true) || default_value end # Convert the object to a config statement. @@ -161,7 +161,7 @@ def to_config # If the value has not been overridden, then print it out commented # and unconverted, so it's clear that that's the default and how it # works. - value = @settings.value(self.name) + value = @settings.value(name) if value != @default line = "#{@name} = #{value}" @@ -180,7 +180,7 @@ def to_config # @return [String] Retrieves the value, or if it's not set, retrieves the default. # @api public def value(bypass_interpolation = false) - @settings.value(self.name, nil, bypass_interpolation) + @settings.value(name, nil, bypass_interpolation) end # Modify the value when it is first evaluated @@ -223,6 +223,6 @@ def allowed_on_commandline? end def inspect - %Q(<#{self.class}:#{self.object_id} @name="#{@name}" @section="#{@section}" @default="#{@default}" @call_hook="#{@call_hook}">) + %Q(<#{self.class}:#{object_id} @name="#{@name}" @section="#{@section}" @default="#{@default}" @call_hook="#{@call_hook}">) end end diff --git a/lib/puppet/settings/boolean_setting.rb b/lib/puppet/settings/boolean_setting.rb index 34a6e2429d6..16ff8326846 100644 --- a/lib/puppet/settings/boolean_setting.rb +++ b/lib/puppet/settings/boolean_setting.rb @@ -21,8 +21,8 @@ def optparse_args def munge(value) case value - when true, "true"; return true - when false, "false"; return false + when true, "true"; true + when false, "false"; false else raise Puppet::Settings::ValidationError, _("Invalid value '%{value}' for boolean parameter: %{name}") % { value: value.inspect, name: @name } end diff --git a/lib/puppet/settings/environment_conf.rb b/lib/puppet/settings/environment_conf.rb index 49ee488941d..5814f91174a 100644 --- a/lib/puppet/settings/environment_conf.rb +++ b/lib/puppet/settings/environment_conf.rb @@ -161,7 +161,7 @@ def self.validate(path_to_conf_file, config) valid = false end - return valid + valid end private_class_method :validate diff --git a/lib/puppet/settings/file_or_directory_setting.rb b/lib/puppet/settings/file_or_directory_setting.rb index 9c7edc971d6..37ec0f582a7 100644 --- a/lib/puppet/settings/file_or_directory_setting.rb +++ b/lib/puppet/settings/file_or_directory_setting.rb @@ -2,7 +2,7 @@ class Puppet::Settings::FileOrDirectorySetting < Puppet::Settings::FileSetting def type - if Puppet::FileSystem.directory?(self.value) || @path_ends_with_slash + if Puppet::FileSystem.directory?(value) || @path_ends_with_slash :directory else :file diff --git a/lib/puppet/settings/file_setting.rb b/lib/puppet/settings/file_setting.rb index 37a9b992f4a..bf19600dfb0 100644 --- a/lib/puppet/settings/file_setting.rb +++ b/lib/puppet/settings/file_setting.rb @@ -126,7 +126,7 @@ def to_resource type = self.type return nil unless type - path = self.value + path = value return nil unless path.is_a?(String) @@ -139,7 +139,7 @@ def to_resource resource = Puppet::Resource.new(:file, path) if Puppet[:manage_internal_file_permissions] - if self.mode + if mode # This ends up mimicking the munge method of the mode # parameter to make sure that we're always passing the string # version of the octal number. If we were setting the @@ -156,8 +156,8 @@ def to_resource # REMIND fails on Windows because chown/chgrp functionality not supported yet if Puppet.features.root? and !Puppet::Util::Platform.windows? - resource[:owner] = self.owner if self.owner - resource[:group] = self.group if self.group + resource[:owner] = owner if owner + resource[:group] = group if group end end @@ -166,7 +166,7 @@ def to_resource resource[:links] = :follow resource[:backup] = false - resource.tag(self.section, self.name, "settings") + resource.tag(section, name, "settings") resource end @@ -216,13 +216,13 @@ def controlled_access(&block) Puppet::Util::SUIDManager.asuser(*chown) do # Update the umask to make non-executable files Puppet::Util.withumask(File.umask ^ 0o111) do - yielded_value = case self.mode + yielded_value = case mode when String - self.mode.to_i(8) + mode.to_i(8) when NilClass 0o640 else - self.mode + mode end yield yielded_value diff --git a/lib/puppet/settings/ini_file.rb b/lib/puppet/settings/ini_file.rb index 65d6baa662d..c8b0fde72c5 100644 --- a/lib/puppet/settings/ini_file.rb +++ b/lib/puppet/settings/ini_file.rb @@ -195,7 +195,7 @@ def write(fh) end def ==(other) - super(other) && self.line_number == other.line_number + super(other) && line_number == other.line_number end end diff --git a/lib/puppet/settings/value_translator.rb b/lib/puppet/settings/value_translator.rb index 1c2533bff55..4d74e6d38ac 100644 --- a/lib/puppet/settings/value_translator.rb +++ b/lib/puppet/settings/value_translator.rb @@ -4,13 +4,13 @@ class Puppet::Settings::ValueTranslator def [](value) # Handle different data types correctly - return case value - when /^false$/i; false - when /^true$/i; true - when true; true - when false; false - else - value.gsub(/^["']|["']$/, '').sub(/\s+$/, '') - end + case value + when /^false$/i; false + when /^true$/i; true + when true; true + when false; false + else + value.gsub(/^["']|["']$/, '').sub(/\s+$/, '') + end end end diff --git a/lib/puppet/ssl/certificate_request_attributes.rb b/lib/puppet/ssl/certificate_request_attributes.rb index 5346f8f25b1..eafecde511b 100644 --- a/lib/puppet/ssl/certificate_request_attributes.rb +++ b/lib/puppet/ssl/certificate_request_attributes.rb @@ -35,6 +35,6 @@ def load return true end - return false + false end end diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 57b5484b6b4..4becb2795ef 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -394,7 +394,7 @@ def add_resource_status(status) # Is the resource currently scheduled? def scheduled?(resource) - self.ignoreschedules || resource_harness.scheduled?(resource) + ignoreschedules || resource_harness.scheduled?(resource) end # Should this resource be skipped? diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index 8367f6b4d6a..7893db862b0 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -19,7 +19,7 @@ class Puppet::Transaction::Event EVENT_STATUSES = %w[noop success failure audit] def self.from_data_hash(data) - obj = self.allocate + obj = allocate obj.initialize_from_hash(data) obj end diff --git a/lib/puppet/transaction/event_manager.rb b/lib/puppet/transaction/event_manager.rb index 5528950c16a..49706857dda 100644 --- a/lib/puppet/transaction/event_manager.rb +++ b/lib/puppet/transaction/event_manager.rb @@ -155,14 +155,14 @@ def process_callback(resource, callback, events) add_callback_status_event(resource, callback, message, "success") end - return true + true rescue => detail resource_error_message = _("Failed to call %{callback}: %{detail}") % { callback: callback, detail: detail } resource.err(resource_error_message) transaction.resource_status(resource).failed_to_restart = true transaction.resource_status(resource).fail_with_event(resource_error_message) resource.log_exception(detail) - return false + false end def add_callback_status_event(resource, callback, message, status) diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 4d90e1fca21..4ef546445e0 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -144,7 +144,7 @@ class Puppet::Transaction::Report TOTAL = "total" def self.from_data_hash(data) - obj = self.allocate + obj = allocate obj.initialize_from_hash(data) obj end diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 2494ea12490..e6797599b51 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -103,7 +103,7 @@ def <=>(other) return nil unless other.is_a?(Puppet::CompilableResourceType) || other.class.is_a?(Puppet::CompilableResourceType) # against other type instances. - self.ref <=> other.ref + ref <=> other.ref end # Code related to resource type attributes. @@ -136,7 +136,7 @@ def self.attrclass(name) # We cache the value, since this method gets called such a huge number # of times (as in, hundreds of thousands in a given run). unless @attrclasses.include?(name) - @attrclasses[name] = case self.attrtype(name) + @attrclasses[name] = case attrtype(name) when :property; @validproperties[name] when :meta; @@metaparamhash[name] when :param; @paramhash[name] @@ -193,10 +193,10 @@ def self.eachmetaparam # def self.ensurable(&block) if block_given? - self.newproperty(:ensure, :parent => Puppet::Property::Ensure, &block) + newproperty(:ensure, :parent => Puppet::Property::Ensure, &block) else - self.newproperty(:ensure, :parent => Puppet::Property::Ensure) do - self.defaultvalues + newproperty(:ensure, :parent => Puppet::Property::Ensure) do + defaultvalues end end end @@ -211,7 +211,7 @@ def self.ensurable? # If the class has all three of these methods defined, then it's # ensurable. [:exists?, :create, :destroy].all? { |method| - self.public_method_defined?(method) + public_method_defined?(method) } end @@ -275,7 +275,7 @@ def self.handle_param_options(name, options) define_method(name.to_s + "?") do val = self[name] if val == :true or val == true - return true + true end end end @@ -576,7 +576,7 @@ def self.validattr?(name) @validattrs ||= {} unless @validattrs.include?(name) - @validattrs[name] = !!(self.validproperty?(name) or self.validparameter?(name) or self.metaparam?(name)) + @validattrs[name] = !!(validproperty?(name) or validparameter?(name) or metaparam?(name)) end @validattrs[name] @@ -622,7 +622,7 @@ def deleting? # @return [Boolean] true if a new parameter was added, false otherwise def add_property_parameter(prop_name) if self.class.validproperty?(prop_name) && !@parameters[prop_name] - self.newattr(prop_name) + newattr(prop_name) return true end false @@ -662,7 +662,7 @@ def [](name) # not the current value. obj.value else - return nil + nil end end @@ -682,7 +682,7 @@ def []=(name, value) end raise Puppet::Error, "Got nil value for #{name}" if value.nil? - property = self.newattr(name) + property = newattr(name) if property begin @@ -933,9 +933,9 @@ def properties # @return [Boolean] true, if this type's name is isomorphic with the object def self.isomorphic? if defined?(@isomorphic) - return @isomorphic + @isomorphic else - return true + true end end @@ -965,7 +965,7 @@ def managed? end } end - return @managed + @managed end ############################### @@ -995,7 +995,7 @@ def remove @parent = nil # Remove the reference to the provider. - if self.provider + if provider @provider.clear @provider = nil end @@ -1035,7 +1035,7 @@ def pre_run_check # # @return [???, nil] WHAT DOES IT RETURN? GUESS IS VOID def flush - self.provider.flush if self.provider and self.provider.respond_to?(:flush) + provider.flush if provider and provider.respond_to?(:flush) end # Says if the ensure property should be retrieved if the resource is ensurable @@ -1051,7 +1051,7 @@ def self.needs_ensure_retrieved # @return [Puppet::Resource] array of all property values (mix of types) # @raise [fail???] if there is a provider and it is not suitable for the host this is evaluated for. def retrieve - fail "Provider #{provider.class.name} is not functional on this host" if self.provider.is_a?(Puppet::Provider) and !provider.class.suitable? + fail "Provider #{provider.class.name} is not functional on this host" if provider.is_a?(Puppet::Provider) and !provider.class.suitable? result = Puppet::Resource.new(self.class, title) @@ -1115,7 +1115,7 @@ def currentpropvalues # is the first property, which is important for skipping 'retrieve' on # all the properties if the resource is absent. ensure_state = false - return properties.each_with_object({}) do |property, prophash| + properties.each_with_object({}) do |property, prophash| if property.name == :ensure ensure_state = property.retrieve prophash[property] = ensure_state @@ -1151,7 +1151,7 @@ def noop # Either requires providers or must be overridden. # @raise [Puppet::DevError] when there are no providers and the implementation has not overridden this method. def self.instances - raise Puppet::DevError, _("%{name} has no providers and has not overridden 'instances'") % { name: self.name } if provider_hash.empty? + raise Puppet::DevError, _("%{name} has no providers and has not overridden 'instances'") % { name: name } if provider_hash.empty? # Put the default provider first, then the rest of the suitable providers. provider_instances = {} @@ -1163,7 +1163,7 @@ def self.instances other = provider_instances[title] if other Puppet.debug { - "%s %s found in both %s and %s; skipping the %s version" % [self.name.to_s.capitalize, title, other.class.name, instance.class.name, instance.class.name] + "%s %s found in both %s and %s; skipping the %s version" % [name.to_s.capitalize, title, other.class.name, instance.class.name, instance.class.name] } next end @@ -1229,9 +1229,9 @@ def self.hash2resource(hash) def pathbuilder p = parent if p - [p.pathbuilder, self.ref].flatten + [p.pathbuilder, ref].flatten else - [self.ref] + [ref] end end @@ -1550,7 +1550,7 @@ def to_edges ## Corrected syntax of debug statement to reflect the way this was called. # i.e. before, after, subscribe, notify - self.debug do + debug do relation = case self.class.name when "subscribe" "subscribes" @@ -1720,7 +1720,7 @@ def self.defaultprovider if defaults.length > 1 Puppet.warning(_("Found multiple default providers for %{name}: %{provider_list}; using %{selected_provider}") % - { name: self.name, provider_list: defaults.collect { |i| i.name.to_s }.join(", "), selected_provider: defaults[0].name }) + { name: name, provider_list: defaults.collect { |i| i.name.to_s }.join(", "), selected_provider: defaults[0].name }) end @defaultprovider = defaults.shift unless defaults.empty? @@ -1736,7 +1736,7 @@ def self.provider_hash_by_type(type) # @return [Hash{ ??? => Puppet::Provider}] Returns a hash of WHAT EXACTLY for this type. # @see provider_hash_by_type method to get the same for some other type def self.provider_hash - Puppet::Type.provider_hash_by_type(self.name) + Puppet::Type.provider_hash_by_type(name) end # Returns the provider having the given name. @@ -1811,7 +1811,7 @@ def self.provide(name, options = {}, &block) options[:resource_type] ||= self - self.providify + providify genclass( name, @@ -1837,7 +1837,7 @@ def self.providify # We expect that the class in which this code is executed will be something # like Puppet::Type::Ssh_authorized_key::ParameterProvider. desc <<-EOT - The specific backend to use for this `#{self.to_s.split('::')[2].downcase}` + The specific backend to use for this `#{to_s.split('::')[2].downcase}` resource. You will seldom need to specify this --- Puppet will usually discover the appropriate provider for your platform. EOT @@ -2088,7 +2088,7 @@ def autorelation(rel_type, rel_catalog = nil) next unless Puppet::Type.type(type) # Retrieve the list of names from the block. - list = self.instance_eval(&block) + list = instance_eval(&block) next unless list list = [list] unless list.is_a?(Array) @@ -2331,7 +2331,7 @@ def initialize(resource) [:file, :line, :catalog, :exported, :virtual].each do |getter| setter = getter.to_s + "=" val = resource.send(getter) - self.send(setter, val) if val + send(setter, val) if val end merge_tags_from(resource) @@ -2357,7 +2357,7 @@ def initialize(resource) # # @return [void] def validate_resource - self.validate if self.respond_to?(:validate) + validate if respond_to?(:validate) rescue Puppet::Error, ArgumentError => detail error = Puppet::ResourceError.new("Validation of #{ref} failed: #{detail}") adderrorcontext(error, detail) @@ -2526,7 +2526,7 @@ def parent def ref # memoizing this is worthwhile ~ 3 percent of calls are the "first time # around" in an average run of Puppet. --daniel 2012-07-17 - @ref ||= "#{self.class.name.to_s.capitalize}[#{self.title}]" + @ref ||= "#{self.class.name.to_s.capitalize}[#{title}]" end # (see self_refresh) @@ -2572,9 +2572,9 @@ def title if self.class.validparameter?(name_var) @title = self[:name] elsif self.class.validproperty?(name_var) - @title = self.should(name_var) + @title = should(name_var) else - self.devfail "Could not find namevar #{name_var} for #{self.class.name}" + devfail "Could not find namevar #{name_var} for #{self.class.name}" end end @@ -2585,19 +2585,19 @@ def title # @see #ref # def to_s - self.ref + ref end # Convert this resource type instance to a Puppet::Resource. # @return [Puppet::Resource] Returns a serializable representation of this resource # def to_resource - resource = self.retrieve_resource + resource = retrieve_resource resource.merge_tags_from(self) @parameters.each do |name, param| # Avoid adding each instance name twice - next if param.class.isnamevar? and param.value == self.title + next if param.class.isnamevar? and param.value == title # We've already got property values next if param.is_a?(Puppet::Property) diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb index 6574d4786cf..94e60a20507 100644 --- a/lib/puppet/type/component.rb +++ b/lib/puppet/type/component.rb @@ -45,11 +45,11 @@ def pathbuilder else myname = reference.to_s end - p = self.parent + p = parent if p - return [p.pathbuilder, myname] + [p.pathbuilder, myname] else - return [myname] + [myname] end end diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 639d7141437..daaa0d88d1a 100644 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -131,24 +131,24 @@ def retrieve # value, which causes us to be treated as in_sync?, which means we # don't actually execute anything. I think. --daniel 2011-03-10 if @resource.check_all_attributes - return :notrun + :notrun else - return self.should + should end end # Actually execute the command. def sync event = :executed_command - tries = self.resource[:tries] - try_sleep = self.resource[:try_sleep] + tries = resource[:tries] + try_sleep = resource[:try_sleep] begin tries.times do |try| # Only add debug messages for tries > 1 to reduce log spam. debug("Exec try #{try + 1}/#{tries}") if tries > 1 - @output, @status = provider.run(self.resource[:command]) - break if self.should.include?(@status.exitstatus.to_s) + @output, @status = provider.run(resource[:command]) + break if should.include?(@status.exitstatus.to_s) if try_sleep > 0 and tries > 1 debug("Sleeping for #{try_sleep} seconds between tries") @@ -165,7 +165,7 @@ def sync when :true log = @resource[:loglevel] when :on_failure - unless self.should.include?(@status.exitstatus.to_s) + unless should.include?(@status.exitstatus.to_s) log = @resource[:loglevel] else log = :false @@ -173,21 +173,21 @@ def sync end unless log == :false if @resource.parameter(:command).sensitive - self.send(log, "[output redacted]") + send(log, "[output redacted]") else @output.split(/\n/).each { |line| - self.send(log, line) + send(log, line) } end end end - unless self.should.include?(@status.exitstatus.to_s) + unless should.include?(@status.exitstatus.to_s) if @resource.parameter(:command).sensitive # Don't print sensitive commands in the clear - self.fail(_("[command redacted] returned %{status} instead of one of [%{expected}]") % { status: @status.exitstatus, expected: self.should.join(",") }) + self.fail(_("[command redacted] returned %{status} instead of one of [%{expected}]") % { status: @status.exitstatus, expected: should.join(",") }) else - self.fail(_("'%{cmd}' returned %{status} instead of one of [%{expected}]") % { cmd: self.resource[:command], status: @status.exitstatus, expected: self.should.join(",") }) + self.fail(_("'%{cmd}' returned %{status} instead of one of [%{expected}]") % { cmd: resource[:command], status: @status.exitstatus, expected: should.join(",") }) end end @@ -503,10 +503,10 @@ def check(value) end if sensitive - self.debug("[output redacted]") + debug("[output redacted]") else output.split(/\n/).each { |line| - self.debug(line) + debug(line) } end @@ -566,10 +566,10 @@ def check(value) end if sensitive - self.debug("[output redacted]") + debug("[output redacted]") else output.split(/\n/).each { |line| - self.debug(line) + debug(line) } end @@ -596,7 +596,7 @@ def check(value) cmd = cmd[0] if cmd.is_a? Array if cmd.is_a?(Puppet::Pops::Evaluator::DeferredValue) - self.debug("The 'command' parameter is deferred and cannot be autorequired") + debug("The 'command' parameter is deferred and cannot be autorequired") else cmd.scan(file_regex) { |str| reqs << str @@ -621,7 +621,7 @@ def check(value) # to do. line = line[0] if line.is_a? Array if line.is_a?(Puppet::Pops::Evaluator::DeferredValue) - self.debug("The '#{param}' parameter is deferred and cannot be autorequired") + debug("The '#{param}' parameter is deferred and cannot be autorequired") else reqs += line.scan(file_regex) end @@ -674,21 +674,21 @@ def check_all_attributes(refreshing = false) end def output - if self.property(:returns).nil? - return nil + if property(:returns).nil? + nil else - return self.property(:returns).output + property(:returns).output end end # Run the command, or optionally run a separately-specified command. def refresh - if self.check_all_attributes(true) + if check_all_attributes(true) cmd = self[:refresh] if cmd provider.run(cmd) else - self.property(:returns).sync + property(:returns).sync end end end diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index ec642d4e09a..d74d9b650ae 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -264,7 +264,7 @@ def self.title_patterns validate do |value| unless value.is_a?(Array) or value.is_a?(String) or value == false - self.devfail "Ignore must be a string or an Array" + devfail "Ignore must be a string or an Array" end end end @@ -442,7 +442,7 @@ def self.title_patterns self.fail _("You cannot specify content when using checksum '%{checksum_type}'") % { checksum_type: checksum_type } if self[:checksum] == checksum_type && !self[:content].nil? end - self.warning _("Possible error: recurselimit is set but not recurse, no recursion will happen") if !self[:recurse] && self[:recurselimit] + warning _("Possible error: recurselimit is set but not recurse, no recursion will happen") if !self[:recurse] && self[:recurselimit] if @parameters[:content] && @parameters[:content].actual_content # Now that we know the checksum, update content (in case it was created before checksum was known). @@ -453,7 +453,7 @@ def self.title_patterns self.fail _("Checksum value '%{value}' is not a valid checksum type %{checksum}") % { value: self[:checksum_value], checksum: self[:checksum] } end - self.warning _("Checksum value is ignored unless content or source are specified") if self[:checksum_value] && !self[:content] && !self[:source] + warning _("Checksum value is ignored unless content or source are specified") if self[:checksum_value] && !self[:content] && !self[:source] provider.validate if provider.respond_to?(:validate) end @@ -465,7 +465,7 @@ def self.[](path) end def self.instances - return [] + [] end # Determine the user to write files as. @@ -531,7 +531,7 @@ def finish # Create any children via recursion or whatever. def eval_generate - return [] unless self.recurse? + return [] unless recurse? recurse end @@ -616,12 +616,12 @@ def pathbuilder # Remove the parent file name list = parent.pathbuilder list.pop # remove the parent's path info - return list << self.ref + list << ref else - return super + super end else - return [self.ref] + [ref] end end @@ -639,7 +639,7 @@ def recurse # If we're purging resources, then delete any resource that isn't on the # remote system. - mark_children_for_purging(children) if self.purge? + mark_children_for_purging(children) if purge? result = children.values.sort_by { |a| a[:path] } remove_less_specific_files(result) @@ -800,7 +800,7 @@ def remove_existing(should) if can_backup?(current_type) backup_existing else - self.warning _("Could not back up file of type %{current_type}") % { current_type: current_type } + warning _("Could not back up file of type %{current_type}") % { current_type: current_type } end end @@ -810,9 +810,9 @@ def remove_existing(should) case current_type when "directory" - return remove_directory(wanted_type) + remove_directory(wanted_type) when "link", "file", "fifo", "socket" - return remove_file(current_type, wanted_type) + remove_file(current_type, wanted_type) else # Including: “blockSpecial”, “characterSpecial”, “unknown” self.fail _("Could not remove files of type %{current_type}") % { current_type: current_type } @@ -833,7 +833,7 @@ def retrieve self.fail err_msg else # Warn if use source permissions is specified on Windows - self.warning err_msg + warning err_msg end end @@ -898,7 +898,7 @@ def stat method = :stat # Files are the only types that support links - if self.instance_of?(Puppet::Type::File) and self[:links] != :follow + if instance_of?(Puppet::Type::File) and self[:links] != :follow method = :lstat end @@ -937,7 +937,7 @@ def write(property = nil) validate_callback = proc { |path| output = Puppet::Util::Execution.execute(self[:validate_cmd].gsub(self[:validate_replacement], path), :failonfail => true, :combine => true) output.split(/\n/).each { |line| - self.debug(line) + debug(line) } } end diff --git a/lib/puppet/type/file/checksum_value.rb b/lib/puppet/type/file/checksum_value.rb index 1a9f3b63670..f72d3e2acb9 100644 --- a/lib/puppet/type/file/checksum_value.rb +++ b/lib/puppet/type/file/checksum_value.rb @@ -26,7 +26,7 @@ def insync?(is) def property_matches?(current, desired) return true if super(current, desired) - return date_matches?(resource.parameter(:checksum).value, current, desired) + date_matches?(resource.parameter(:checksum).value, current, desired) end def retrieve diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb index 6cf44e5ba10..24bce1c7aae 100644 --- a/lib/puppet/type/file/content.rb +++ b/lib/puppet/type/file/content.rb @@ -79,11 +79,11 @@ def change_to_s(currentvalue, newvalue) newvalue = tmp end if currentvalue == :absent - return "defined content as '#{newvalue}'" + "defined content as '#{newvalue}'" elsif newvalue == :absent - return "undefined content from '#{currentvalue}'" + "undefined content from '#{currentvalue}'" else - return "content changed '#{currentvalue}' to '#{newvalue}'" + "content changed '#{currentvalue}' to '#{newvalue}'" end end @@ -92,7 +92,7 @@ def length end def content - self.should + should end # Override this method to provide diffs if asked for. @@ -119,7 +119,7 @@ def property_matches?(current, desired) # The inherited equality is always accepted, so use it if valid. return true if super(current, desired) - return date_matches?(checksum_type, current, desired) + date_matches?(checksum_type, current, desired) end def retrieve diff --git a/lib/puppet/type/file/ensure.rb b/lib/puppet/type/file/ensure.rb index 38e86352022..760ac0f3791 100644 --- a/lib/puppet/type/file/ensure.rb +++ b/lib/puppet/type/file/ensure.rb @@ -164,27 +164,27 @@ def insync?(currentvalue) return true end - if self.should == :present - return !(currentvalue.nil? or currentvalue == :absent) + if should == :present + !(currentvalue.nil? or currentvalue == :absent) else - return super(currentvalue) + super(currentvalue) end end def retrieve stat = @resource.stat if stat - return stat.ftype.intern - elsif self.should == :false - return :false + stat.ftype.intern + elsif should == :false + :false else - return :absent + :absent end end def sync - @resource.remove_existing(self.should) - if self.should == :absent + @resource.remove_existing(should) + if should == :absent return :file_removed end diff --git a/lib/puppet/type/file/mode.rb b/lib/puppet/type/file/mode.rb index a0e3a38541f..d2283c24765 100644 --- a/lib/puppet/type/file/mode.rb +++ b/lib/puppet/type/file/mode.rb @@ -131,10 +131,10 @@ def insync?(currentvalue) end stat = @resource.stat if stat && stat.ftype == "link" && @resource[:links] != :follow - self.debug _("Not managing symlink mode") - return true + debug _("Not managing symlink mode") + true else - return super(currentvalue) + super(currentvalue) end end @@ -153,7 +153,7 @@ def property_matches?(current, desired) # been synced. def retrieve if @resource.stat - @should &&= @should.collect { |s| self.dirmask(s) } + @should &&= @should.collect { |s| dirmask(s) } end super diff --git a/lib/puppet/type/file/selcontext.rb b/lib/puppet/type/file/selcontext.rb index 0277e70c250..225bb5f2c5e 100644 --- a/lib/puppet/type/file/selcontext.rb +++ b/lib/puppet/type/file/selcontext.rb @@ -30,10 +30,10 @@ class SELFileContext < Puppet::Property def retrieve return :absent unless @resource.stat - context = self.get_selinux_current_context(@resource[:path]) + context = get_selinux_current_context(@resource[:path]) is = parse_selinux_context(name, context) if name == :selrange and selinux_support? - self.selinux_category_to_label(is) + selinux_category_to_label(is) else is end @@ -44,13 +44,13 @@ def retrieve_default_context(property) return nil end - context = self.get_selinux_default_context(@resource[:path], @resource[:ensure]) + context = get_selinux_default_context(@resource[:path], @resource[:ensure]) unless context return nil end - property_default = self.parse_selinux_context(property, context) - self.debug "Found #{property} default '#{property_default}' for #{@resource[:path]}" unless property_default.nil? + property_default = parse_selinux_context(property, context) + debug "Found #{property} default '#{property_default}' for #{@resource[:path]}" unless property_default.nil? property_default end @@ -72,14 +72,14 @@ def unsafe_munge(should) end if name == :selrange - self.selinux_category_to_label(should) + selinux_category_to_label(should) else should end end def sync - self.set_selinux_context(@resource[:path], @should, name) + set_selinux_context(@resource[:path], @should, name) :file_changed end end @@ -103,7 +103,7 @@ def sync enabled." @event = :file_changed - defaultto { self.retrieve_default_context(:seluser) } + defaultto { retrieve_default_context(:seluser) } end Puppet::Type.type(:file).newproperty(:selrole, :parent => Puppet::SELFileContext) do @@ -114,7 +114,7 @@ def sync enabled." @event = :file_changed - defaultto { self.retrieve_default_context(:selrole) } + defaultto { retrieve_default_context(:selrole) } end Puppet::Type.type(:file).newproperty(:seltype, :parent => Puppet::SELFileContext) do @@ -125,7 +125,7 @@ def sync enabled." @event = :file_changed - defaultto { self.retrieve_default_context(:seltype) } + defaultto { retrieve_default_context(:seltype) } end Puppet::Type.type(:file).newproperty(:selrange, :parent => Puppet::SELFileContext) do @@ -137,6 +137,6 @@ def sync Security)." @event = :file_changed - defaultto { self.retrieve_default_context(:selrange) } + defaultto { retrieve_default_context(:selrange) } end end diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb index d97bfd1226c..15242d2ef41 100644 --- a/lib/puppet/type/file/source.rb +++ b/lib/puppet/type/file/source.rb @@ -130,9 +130,9 @@ def self.normalize(source) def change_to_s(currentvalue, newvalue) # newvalue = "{md5}#{@metadata.checksum}" if resource.property(:ensure).retrieve == :absent - return "creating from source #{metadata.source} with contents #{metadata.checksum}" + "creating from source #{metadata.source} with contents #{metadata.checksum}" else - return "replacing from source #{metadata.source} with contents #{metadata.checksum}" + "replacing from source #{metadata.source} with contents #{metadata.checksum}" end end diff --git a/lib/puppet/type/file/target.rb b/lib/puppet/type/file/target.rb index cef5fec0e2f..973e5ddf9fa 100644 --- a/lib/puppet/type/file/target.rb +++ b/lib/puppet/type/file/target.rb @@ -36,7 +36,7 @@ module Puppet def mklink raise Puppet::Error, "Cannot symlink on this platform version" unless provider.feature?(:manages_symlinks) - target = self.should + target = should # Clean up any existing objects. The argument is just for logging, # it doesn't determine what's removed. @@ -63,12 +63,12 @@ def mklink end def insync?(currentvalue) - if [:nochange, :notlink].include?(self.should) or @resource.recurse? - return true + if [:nochange, :notlink].include?(should) or @resource.recurse? + true elsif !@resource.replace? and Puppet::FileSystem.exist?(@resource[:path]) - return true + true else - return super(currentvalue) + super(currentvalue) end end @@ -76,12 +76,12 @@ def retrieve stat = @resource.stat if stat if stat.ftype == "link" - return Puppet::FileSystem.readlink(@resource[:path]) + Puppet::FileSystem.readlink(@resource[:path]) else - return :notlink + :notlink end else - return :absent + :absent end end end diff --git a/lib/puppet/type/filebucket.rb b/lib/puppet/type/filebucket.rb index 7d53db9565f..d0d5b339042 100644 --- a/lib/puppet/type/filebucket.rb +++ b/lib/puppet/type/filebucket.rb @@ -113,11 +113,11 @@ def mkbucket @bucket = Puppet::FileBucket::Dipper.new(args) rescue => detail message = _("Could not create %{type} filebucket: %{detail}") % { type: type, detail: detail } - self.log_exception(detail, message) + log_exception(detail, message) self.fail(message) end - @bucket.name = self.name + @bucket.name = name end end end diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb index 30b6378f400..f5bc3696337 100644 --- a/lib/puppet/type/group.rb +++ b/lib/puppet/type/group.rb @@ -56,10 +56,10 @@ def retrieve end def sync - if self.should == :absent + if should == :absent raise Puppet::DevError, _("GID cannot be deleted") else - provider.gid = self.should + provider.gid = should end end @@ -73,7 +73,7 @@ def sync end when Symbol unless gid == :absent - self.devfail "Invalid GID #{gid}" + devfail "Invalid GID #{gid}" end end diff --git a/lib/puppet/type/notify.rb b/lib/puppet/type/notify.rb index 4bda717e662..81bda653f90 100644 --- a/lib/puppet/type/notify.rb +++ b/lib/puppet/type/notify.rb @@ -12,14 +12,14 @@ module Puppet newproperty(:message, :idempotent => false) do desc "The message to be sent to the log. Note that the value specified must be a string." def sync - message = @sensitive ? 'Sensitive [value redacted]' : self.should + message = @sensitive ? 'Sensitive [value redacted]' : should case @resource["withpath"] when :true send(@resource[:loglevel], message) else Puppet.send(@resource[:loglevel], message) end - return + nil end def retrieve diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb index db71af27506..8fce7abd4f4 100644 --- a/lib/puppet/type/package.rb +++ b/lib/puppet/type/package.rb @@ -119,7 +119,7 @@ module Puppet # Because yum always exits with a 0 exit code, there's a retrieve # in the "install" method. So, check the current state now, # to compare against later. - current = self.retrieve + current = retrieve begin provider.update rescue => detail @@ -140,7 +140,7 @@ module Puppet self.fail Puppet::Error, _("Could not update: %{detail}") % { detail: detail }, detail end - if self.retrieve == :absent + if retrieve == :absent :package_installed else :package_changed @@ -188,7 +188,7 @@ def insync?(is) # that can't query versions. return true else - self.debug "#{@resource.name} #{is.inspect} is installed, latest is #{@latest.inspect}" + debug "#{@resource.name} #{is.inspect} is installed, latest is #{@latest.inspect}" end when :absent diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/resources.rb index eb02abc6cd3..aa88180bdc7 100644 --- a/lib/puppet/type/resources.rb +++ b/lib/puppet/type/resources.rb @@ -100,9 +100,9 @@ def check(resource) @checkmethod ||= "#{self[:name]}_check" @hascheck ||= respond_to?(@checkmethod) if @hascheck - return send(@checkmethod, resource) + send(@checkmethod, resource) else - return true + true end end @@ -116,7 +116,7 @@ def able_to_ensure_absent?(resource) # Generate any new resources we need to manage. This is pretty hackish # right now, because it only supports purging. def generate - return [] unless self.purge? + return [] unless purge? resource_type.instances .reject { |r| catalog.resource_refs.include? r.ref } diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb index d5750a46300..55c110fe176 100644 --- a/lib/puppet/type/schedule.rb +++ b/lib/puppet/type/schedule.rb @@ -255,10 +255,10 @@ def match?(previous, now) when :number method = ScheduleMethods[value] if method.is_a?(Proc) - return method.call(previous, now) + method.call(previous, now) else # We negate it, because if they're equal we don't run - return now.send(method) != previous.send(method) + now.send(method) != previous.send(method) end when :distance scale = ScheduleScales[value] @@ -267,7 +267,7 @@ def match?(previous, now) # than the unit of time, we match. We divide the scale # by the repeat, so that we'll repeat that often within # the scale. - return (now.to_i - previous.to_i) >= (scale / @resource[:repeat]) + (now.to_i - previous.to_i) >= (scale / @resource[:repeat]) end end end @@ -401,7 +401,7 @@ def self.mkdefaultschedules Puppet.debug "Creating default schedules" - result << self.new( + result << new( :name => "puppet", :period => :hourly, @@ -410,7 +410,7 @@ def self.mkdefaultschedules # And then one for every period @parameters.find { |p| p.name == :period }.value_collection.values.each { |value| - result << self.new( + result << new( :name => value.to_s, :period => value ) diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb index c3f0d8fc490..48c62ac7bb8 100644 --- a/lib/puppet/type/tidy.rb +++ b/lib/puppet/type/tidy.rb @@ -100,7 +100,7 @@ # Make sure we convert to an array. munge do |value| - fail _("Tidy can't use matches with recurse 0, false, or undef") if "#{@resource[:recurse]}" =~ /^(0|false|)$/ + fail _("Tidy can't use matches with recurse 0, false, or undef") if (@resource[:recurse]).to_s =~ /^(0|false|)$/ [value].flatten end @@ -110,7 +110,7 @@ def tidy?(path, stat) basename = File.basename(path) flags = File::FNM_DOTMATCH | File::FNM_PATHNAME - return(value.find { |pattern| File.fnmatch(pattern, basename, flags) } ? true : false) + (value.find { |pattern| File.fnmatch(pattern, basename, flags) } ? true : false) end end @@ -139,7 +139,7 @@ def tidy?(path, stat) def convert(unit, multi) num = AgeConvertors[unit] if num - return num * multi + num * multi else self.fail _("Invalid age unit '%{unit}'") % { unit: unit } end @@ -181,7 +181,7 @@ def convert(unit, multi) if num result = multi num.times do result *= 1024 end - return result + result else self.fail _("Invalid size unit '%{unit}'") % { unit: unit } end @@ -260,9 +260,9 @@ def retrieve # Our ensure property knows how to retrieve everything for us. obj = @parameters[:ensure] if obj - return obj.retrieve + obj.retrieve else - return {} + {} end end @@ -329,10 +329,10 @@ def matches?(path) basename = File.basename(path) flags = File::FNM_DOTMATCH | File::FNM_PATHNAME if self[:matches].find { |pattern| File.fnmatch(pattern, basename, flags) } - return true + true else debug "No specified patterns match #{path}, not tidying" - return false + false end end @@ -371,10 +371,10 @@ def stat(path) Puppet::FileSystem.lstat(path) rescue Errno::ENOENT debug _("File does not exist") - return nil + nil rescue Errno::EACCES # TRANSLATORS "stat" is a program name and should not be translated warning _("Could not stat; permission denied") - return nil + nil end end diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb index ca292c99815..bb44e2e1408 100644 --- a/lib/puppet/type/user.rb +++ b/lib/puppet/type/user.rb @@ -93,12 +93,12 @@ module Puppet def retrieve if provider.exists? if provider.respond_to?(:is_role?) and provider.is_role? - return :role + :role else - return :present + :present end else - return :absent + :absent end end @@ -849,7 +849,7 @@ def unknown_keys_in_file(keyfile) name = "#{keyfile}:unnamed-#{name_index += 1}" end names << name - Puppet.debug "#{self.ref} parsed for purging Ssh_authorized_key[#{name}]" + Puppet.debug "#{ref} parsed for purging Ssh_authorized_key[#{name}]" end names.map { |keyname| diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index e697aa6056a..06c7b11815d 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -190,7 +190,7 @@ def benchmark(*args) yield } object.send(level, msg % { seconds: "%0.2f" % seconds }) - return seconds + seconds else yield end diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index 180f21d5ec2..fb86b5fb609 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -81,7 +81,7 @@ def load_file(name, env) begin mark_loaded(name, file) Kernel.load file - return true + true rescue SystemExit, NoMemoryError raise rescue Exception => detail diff --git a/lib/puppet/util/backups.rb b/lib/puppet/util/backups.rb index c3322e785ea..528dbcbe973 100644 --- a/lib/puppet/util/backups.rb +++ b/lib/puppet/util/backups.rb @@ -13,7 +13,7 @@ def perform_backup(file = nil) file ||= self[:path] return true unless Puppet::FileSystem.exist?(file) - return(self.bucket ? perform_backup_with_bucket(file) : perform_backup_with_backuplocal(file, self[:backup])) + (bucket ? perform_backup_with_bucket(file) : perform_backup_with_backuplocal(file, self[:backup])) end private @@ -44,7 +44,7 @@ def perform_backup_with_backuplocal(fileobj, backup) # N.B. cp_r works on both files and directories FileUtils.cp_r(file, bfile, :preserve => true) - return true + true rescue => detail # since they said they want a backup, let's error out # if we couldn't make one @@ -53,7 +53,7 @@ def perform_backup_with_backuplocal(fileobj, backup) end def remove_backup(newfile) - if self.instance_of?(Puppet::Type::File) and self[:links] != :follow + if instance_of?(Puppet::Type::File) and self[:links] != :follow method = :lstat else method = :stat @@ -75,14 +75,14 @@ def remove_backup(newfile) Puppet::FileSystem.unlink(newfile) rescue => detail message = _("Could not remove old backup: %{detail}") % { detail: detail } - self.log_exception(detail, message) + log_exception(detail, message) self.fail Puppet::Error, message, detail end end def backup_file_with_filebucket(f) - sum = self.bucket.backup(f) - self.info _("Filebucketed %{f} to %{filebucket} with sum %{sum}") % { f: f, filebucket: self.bucket.name, sum: sum } - return sum + sum = bucket.backup(f) + info _("Filebucketed %{f} to %{filebucket} with sum %{sum}") % { f: f, filebucket: bucket.name, sum: sum } + sum end end diff --git a/lib/puppet/util/character_encoding.rb b/lib/puppet/util/character_encoding.rb index 5093fc24550..2ebf4b5d021 100644 --- a/lib/puppet/util/character_encoding.rb +++ b/lib/puppet/util/character_encoding.rb @@ -26,7 +26,7 @@ def convert_to_utf_8(string) } end # String is already valid UTF-8 - noop - return string_copy + string_copy else # If the string comes to us as BINARY encoded, we don't know what it # started as. However, to encode! we need a starting place, and our @@ -34,7 +34,7 @@ def convert_to_utf_8(string) # So set external_encoding to default_external before we try to # transcode to UTF-8. string_copy.force_encoding(Encoding.default_external) if original_encoding == Encoding::BINARY - return string_copy.encode(Encoding::UTF_8) + string_copy.encode(Encoding::UTF_8) end rescue EncodingError => detail # Set the encoding on our copy back to its original if we modified it @@ -46,7 +46,7 @@ def convert_to_utf_8(string) Puppet.debug { _("%{error}: %{value} cannot be transcoded by Puppet.") % { error: detail.inspect, value: string.dump } } - return string_copy + string_copy end end @@ -68,14 +68,15 @@ def override_encoding_to_utf_8(string) string_copy = string.dup original_encoding = string_copy.encoding return string_copy if original_encoding == Encoding::UTF_8 + if string_copy.force_encoding(Encoding::UTF_8).valid_encoding? - return string_copy + string_copy else Puppet.debug { _("%{value} is not valid UTF-8 and result of overriding encoding would be invalid.") % { value: string.dump } } # Set copy back to its original encoding before returning - return string_copy.force_encoding(original_encoding) + string_copy.force_encoding(original_encoding) end end end diff --git a/lib/puppet/util/docs.rb b/lib/puppet/util/docs.rb index 9232c83bd85..61ece32fceb 100644 --- a/lib/puppet/util/docs.rb +++ b/lib/puppet/util/docs.rb @@ -21,7 +21,7 @@ def dochook(name, &block) # Generate the full doc string. def doc extra = methods.find_all { |m| m.to_s =~ /^dochook_.+/ }.sort.filter_map { |m| - self.send(m) + send(m) }.collect { |r| "* #{r}" }.join("\n") if @doc diff --git a/lib/puppet/util/errors.rb b/lib/puppet/util/errors.rb index aadc923c4ff..e3e317018a7 100644 --- a/lib/puppet/util/errors.rb +++ b/lib/puppet/util/errors.rb @@ -22,8 +22,8 @@ def devfail(msg) # @param other [Exception] original exception, source of backtrace info # @return [Exception] error parameter def adderrorcontext(error, other = nil) - error.line ||= self.line if error.respond_to?(:line=) and self.respond_to?(:line) and self.line - error.file ||= self.file if error.respond_to?(:file=) and self.respond_to?(:file) and self.file + error.line ||= line if error.respond_to?(:line=) and respond_to?(:line) and line + error.file ||= file if error.respond_to?(:file=) and respond_to?(:file) and file error.original ||= other if error.respond_to?(:original=) error.set_backtrace(other.backtrace) if other and other.respond_to?(:backtrace) diff --git a/lib/puppet/util/feature.rb b/lib/puppet/util/feature.rb index e01b01f9d95..877a293abf6 100644 --- a/lib/puppet/util/feature.rb +++ b/lib/puppet/util/feature.rb @@ -77,7 +77,7 @@ def method_missing(method, *args) feature = method.to_s.sub(/\?$/, '') @loader.load(feature, Puppet.lookup(:current_environment)) - respond_to?(method) && self.send(method) + respond_to?(method) && send(method) end # Actually test whether the feature is present. We only want to test when diff --git a/lib/puppet/util/fileparsing.rb b/lib/puppet/util/fileparsing.rb index 4a294043ab5..c6db6f8b233 100644 --- a/lib/puppet/util/fileparsing.rb +++ b/lib/puppet/util/fileparsing.rb @@ -230,9 +230,9 @@ def handle_record_line(line, record) if ret ret[:record_type] = record.name - return ret + ret else - return nil + nil end end @@ -246,7 +246,7 @@ def line_separator def lines(text) # NOTE: We do not have to remove trailing separators because split will ignore # them by default (unless you pass -1 as a second parameter) - text.split(self.line_separator) + text.split(line_separator) end # Split a bunch of text into lines and then parse them individually. @@ -346,7 +346,7 @@ def to_line(details) end case record.type - when :text; return details[:line] + when :text; details[:line] else return record.to_line(details) if record.respond_to?(:to_line) @@ -358,9 +358,9 @@ def to_line(details) if regex == true regex = /\s+$/ end - return line.sub(regex, '') + line.sub(regex, '') else - return line + line end end end @@ -368,9 +368,9 @@ def to_line(details) # Whether to add a trailing separator to the file. Defaults to true def trailing_separator if defined?(@trailing_separator) - return @trailing_separator + @trailing_separator else - return true + true end end @@ -378,11 +378,9 @@ def valid_attr?(type, attr) type = type.intern record = record_type(type) if record && record.fields.include?(attr.intern) - return true - elsif attr.intern == :ensure - return true + true else - false + attr.intern == :ensure end end diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 616e608dc97..a8c9bdbc075 100644 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -40,9 +40,9 @@ def self.newfiletype(name, &block) val = real_read @loaded = Time.now if val - return val.gsub(/# HEADER.*\n/, '') + val.gsub(/# HEADER.*\n/, '') else - return "" + "" end rescue Puppet::Error raise @@ -57,7 +57,7 @@ def self.newfiletype(name, &block) define_method(:write) do |text| val = real_write(text) @synced = Time.now - return val + val rescue Puppet::Error raise rescue => detail @@ -110,7 +110,7 @@ def read # being explicitly preserved Puppet::FileSystem.read(@path, :encoding => Encoding.default_external) else - return nil + nil end end @@ -202,11 +202,11 @@ def read rescue => detail case detail.to_s when /no crontab for/ - return "" + "" when /are not allowed to/ Puppet.debug _("The %{path} user is not authorized to use cron. Their crontab file is treated as empty in case Puppet authorizes them in the middle of the run (by, for example, modifying the cron.deny or cron.allow files).") % { path: @path } - return "" + "" else raise FileReadError, _("Could not read crontab for %{path}: %{detail}") % { path: @path, detail: detail }, detail.backtrace end @@ -245,9 +245,9 @@ def write(text) # does not think I should be allowed to set the @path to my own user name def cmdbase if @uid == Puppet::Util::SUIDManager.uid || Puppet.runtime[:facter].value('os.name') == "HP-UX" - return "crontab" + "crontab" else - return "crontab -u #{@path}" + "crontab -u #{@path}" end end end @@ -267,11 +267,11 @@ def read rescue => detail case detail.to_s when /can't open your crontab/ - return "" + "" when /you are not authorized to use cron/ Puppet.debug _("The %{path} user is not authorized to use cron. Their crontab file is treated as empty in case Puppet authorizes them in the middle of the run (by, for example, modifying the cron.deny or cron.allow files).") % { path: @path } - return "" + "" else raise FileReadError, _("Could not read crontab for %{path}: %{detail}") % { path: @path, detail: detail }, detail.backtrace end @@ -318,11 +318,11 @@ def read rescue => detail case detail.to_s when /open.*in.*directory/ - return "" + "" when /not.*authorized.*cron/ Puppet.debug _("The %{path} user is not authorized to use cron. Their crontab file is treated as empty in case Puppet authorizes them in the middle of the run (by, for example, modifying the cron.deny or cron.allow files).") % { path: @path } - return "" + "" else raise FileReadError, _("Could not read crontab for %{path}: %{detail}") % { path: @path, detail: detail }, detail.backtrace end diff --git a/lib/puppet/util/inifile.rb b/lib/puppet/util/inifile.rb index f6e4750c68b..98a4655ce68 100644 --- a/lib/puppet/util/inifile.rb +++ b/lib/puppet/util/inifile.rb @@ -73,7 +73,7 @@ def []=(key, value) # exists, return nil def [](key) entry = find_entry(key) - return(entry.nil? ? nil : entry[1]) + (entry.nil? ? nil : entry[1]) end # Format the section as text in the way it should be @@ -251,7 +251,7 @@ def add_section(name) private def section_exists?(name) - if self.get_section(name) + if get_section(name) true elsif @file_collection and @file_collection.get_section(name) true diff --git a/lib/puppet/util/ldap/manager.rb b/lib/puppet/util/ldap/manager.rb index 3d7156aca00..f1a08e85a61 100644 --- a/lib/puppet/util/ldap/manager.rb +++ b/lib/puppet/util/ldap/manager.rb @@ -109,7 +109,7 @@ def entry2provider(entry) # Create our normal search filter. def filter - return(objectclasses.length == 1 ? "objectclass=#{objectclasses[0]}" : "(&(objectclass=" + objectclasses.join(")(objectclass=") + "))") + (objectclasses.length == 1 ? "objectclass=#{objectclasses[0]}" : "(&(objectclass=" + objectclasses.join(")(objectclass=") + "))") end # Find the associated entry for a resource. Returns a hash, minus @@ -213,7 +213,7 @@ def search(sfilter = nil) result << entry2provider(entry) end end - return(result.empty? ? nil : result) + (result.empty? ? nil : result) end # Update the ldap entry with the desired state. diff --git a/lib/puppet/util/lockfile.rb b/lib/puppet/util/lockfile.rb index 256c5cf2342..c57df408637 100644 --- a/lib/puppet/util/lockfile.rb +++ b/lib/puppet/util/lockfile.rb @@ -51,7 +51,7 @@ def locked? # was locked. # @return [String] the data object. def lock_data - return File.read(@file_path) if file_locked? + File.read(@file_path) if file_locked? end # Private, internal utility method for encapsulating the logic about diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb index 5a0d3f64f01..f61a91305c6 100644 --- a/lib/puppet/util/log.rb +++ b/lib/puppet/util/log.rb @@ -312,7 +312,7 @@ def initialize(args) tags = args[:tags] if tags - tags.each { |t| self.tag(t) } + tags.each { |t| tag(t) } end # Don't add these unless defined (preserve 3.x API as much as possible) @@ -345,7 +345,7 @@ def initialize_from_hash(data) end def to_hash - self.to_data_hash + to_data_hash end def to_data_hash diff --git a/lib/puppet/util/log/destination.rb b/lib/puppet/util/log/destination.rb index f1452f412b2..2b90d2cd602 100644 --- a/lib/puppet/util/log/destination.rb +++ b/lib/puppet/util/log/destination.rb @@ -32,9 +32,9 @@ def self.match?(obj) def name if defined?(@name) - return @name + @name else - return self.class.name + self.class.name end end diff --git a/lib/puppet/util/metric.rb b/lib/puppet/util/metric.rb index 21c522b249e..903783e78c8 100644 --- a/lib/puppet/util/metric.rb +++ b/lib/puppet/util/metric.rb @@ -36,9 +36,9 @@ def to_data_hash def [](name) value = @values.find { |v| v[0] == name } if value - return value[2] + value[2] else - return 0 + 0 end end diff --git a/lib/puppet/util/network_device/config.rb b/lib/puppet/util/network_device/config.rb index 6ed4e9fcb1a..9b9fde3ba9c 100644 --- a/lib/puppet/util/network_device/config.rb +++ b/lib/puppet/util/network_device/config.rb @@ -6,7 +6,7 @@ class Puppet::Util::NetworkDevice::Config def self.main - @main ||= self.new + @main ||= new end def self.devices diff --git a/lib/puppet/util/package/version/range/eq.rb b/lib/puppet/util/package/version/range/eq.rb index 6890858a6db..7c30b1e47a8 100644 --- a/lib/puppet/util/package/version/range/eq.rb +++ b/lib/puppet/util/package/version/range/eq.rb @@ -6,7 +6,7 @@ module Puppet::Util::Package::Version class Range class Eq < Simple def to_s - "#{@version}" + @version.to_s end def include?(version) diff --git a/lib/puppet/util/package/version/rpm.rb b/lib/puppet/util/package/version/rpm.rb index 4774fcf2b8a..c2db84c9ba0 100644 --- a/lib/puppet/util/package/version/rpm.rb +++ b/lib/puppet/util/package/version/rpm.rb @@ -41,7 +41,7 @@ def eql?(other) def <=>(other) raise ArgumentError, _("Cannot compare, as %{other} is not a Rpm Version") % { other: other } unless other.is_a?(self.class) - rpm_compare_evr(self.to_s, other.to_s) + rpm_compare_evr(to_s, other.to_s) end private diff --git a/lib/puppet/util/pidlock.rb b/lib/puppet/util/pidlock.rb index 3001ab6357a..7753d1816f9 100644 --- a/lib/puppet/util/pidlock.rb +++ b/lib/puppet/util/pidlock.rb @@ -25,7 +25,7 @@ def lock def unlock if mine? - return @lockfile.unlock + @lockfile.unlock else false end diff --git a/lib/puppet/util/plist.rb b/lib/puppet/util/plist.rb index a9f3b9ddb9d..387ffcfe388 100644 --- a/lib/puppet/util/plist.rb +++ b/lib/puppet/util/plist.rb @@ -51,7 +51,7 @@ def read_plist_file(file_path) Puppet.warning(message) end end - return nil + nil end # Read plist text using the CFPropertyList gem. diff --git a/lib/puppet/util/posix.rb b/lib/puppet/util/posix.rb index 1f4f3570bb1..71cb241d6af 100644 --- a/lib/puppet/util/posix.rb +++ b/lib/puppet/util/posix.rb @@ -87,10 +87,10 @@ def get_posix_field(space, field, id) end begin - return Etc.send(method, id).send(field) + Etc.send(method, id).send(field) rescue NoMethodError, ArgumentError # ignore it; we couldn't find the object - return nil + nil end end @@ -128,8 +128,8 @@ def search_posix_field(type, field, id) # Determine what the field name is for users and groups. def idfield(space) case space.intern - when :gr, :group; return :gid - when :pw, :user, :passwd; return :uid + when :gr, :group; :gid + when :pw, :user, :passwd; :uid else raise ArgumentError, _("Can only handle users and groups") end @@ -138,8 +138,8 @@ def idfield(space) # Determine what the method is to get users and groups by id def methodbyid(space) case space.intern - when :gr, :group; return :getgrgid - when :pw, :user, :passwd; return :getpwuid + when :gr, :group; :getgrgid + when :pw, :user, :passwd; :getpwuid else raise ArgumentError, _("Can only handle users and groups") end @@ -148,8 +148,8 @@ def methodbyid(space) # Determine what the method is to get users and groups by name def methodbyname(space) case space.intern - when :gr, :group; return :getgrnam - when :pw, :user, :passwd; return :getpwnam + when :gr, :group; :getgrnam + when :pw, :user, :passwd; :getpwnam else raise ArgumentError, _("Can only handle users and groups") end @@ -194,13 +194,13 @@ def get_posix_value(location, id_field, field) if id == check_value_id Puppet.debug("Multiple entries found for resource: '#{location}' with #{id_field}: #{id}") - return id + id else Puppet.debug("The value retrieved: '#{check_value}' is different than the required state: '#{field}', searching in all entries") - return search_posix_field(location, id_field, field) + search_posix_field(location, id_field, field) end else - return id + id end end end diff --git a/lib/puppet/util/provider_features.rb b/lib/puppet/util/provider_features.rb index ea1882b1b22..bd2677c07bc 100644 --- a/lib/puppet/util/provider_features.rb +++ b/lib/puppet/util/provider_features.rb @@ -22,13 +22,13 @@ class ProviderFeature # @param obj [Object, Class] the object or class to check if requirements are met # @return [Boolean] whether all requirements for this feature are met or not. def available?(obj) - if self.methods - return !!methods_available?(obj) + if methods + !!methods_available?(obj) else # In this case, the provider has to declare support for this # feature, and that's been checked before we ever get to the # method checks. - return false + false end end diff --git a/lib/puppet/util/rdoc/generators/puppet_generator.rb b/lib/puppet/util/rdoc/generators/puppet_generator.rb index 07902c38087..d79114c027e 100644 --- a/lib/puppet/util/rdoc/generators/puppet_generator.rb +++ b/lib/puppet/util/rdoc/generators/puppet_generator.rb @@ -642,7 +642,7 @@ def build_child_list(context) end def <=>(other) - self.name <=> other.name + name <=> other.name end end @@ -809,7 +809,7 @@ def attribute_values end def <=>(other) - self.name <=> other.name + name <=> other.name end end @@ -849,7 +849,7 @@ def section end def index_name - "#{@context.name}" + @context.name.to_s end def params diff --git a/lib/puppet/util/reference.rb b/lib/puppet/util/reference.rb index b65b8edbd3e..bba7d138783 100644 --- a/lib/puppet/util/reference.rb +++ b/lib/puppet/util/reference.rb @@ -17,7 +17,7 @@ def self.modes end def self.newreference(name, options = {}, &block) - ref = self.new(name, **options, &block) + ref = new(name, **options, &block) instance_hash(:reference)[name.intern] = ref ref @@ -71,14 +71,14 @@ def self.references(environment) def doc if defined?(@doc) - return "#{@name} - #{@doc}" + "#{@name} - #{@doc}" else - return @title + @title end end def dynamic? - self.dynamic + dynamic end def initialize(name, title: nil, depth: nil, dynamic: nil, doc: nil, &block) diff --git a/lib/puppet/util/rpm_compare.rb b/lib/puppet/util/rpm_compare.rb index 4d4d13465c2..a10b7977015 100644 --- a/lib/puppet/util/rpm_compare.rb +++ b/lib/puppet/util/rpm_compare.rb @@ -141,7 +141,7 @@ def rpm_parse_evr(full_version) version = full_version release = nil end - return { :epoch => epoch, :version => version, :release => release, :arch => architecture } + { :epoch => epoch, :version => version, :release => release, :arch => architecture } end # this method is a native implementation of the @@ -152,7 +152,7 @@ def compare_values(s1, s2) return 1 if !s1.nil? && s2.nil? return -1 if s1.nil? && !s2.nil? - return rpmvercmp(s1, s2) + rpmvercmp(s1, s2) end # how rpm compares two package versions: @@ -190,8 +190,6 @@ def rpm_compare_evr(should, is) # This should NOT be triggered if we're trying to ensure latest. return 0 if should_hash[:release].nil? - rc = compare_values(should_hash[:release], is_hash[:release]) - - return rc + compare_values(should_hash[:release], is_hash[:release]) end end diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index 7597fa52c28..44976924059 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -142,10 +142,10 @@ def set_selinux_context(file, value, component = false) retval = Selinux.lsetfilecon(file, context) if retval == 0 - return true + true else Puppet.warning _("Failed to set SELinux context %{context} on %{file}") % { context: context, file: file } - return false + false end end @@ -294,7 +294,7 @@ def find_fs(path) end # Should never be reached... - return mounts['/'] + mounts['/'] end ## diff --git a/lib/puppet/util/storage.rb b/lib/puppet/util/storage.rb index 9740185f231..dc896ac70c5 100644 --- a/lib/puppet/util/storage.rb +++ b/lib/puppet/util/storage.rb @@ -40,14 +40,14 @@ def self.init @@state = {} end - self.init + init def self.load Puppet.settings.use(:main) unless FileTest.directory?(Puppet[:statedir]) filename = Puppet[:statefile] unless Puppet::FileSystem.exist?(filename) - self.init if @@state.nil? + init if @@state.nil? return end unless File.file?(filename) @@ -68,7 +68,7 @@ def self.load unless @@state.is_a?(Hash) Puppet.err _("State got corrupted") - self.init + init end end diff --git a/lib/puppet/util/suidmanager.rb b/lib/puppet/util/suidmanager.rb index a9f71f272c0..3134a48157f 100644 --- a/lib/puppet/util/suidmanager.rb +++ b/lib/puppet/util/suidmanager.rb @@ -65,8 +65,8 @@ def asuser(new_uid = nil, new_gid = nil) return yield unless root? return yield unless new_uid or new_gid - old_euid = self.euid - old_egid = self.egid + old_euid = euid + old_egid = egid begin change_privileges(new_uid, new_gid, false) diff --git a/lib/puppet/util/symbolic_file_mode.rb b/lib/puppet/util/symbolic_file_mode.rb index 52421c4ba90..2701c59d3cd 100644 --- a/lib/puppet/util/symbolic_file_mode.rb +++ b/lib/puppet/util/symbolic_file_mode.rb @@ -19,7 +19,7 @@ def valid_symbolic_mode?(value) return true if value =~ /^0?[0-7]{1,4}$/ return true if value =~ /^([ugoa]*[-=+][-=+rstwxXugo]*)(,[ugoa]*[-=+][-=+rstwxXugo]*)*$/ - return false + false end def display_mode(value) @@ -146,12 +146,10 @@ def symbolic_mode_to_int(modification, to_mode = 0, is_a_directory = false) raise Puppet::Error, _("%{error}%{rest} in symbolic mode %{modification}") % { error: e, rest: rest, modification: modification.inspect }, e.backtrace end - result = - final_mode['s'] << 9 | + final_mode['s'] << 9 | final_mode['u'] << 6 | final_mode['g'] << 3 | final_mode['o'] << 0 - return result end end end diff --git a/lib/puppet/util/tag_set.rb b/lib/puppet/util/tag_set.rb index 9d64367402e..6bc09db3500 100644 --- a/lib/puppet/util/tag_set.rb +++ b/lib/puppet/util/tag_set.rb @@ -7,7 +7,7 @@ class Puppet::Util::TagSet < Set include Puppet::Network::FormatSupport def self.from_yaml(yaml) - self.new(Puppet::Util::Yaml.safe_load(yaml, [Symbol])) + new(Puppet::Util::Yaml.safe_load(yaml, [Symbol])) end def to_yaml @@ -15,7 +15,7 @@ def to_yaml end def self.from_data_hash(data) - self.new(data) + new(data) end # TODO: A method named #to_data_hash should not return an array diff --git a/lib/puppet/util/tagging.rb b/lib/puppet/util/tagging.rb index 152afe3d1d4..123b6d9ae25 100644 --- a/lib/puppet/util/tagging.rb +++ b/lib/puppet/util/tagging.rb @@ -71,7 +71,7 @@ def tagged?(*tags) # @return [Boolean] true if this instance is tagged with at least one of the provided tags # def raw_tagged?(tag_array) - my_tags = self.tags + my_tags = tags !tag_array.index { |t| my_tags.include?(t) }.nil? end diff --git a/lib/puppet/util/terminal.rb b/lib/puppet/util/terminal.rb index 38e40294d2a..02a2a33f009 100644 --- a/lib/puppet/util/terminal.rb +++ b/lib/puppet/util/terminal.rb @@ -11,8 +11,8 @@ def self.width result = %x(stty size 2>/dev/null).split[1] || %x(tput cols 2>/dev/null).split[0] end - return (result || '80').to_i + (result || '80').to_i rescue - return 80 + 80 end end diff --git a/lib/puppet/util/windows/access_control_list.rb b/lib/puppet/util/windows/access_control_list.rb index 518edd037db..ecf277fdf84 100644 --- a/lib/puppet/util/windows/access_control_list.rb +++ b/lib/puppet/util/windows/access_control_list.rb @@ -109,7 +109,7 @@ def inspect def ==(other) self.class == other.class && - self.to_a == other.to_a + to_a == other.to_a end alias eql? == diff --git a/lib/puppet/util/windows/adsi.rb b/lib/puppet/util/windows/adsi.rb index 57f78152aec..61f31346c32 100644 --- a/lib/puppet/util/windows/adsi.rb +++ b/lib/puppet/util/windows/adsi.rb @@ -165,7 +165,7 @@ def parse_name(name) domain = matches[0][1] || '.' account = matches[0][2] - return account, domain + [account, domain] end # returns Puppet::Util::Windows::SID::Principal[] @@ -399,7 +399,7 @@ def set_groups(desired_groups, minimum = true) desired_groups = desired_groups.split(',').map(&:strip) - current_hash = self.group_sids.to_h { |sid| [sid.sid, sid] } + current_hash = group_sids.to_h { |sid| [sid.sid, sid] } desired_hash = self.class.name_sid_hash(desired_groups) # First we add the user to all the groups it should be in but isn't @@ -638,7 +638,7 @@ def members def set_members(desired_members, inclusive = true) return if desired_members.nil? - current_hash = self.member_sids.to_h { |sid| [sid.sid, sid] } + current_hash = member_sids.to_h { |sid| [sid.sid, sid] } desired_hash = self.class.name_sid_hash(desired_members) # First we add all missing members diff --git a/lib/puppet/util/windows/daemon.rb b/lib/puppet/util/windows/daemon.rb index f0ecdf6dd3b..83ff582706e 100644 --- a/lib/puppet/util/windows/daemon.rb +++ b/lib/puppet/util/windows/daemon.rb @@ -209,7 +209,7 @@ class Daemon # This is a shortcut for Daemon.new + Daemon#mainloop. # def self.mainloop - self.new.mainloop + new.mainloop end # This is the method that actually puts your code into a loop and allows it diff --git a/lib/puppet/util/windows/monkey_patches/process.rb b/lib/puppet/util/windows/monkey_patches/process.rb index fccde3f1ab0..3ab9c0ba75c 100644 --- a/lib/puppet/util/windows/monkey_patches/process.rb +++ b/lib/puppet/util/windows/monkey_patches/process.rb @@ -197,7 +197,7 @@ def setpriority(kind, int, int_priority) FFI::WIN32.CloseHandle(handle) end - return 0 + 0 end private diff --git a/lib/puppet/util/windows/root_certs.rb b/lib/puppet/util/windows/root_certs.rb index ccacc29e11f..ec0f19ed80d 100644 --- a/lib/puppet/util/windows/root_certs.rb +++ b/lib/puppet/util/windows/root_certs.rb @@ -25,7 +25,7 @@ def each # Returns a new instance. # @return [Puppet::Util::Windows::RootCerts] object constructed from current root certificates def self.instance - new(self.load_certs) + new(load_certs) end # Returns an array of root certificates. diff --git a/lib/puppet/util/windows/sid.rb b/lib/puppet/util/windows/sid.rb index e3d06cc5466..05a1582f93e 100644 --- a/lib/puppet/util/windows/sid.rb +++ b/lib/puppet/util/windows/sid.rb @@ -86,7 +86,7 @@ def name_to_principal(name, allow_unresolved = false) raw_sid_bytes ? Principal.lookup_account_sid(raw_sid_bytes) : Principal.lookup_account_name(name) rescue => e - Puppet.debug("#{e.message}") + Puppet.debug(e.message.to_s) (allow_unresolved && raw_sid_bytes) ? unresolved_principal(name, raw_sid_bytes) : nil end module_function :name_to_principal diff --git a/lib/puppet/util/windows/user.rb b/lib/puppet/util/windows/user.rb index a90a0cf5c41..4e55e0d8d64 100644 --- a/lib/puppet/util/windows/user.rb +++ b/lib/puppet/util/windows/user.rb @@ -13,7 +13,7 @@ def admin? # if Vista or later, check for unrestricted process token elevated_supported = Puppet::Util::Windows::Process.supports_elevated_security? - return elevated_supported ? Puppet::Util::Windows::Process.elevated_security? : true + elevated_supported ? Puppet::Util::Windows::Process.elevated_security? : true end module_function :admin? @@ -84,7 +84,7 @@ def password_is?(name, password, domain = '.') ERROR_ACCOUNT_DISABLED, ] - return authenticated_error_codes.include?(detail.code) + authenticated_error_codes.include?(detail.code) end module_function :password_is? diff --git a/lib/puppet/version.rb b/lib/puppet/version.rb index aa5896a4815..2a7ced2ff30 100644 --- a/lib/puppet/version.rb +++ b/lib/puppet/version.rb @@ -69,7 +69,7 @@ def self.version # @return [String] containing the puppet version to minor specificity, e.g. "3.0" def self.minor_version - self.version.split('.')[0..1].join('.') + version.split('.')[0..1].join('.') end def self.version=(version)