diff options
author | 007lva <007.lva@gmail.com> | 2020-09-24 23:08:12 +0200 |
---|---|---|
committer | 007lva <007.lva@gmail.com> | 2020-09-24 23:08:52 +0200 |
commit | 6ecacec32423b116e64fdcc11be0e8e18ce94706 (patch) | |
tree | ea00b3aa4389335922f42b6e22aa6921f64ad070 /lib/chef | |
parent | a1e8747af72cf91a7b5a729db647e158f46ad01f (diff) | |
download | chef-6ecacec32423b116e64fdcc11be0e8e18ce94706.tar.gz |
Use Ruby 2.6 endless Range syntax
Signed-off-by: Luigi <007.lva@gmail.com>
Diffstat (limited to 'lib/chef')
28 files changed, 33 insertions, 33 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb index 4ffbcde1c0..117f498831 100644 --- a/lib/chef/application.rb +++ b/lib/chef/application.rb @@ -172,7 +172,7 @@ class Chef def configure_logging configure_log_location logger.init(MonoLogger.new(chef_config[:log_location][0])) - chef_config[:log_location][1..-1].each do |log_location| + chef_config[:log_location][1..].each do |log_location| logger.loggers << MonoLogger.new(log_location) end logger.level = resolve_log_level diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index d7541a592e..eeeb96e38b 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -265,7 +265,7 @@ class Chef @memory_store.get(path) elsif path[0] == "file_store" && path[1] == "repo" - entry = Chef::ChefFS::FileSystem.resolve_path(chef_fs, path[2..-1].join("/")) + entry = Chef::ChefFS::FileSystem.resolve_path(chef_fs, path[2..].join("/")) begin entry.read rescue Chef::ChefFS::FileSystem::NotFoundError => e diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb index d01d24c360..d28bb65db6 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb @@ -64,7 +64,7 @@ class Chef if is_dir return recursive && name != "." && name != ".." elsif ruby_only - return false if name[-3..-1] != ".rb" + return false if name[-3..] != ".rb" end # Check chefignore diff --git a/lib/chef/cookbook/gem_installer.rb b/lib/chef/cookbook/gem_installer.rb index b652e5dee0..d7c18627de 100644 --- a/lib/chef/cookbook/gem_installer.rb +++ b/lib/chef/cookbook/gem_installer.rb @@ -47,7 +47,7 @@ class Chef v2 end end - cookbook_gems[args.first] += args[1..-1] + cookbook_gems[args.first] += args[1..] end end diff --git a/lib/chef/file_content_management/tempfile.rb b/lib/chef/file_content_management/tempfile.rb index 763648de33..27efe34191 100644 --- a/lib/chef/file_content_management/tempfile.rb +++ b/lib/chef/file_content_management/tempfile.rb @@ -76,7 +76,7 @@ class Chef # complexity here is due to supporting mangling non-UTF8 strings (e.g. latin-1 filenames with characters that are illegal in UTF-8) b = File.basename(@new_resource.path) i = b.index(".") - i.nil? ? "" : b[i..-1].scrub + i.nil? ? "" : b[i..].scrub end # Returns the possible directories for the tempfile to be created in. diff --git a/lib/chef/formatters/indentable_output_stream.rb b/lib/chef/formatters/indentable_output_stream.rb index c2d835d951..4943041b37 100644 --- a/lib/chef/formatters/indentable_output_stream.rb +++ b/lib/chef/formatters/indentable_output_stream.rb @@ -126,7 +126,7 @@ class Chef indent_line(options) # Note that the next line will need to be started - if line[-1..-1] == "\n" + if line[-1..] == "\n" @line_started = false end diff --git a/lib/chef/knife/node_policy_set.rb b/lib/chef/knife/node_policy_set.rb index cfbae1ff6f..d34ebd9478 100644 --- a/lib/chef/knife/node_policy_set.rb +++ b/lib/chef/knife/node_policy_set.rb @@ -45,7 +45,7 @@ class Chef # Set policy name and group to node def set_policy(node) - policy_group, policy_name = @name_args[1..-1] + policy_group, policy_name = @name_args[1..] node.policy_name = policy_name node.policy_group = policy_group end @@ -70,7 +70,7 @@ class Chef # True if one of policy_name or policy_group was given, but not both def incomplete_policyfile_options? - policy_group, policy_name = @name_args[1..-1] + policy_group, policy_name = @name_args[1..] (policy_group.nil? || policy_name.nil? || @name_args[1..-1].size > 2) end diff --git a/lib/chef/knife/node_run_list_add.rb b/lib/chef/knife/node_run_list_add.rb index ac5f09bae9..40476371eb 100644 --- a/lib/chef/knife/node_run_list_add.rb +++ b/lib/chef/knife/node_run_list_add.rb @@ -43,7 +43,7 @@ class Chef node = Chef::Node.load(@name_args[0]) if @name_args.size > 2 # Check for nested lists and create a single plain one - entries = @name_args[1..-1].map do |entry| + entries = @name_args[1..].map do |entry| entry.split(",").map(&:strip) end.flatten else diff --git a/lib/chef/knife/node_run_list_remove.rb b/lib/chef/knife/node_run_list_remove.rb index 08f4e5d382..484e575475 100644 --- a/lib/chef/knife/node_run_list_remove.rb +++ b/lib/chef/knife/node_run_list_remove.rb @@ -34,7 +34,7 @@ class Chef if @name_args.size > 2 # Check for nested lists and create a single plain one - entries = @name_args[1..-1].map do |entry| + entries = @name_args[1..].map do |entry| entry.split(",").map(&:strip) end.flatten else diff --git a/lib/chef/knife/node_run_list_set.rb b/lib/chef/knife/node_run_list_set.rb index eae05003ff..f356b39d95 100644 --- a/lib/chef/knife/node_run_list_set.rb +++ b/lib/chef/knife/node_run_list_set.rb @@ -36,7 +36,7 @@ class Chef exit 1 elsif @name_args.size > 2 # Check for nested lists and create a single plain one - entries = @name_args[1..-1].map do |entry| + entries = @name_args[1..].map do |entry| entry.split(",").map(&:strip) end.flatten else diff --git a/lib/chef/knife/role_env_run_list_add.rb b/lib/chef/knife/role_env_run_list_add.rb index 1fc8ef1e74..b5753b46fc 100644 --- a/lib/chef/knife/role_env_run_list_add.rb +++ b/lib/chef/knife/role_env_run_list_add.rb @@ -68,7 +68,7 @@ class Chef if @name_args.size > 2 # Check for nested lists and create a single plain one - entries = @name_args[2..-1].map do |entry| + entries = @name_args[2..].map do |entry| entry.split(",").map(&:strip) end.flatten else diff --git a/lib/chef/knife/role_env_run_list_set.rb b/lib/chef/knife/role_env_run_list_set.rb index d9294b9bc4..0f1ce62a5d 100644 --- a/lib/chef/knife/role_env_run_list_set.rb +++ b/lib/chef/knife/role_env_run_list_set.rb @@ -51,7 +51,7 @@ class Chef exit 1 elsif @name_args.size > 2 # Check for nested lists and create a single plain one - entries = @name_args[2..-1].map do |entry| + entries = @name_args[2..].map do |entry| entry.split(",").map(&:strip) end.flatten else diff --git a/lib/chef/knife/role_run_list_add.rb b/lib/chef/knife/role_run_list_add.rb index 5ed91d5d49..76633ff5f6 100644 --- a/lib/chef/knife/role_run_list_add.rb +++ b/lib/chef/knife/role_run_list_add.rb @@ -68,7 +68,7 @@ class Chef if @name_args.size > 1 # Check for nested lists and create a single plain one - entries = @name_args[1..-1].map do |entry| + entries = @name_args[1..].map do |entry| entry.split(",").map(&:strip) end.flatten else diff --git a/lib/chef/knife/role_run_list_set.rb b/lib/chef/knife/role_run_list_set.rb index 7302797c33..ad1a5e2923 100644 --- a/lib/chef/knife/role_run_list_set.rb +++ b/lib/chef/knife/role_run_list_set.rb @@ -50,7 +50,7 @@ class Chef exit 1 elsif @name_args.size > 1 # Check for nested lists and create a single plain one - entries = @name_args[1..-1].map do |entry| + entries = @name_args[1..].map do |entry| entry.split(",").map(&:strip) end.flatten else diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index a6428d9726..a586bf37c2 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -489,7 +489,7 @@ class Chef new_window_cmds = lambda do if session.servers_for.size > 1 - [""] + session.servers_for[1..-1].map do |server| + [""] + session.servers_for[1..].map do |server| if config[:tmux_split] "split-window #{ssh_dest.call(server)}; tmux select-layout tiled" else @@ -625,7 +625,7 @@ class Chef when "cssh" cssh else - ssh_command(@name_args[1..-1].join(" ")) + ssh_command(@name_args[1..].join(" ")) end session.close diff --git a/lib/chef/knife/tag_create.rb b/lib/chef/knife/tag_create.rb index fe357981b7..2f0d302e74 100644 --- a/lib/chef/knife/tag_create.rb +++ b/lib/chef/knife/tag_create.rb @@ -32,7 +32,7 @@ class Chef def run name = @name_args[0] - tags = @name_args[1..-1] + tags = @name_args[1..] if name.nil? || tags.nil? || tags.empty? show_usage diff --git a/lib/chef/knife/tag_delete.rb b/lib/chef/knife/tag_delete.rb index 1c9f2185d7..85fa6a9e27 100644 --- a/lib/chef/knife/tag_delete.rb +++ b/lib/chef/knife/tag_delete.rb @@ -32,7 +32,7 @@ class Chef def run name = @name_args[0] - tags = @name_args[1..-1] + tags = @name_args[1..] if name.nil? || tags.nil? || tags.empty? show_usage diff --git a/lib/chef/mixin/template.rb b/lib/chef/mixin/template.rb index a369cae9e5..dcb728f964 100644 --- a/lib/chef/mixin/template.rb +++ b/lib/chef/mixin/template.rb @@ -204,7 +204,7 @@ class Chef all_ivars.delete(:@_extension_modules) all_ivars.inject({}) do |ivar_map, ivar_symbol_name| value = instance_variable_get(ivar_symbol_name) - name_without_at = ivar_symbol_name.to_s[1..-1].to_sym + name_without_at = ivar_symbol_name.to_s[1..].to_sym ivar_map[name_without_at] = value ivar_map end diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb index c1d621a77e..0b85dbe9df 100644 --- a/lib/chef/node_map.rb +++ b/lib/chef/node_map.rb @@ -225,13 +225,13 @@ class Chef if attribute == :platform_family # If any blocklist value matches, we don't match - return false if blocklist.any? { |v| v[1..-1] == value || platform_family_query_helper?(node, v[1..-1]) } + return false if blocklist.any? { |v| v[1..] == value || platform_family_query_helper?(node, v[1..]) } # If the allowlist is empty, or anything matches, we match. allowlist.empty? || allowlist.any? { |v| v == :all || v == value || platform_family_query_helper?(node, v) } else # If any blocklist value matches, we don't match - return false if blocklist.any? { |v| v[1..-1] == value } + return false if blocklist.any? { |v| v[1..] == value } # If the allowlist is empty, or anything matches, we match. allowlist.empty? || allowlist.any? { |v| v == :all || v == value } diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb index 60b89a8094..4d5631397b 100644 --- a/lib/chef/provider.rb +++ b/lib/chef/provider.rb @@ -88,7 +88,7 @@ class Chef def self.use(partial) dirname = ::File.dirname(partial) basename = ::File.basename(partial, ".rb") - basename = basename[1..-1] if basename.start_with?("_") + basename = basename[1..] if basename.start_with?("_") class_eval IO.read(::File.expand_path("#{dirname}/_#{basename}.rb", ::File.dirname(caller_locations.first.absolute_path))) end diff --git a/lib/chef/provider/service/redhat.rb b/lib/chef/provider/service/redhat.rb index 3ef7110002..14b55bef85 100644 --- a/lib/chef/provider/service/redhat.rb +++ b/lib/chef/provider/service/redhat.rb @@ -84,7 +84,7 @@ class Chef chkconfig = shell_out!("/sbin/chkconfig --list #{current_resource.service_name}", returns: [0, 1]) unless run_levels.nil? || run_levels.empty? all_levels_match = true - chkconfig.stdout.split(/\s+/)[1..-1].each do |level| + chkconfig.stdout.split(/\s+/)[1..].each do |level| index = level.split(":").first status = level.split(":").last if CHKCONFIG_ON.match?(level) diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index 2a7300c017..7b266b8d62 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -584,7 +584,7 @@ in 'password', with the associated 'salt' and 'iterations'.") # def run_dscl(*args) - result = shell_out("dscl", ".", "-#{args[0]}", args[1..-1]) + result = shell_out("dscl", ".", "-#{args[0]}", args[1..]) return "" if ( args.first =~ /^delete/ ) && ( result.exitstatus != 0 ) raise(Chef::Exceptions::DsclCommandFailed, "dscl error: #{result.inspect}") unless result.exitstatus == 0 raise(Chef::Exceptions::DsclCommandFailed, "dscl error: #{result.inspect}") if result.stdout.include?("No such key: ") @@ -593,7 +593,7 @@ in 'password', with the associated 'salt' and 'iterations'.") end def run_plutil(*args) - result = shell_out("plutil", "-#{args[0]}", args[1..-1]) + result = shell_out("plutil", "-#{args[0]}", args[1..]) raise(Chef::Exceptions::PlistUtilCommandFailed, "plutil error: #{result.inspect}") unless result.exitstatus == 0 if result.stdout.encoding == Encoding::ASCII_8BIT diff --git a/lib/chef/provider/user/mac.rb b/lib/chef/provider/user/mac.rb index a738fa4aa0..a3980aa12f 100644 --- a/lib/chef/provider/user/mac.rb +++ b/lib/chef/provider/user/mac.rb @@ -608,7 +608,7 @@ class Chef end def run_dscl(*args) - result = shell_out("dscl", "-plist", ".", "-#{args[0]}", args[1..-1]) + result = shell_out("dscl", "-plist", ".", "-#{args[0]}", args[1..]) return "" if ( args.first =~ /^delete/ ) && ( result.exitstatus != 0 ) raise(Chef::Exceptions::DsclCommandFailed, "dscl error: #{result.inspect}") unless result.exitstatus == 0 raise(Chef::Exceptions::DsclCommandFailed, "dscl error: #{result.inspect}") if /No such key: /.match?(result.stdout) @@ -617,7 +617,7 @@ class Chef end def run_plutil(*args) - result = shell_out("plutil", "-#{args[0]}", args[1..-1]) + result = shell_out("plutil", "-#{args[0]}", args[1..]) raise(Chef::Exceptions::PlistUtilCommandFailed, "plutil error: #{result.inspect}") unless result.exitstatus == 0 result.stdout diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 2e5b17f277..e572f0667d 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -1480,7 +1480,7 @@ class Chef def self.use(partial) dirname = ::File.dirname(partial) basename = ::File.basename(partial, ".rb") - basename = basename[1..-1] if basename.start_with?("_") + basename = basename[1..] if basename.start_with?("_") class_eval IO.read(::File.expand_path("#{dirname}/_#{basename}.rb", ::File.dirname(caller_locations.first.absolute_path))) end diff --git a/lib/chef/resource/apt_repository.rb b/lib/chef/resource/apt_repository.rb index e4569561fc..ac15486d97 100644 --- a/lib/chef/resource/apt_repository.rb +++ b/lib/chef/resource/apt_repository.rb @@ -168,7 +168,7 @@ class Chef # is the provided ID a key ID from a keyserver. Looks at length and HEX only values # @param [String] id the key value passed by the user that *may* be an ID def is_key_id?(id) - id = id[2..-1] if id.start_with?("0x") + id = id[2..] if id.start_with?("0x") id =~ /^\h+$/ && [8, 16, 40].include?(id.length) end diff --git a/lib/chef/util/backup.rb b/lib/chef/util/backup.rb index 5728dcaedd..e739488fb9 100644 --- a/lib/chef/util/backup.rb +++ b/lib/chef/util/backup.rb @@ -36,7 +36,7 @@ class Chef slice_number = @new_resource.backup backup_files = sorted_backup_files if backup_files.length >= @new_resource.backup - remainder = backup_files.slice(slice_number..-1) + remainder = backup_files.slice(slice_number..) remainder.each do |backup_to_delete| delete_backup(backup_to_delete) end diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb index e898144414..55fc2461e8 100644 --- a/lib/chef/win32/file.rb +++ b/lib/chef/win32/file.rb @@ -124,7 +124,7 @@ class Chef # Return the link destination (strip off \??\ at the beginning, which is a local filesystem thing) link_dest = reparse_buffer.reparse_buffer.substitute_name if /^\\\?\?\\/.match?(link_dest) - link_dest = link_dest[4..-1] + link_dest = link_dest[4..] end link_dest end diff --git a/lib/chef/win32/unicode.rb b/lib/chef/win32/unicode.rb index f6e97737de..731fe2fbd9 100644 --- a/lib/chef/win32/unicode.rb +++ b/lib/chef/win32/unicode.rb @@ -40,7 +40,7 @@ module FFI last_char = nil while last_char != "\000\000" length += 1 - last_char = get_bytes(0, length * 2)[-2..-1] + last_char = get_bytes(0, length * 2)[-2..] end num_wchars = length |