summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-07-14 14:26:07 -0700
committerTim Smith <tsmith84@gmail.com>2020-07-14 14:26:07 -0700
commit9a0acef3d6d50c19a75c4bb5159522637297f34a (patch)
tree27452efce8c887e77b7c29d9b3d023dcc2eb0a18
parent0650fb361ae90f067707b3a9cb7f736d104d0650 (diff)
downloadohai-frozen_strings.tar.gz
Some frozen string fixesfrozen_strings
Mostly just switching to String.new, but a bit of refactoring as well. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/aix/virtualization.rb7
-rw-r--r--lib/ohai/plugins/passwd.rb2
-rw-r--r--lib/ohai/plugins/ruby.rb13
-rw-r--r--lib/ohai/plugins/shard.rb2
-rw-r--r--spec/unit/plugins/passwd_spec.rb2
5 files changed, 13 insertions, 13 deletions
diff --git a/lib/ohai/plugins/aix/virtualization.rb b/lib/ohai/plugins/aix/virtualization.rb
index e3a2080b..9db19630 100644
--- a/lib/ohai/plugins/aix/virtualization.rb
+++ b/lib/ohai/plugins/aix/virtualization.rb
@@ -2,7 +2,7 @@
#
# Author:: Julian C. Dunn (<jdunn@chef.io>)
# Author:: Isa Farnik (<isa@chef.io>)
-# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -91,7 +91,7 @@ Ohai.plugin(:Virtualization) do
}
wpars[wpar_name][title][key] = value
when "security settings"
- privileges ||= ""
+ privileges = String.new
wpars[wpar_name][title]["Privileges"] ||= []
if /^Privileges/.match?(line)
@@ -140,7 +140,8 @@ Ohai.plugin(:Virtualization) do
]
top_level.each do |attribute|
- evalstr = "wpars['#{wpar_name}']"
+ evalstr = String.new
+ evalstr << "wpars['#{wpar_name}']"
breadcrumb = attribute.split(".")
breadcrumb.each do |node|
evalstr << "[\'#{node}\']"
diff --git a/lib/ohai/plugins/passwd.rb b/lib/ohai/plugins/passwd.rb
index d86be58e..99e0eff3 100644
--- a/lib/ohai/plugins/passwd.rb
+++ b/lib/ohai/plugins/passwd.rb
@@ -10,7 +10,7 @@ Ohai.plugin(:Passwd) do
# @return [String]
#
def fix_encoding(str)
- str.force_encoding(Encoding.default_external) if str.respond_to?(:force_encoding)
+ str.dup.force_encoding(Encoding.default_external) if str.respond_to?(:force_encoding)
str
end
diff --git a/lib/ohai/plugins/ruby.rb b/lib/ohai/plugins/ruby.rb
index cdfef15a..937082b2 100644
--- a/lib/ohai/plugins/ruby.rb
+++ b/lib/ohai/plugins/ruby.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,8 +23,7 @@ Ohai.plugin(:Ruby) do
def run_ruby(command)
cmd = "ruby -e \"require 'rbconfig'; #{command}\""
- so = shell_out(cmd)
- so.stdout.strip
+ shell_out(cmd).stdout.strip
end
collect_data do
@@ -47,13 +46,13 @@ Ohai.plugin(:Ruby) do
}
# Create a query string from above hash
- env_string = ""
- values.each_key do |v|
- env_string << "#{v}=\#{#{values[v]}},"
+ env_string = []
+ values.each_pair do |k,v|
+ env_string << "#{k}=\#{#{v}}"
end
# Query the system ruby
- result = run_ruby "puts %Q(#{env_string})"
+ result = run_ruby "puts %Q(#{env_string.join(',')})"
# Parse results to plugin hash
result.split(",").each do |entry|
diff --git a/lib/ohai/plugins/shard.rb b/lib/ohai/plugins/shard.rb
index 7c77ac11..3a94b742 100644
--- a/lib/ohai/plugins/shard.rb
+++ b/lib/ohai/plugins/shard.rb
@@ -65,7 +65,7 @@ Ohai.plugin(:ShardSeed) do
# under their collect_data block.
def create_seed(&block)
sources = Ohai.config[:plugin][:shard_seed][:sources] || default_sources
- data = ""
+ data = String.new
sources.each do |src|
data << case src
when :fqdn
diff --git a/spec/unit/plugins/passwd_spec.rb b/spec/unit/plugins/passwd_spec.rb
index bc518c12..2126211f 100644
--- a/spec/unit/plugins/passwd_spec.rb
+++ b/spec/unit/plugins/passwd_spec.rb
@@ -56,7 +56,7 @@ describe Ohai::System, "plugin etc", :unix_only do
if "".respond_to?(:force_encoding)
it "sets the encoding of strings to the default external encoding" do
fields = ["root", 1, 1, "/root", "/bin/zsh", "BOFH"]
- fields.each { |f| f.force_encoding(Encoding::ASCII_8BIT) if f.respond_to?(:force_encoding) }
+ fields.each { |f| f.dup.force_encoding(Encoding::ASCII_8BIT) if f.respond_to?(:force_encoding) }
allow(Etc).to receive(:passwd).and_yield(PasswdEntry.new(*fields))
plugin.run
root = plugin[:etc][:passwd]["root"]