Fix issues reported by new rubocop
authorTom Hughes <tom@compton.nu>
Fri, 15 Jan 2016 23:05:34 +0000 (23:05 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 15 Jan 2016 23:05:34 +0000 (23:05 +0000)
24 files changed:
.rubocop.yml
cookbooks/chef/libraries/edit_file.rb
cookbooks/chef/libraries/random_password.rb
cookbooks/chef/libraries/subversion.rb
cookbooks/hardware/recipes/default.rb
cookbooks/munin/files/default/plugins/api_calls_
cookbooks/munin/files/default/plugins/api_calls_num
cookbooks/munin/files/default/plugins/api_calls_status
cookbooks/munin/files/default/plugins/api_waits_
cookbooks/mysql/libraries/mysql.rb
cookbooks/mysql/providers/database.rb
cookbooks/networking/libraries/interfaces.rb
cookbooks/networking/libraries/ipaddresses.rb
cookbooks/networking/recipes/default.rb
cookbooks/nfs/recipes/default.rb
cookbooks/nfs/recipes/server.rb
cookbooks/nodejs/providers/package.rb
cookbooks/nominatim/recipes/base.rb
cookbooks/postgresql/libraries/postgresql.rb
cookbooks/postgresql/providers/database.rb
cookbooks/postgresql/providers/table.rb
cookbooks/tile/files/default/ruby/expire.rb
cookbooks/web/definitions/rails_port.rb
cookbooks/wordpress/libraries/wordpress.rb

index 2219d6e..23c3f82 100644 (file)
@@ -18,9 +18,5 @@ Style/FileName:
 Style/HashSyntax:
   EnforcedStyle: hash_rockets
 
-Style/SingleSpaceBeforeFirstArg:
-  Exclude:
-    - '**/metadata.rb'
-
 Style/StringLiterals:
   EnforcedStyle: double_quotes
index 6260c8a..bfbec45 100644 (file)
@@ -1,10 +1,10 @@
 class Chef
   module Mixin
     module EditFile
-      def edit_file(file, &block)
+      def edit_file(file, &_block)
         Chef::DelayedEvaluator.new do
           ::File.new(file).collect do |line|
-            block.call(line)
+            yield line
           end.join("")
         end
       end
index f8c6674..71d8bcf 100644 (file)
@@ -1,7 +1,7 @@
 class Chef
   class Recipe
     def random_password(length)
-      length.times.collect do
+      Array.new(length) do
         "!\#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~"[rand(91)].chr
       end.join
     end
index b5ac6f3..dd2c7ec 100644 (file)
@@ -17,20 +17,18 @@ class Chef
       end
 
       def current_repository_matches_target_repository?
-        (!current_repository.nil?) && (@new_resource.repository == current_repository)
+        !current_repository.nil? && (@new_resource.repository == current_repository)
       end
 
       def repo_attrs
         return {} unless ::File.exist?(::File.join(@new_resource.destination, ".svn"))
 
         @repo_attrs ||= svn_info.lines.each_with_object({}) do |line, attrs|
-          if line =~ SVN_INFO_PATTERN
-            property = Regexp.last_match[1]
-            value = Regexp.last_match[2]
-            attrs[property] = value
-          else
-            fail "Could not parse `svn info` data: #{line}"
-          end
+          fail "Could not parse `svn info` data: #{line}" unless line =~ SVN_INFO_PATTERN
+
+          property = Regexp.last_match[1]
+          value = Regexp.last_match[2]
+          attrs[property] = value
         end
       end
 
index 8ba21da..8342a9a 100644 (file)
@@ -297,11 +297,11 @@ end
   end
 end
 
-if node[:hardware][:disk]
-  disks = node[:hardware][:disk][:disks]
-else
-  disks = []
-end
+disks = if node[:hardware][:disk]
+          node[:hardware][:disk][:disks]
+        else
+          []
+        end
 
 disks = disks.map do |disk|
   next if disk[:state] == "spun_down"
@@ -476,15 +476,15 @@ unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
     cpu = File.basename(coretemp).sub("coretemp.", "").to_i
     chip = format("coretemp-isa-%04d", cpu)
 
-    if File.exist?("#{coretemp}/name")
-      temps = Dir.glob("#{coretemp}/temp*_input").map do |temp|
-        File.basename(temp).sub("temp", "").sub("_input", "").to_i
-      end.sort
-    else
-      temps = Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
-        File.basename(temp).sub("temp", "").sub("_input", "").to_i
-      end.sort
-    end
+    temps = if File.exist?("#{coretemp}/name")
+              Dir.glob("#{coretemp}/temp*_input").map do |temp|
+                File.basename(temp).sub("temp", "").sub("_input", "").to_i
+              end.sort
+            else
+              Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
+                File.basename(temp).sub("temp", "").sub("_input", "").to_i
+              end.sort
+            end
 
     if temps.first == 1
       node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
index 158bf90..17bba16 100755 (executable)
@@ -26,7 +26,7 @@ CALL_TYPES = {
   :trkpts => "GPX trackpoints calls",
   :web => "Web site traffic",
   :other => "Other API calls"
-}
+}.freeze
 
 def categorise_uri(line)
   uri = line.split(" ")[1]
index 443af2c..e2f74d9 100755 (executable)
@@ -11,7 +11,7 @@ CALL_TYPES = {
   :trkpts => "GPX trackpoints calls",
   :web => "Web site traffic",
   :other => "Other API calls"
-}
+}.freeze
 
 if ARGV[0] == "config"
   puts "graph_title Requests processed"
index 6d0e619..1f18a45 100755 (executable)
@@ -23,7 +23,7 @@ HTTP_STATUSES = {
   "502" => "Bad Gateway",
   "503" => "Service Unavailable",
   "509" => "Bandwidth Limit Exceeded"
-}
+}.freeze
 
 if ARGV[0] == "config"
   puts "graph_title HTTP response codes"
index d072b89..4921686 100755 (executable)
@@ -26,7 +26,7 @@ CALL_TYPES = {
   :trkpts => "GPX trackpoints calls",
   :web => "Web site traffic",
   :other => "Other API calls"
-}
+}.freeze
 
 def categorise_uri(line)
   uri = line.split(" ")[1]
index 91eb6f9..61d600f 100644 (file)
@@ -11,14 +11,14 @@ class Chef
       :show_db, :super, :create_tmp_table, :lock_tables, :execute,
       :repl_slave, :repl_client, :create_view, :show_view, :create_routine,
       :alter_routine, :create_user, :event, :trigger, :create_tablespace
-    ]
+    ].freeze
 
     DATABASE_PRIVILEGES = [
       :select, :insert, :update, :delete, :create, :drop, :grant,
       :references, :index, :alter, :create_tmp_table, :lock_tables,
       :create_view, :show_view, :create_routine, :alter_routine,
       :execute, :event, :trigger
-    ]
+    ].freeze
 
     def execute(options)
       # Create argument array
index 6e488ce..345ef7e 100644 (file)
@@ -65,12 +65,10 @@ action :create do
             @mysql.execute(:command => "GRANT #{@mysql.privilege_name(privilege)} ON `#{new_resource.database}`.* TO #{user}")
           end
         end
-      else
-        if current_privileges.include?(privilege)
-          converge_by("revoke #{privilege} for #{user} on #{new_resource}") do
-            Chef::Log.info("Revoking #{privilege} for #{user} on #{new_resource}")
-            @mysql.execute(:command => "REVOKE #{@mysql.privilege_name(privilege)} ON `#{new_resource.database}`.* FROM #{user}")
-          end
+      elsif current_privileges.include?(privilege)
+        converge_by("revoke #{privilege} for #{user} on #{new_resource}") do
+          Chef::Log.info("Revoking #{privilege} for #{user} on #{new_resource}")
+          @mysql.execute(:command => "REVOKE #{@mysql.privilege_name(privilege)} ON `#{new_resource.database}`.* FROM #{user}")
         end
       end
     end
index 029cb4f..c2f170b 100644 (file)
@@ -13,7 +13,7 @@ class Chef
         if block.nil?
           interfaces << interface
         else
-          block.call(interface)
+          yield interface
         end
       end
 
index 5eb5426..51ef152 100644 (file)
@@ -7,7 +7,7 @@ class Chef
         if block.nil?
           addresses << interface[:address]
         else
-          block.call(interface[:address])
+          yield interface[:address]
         end
       end
 
index 477a15b..ab139e9 100644 (file)
@@ -35,7 +35,7 @@ node[:networking][:interfaces].each do |name, interface|
 
   prefix = node[:networking][:interfaces][name][:prefix]
 
-  node.set[:networking][:interfaces][name][:netmask] = (~IPAddr.new(interface[:address]).mask(0)).mask(prefix)
+  node.set[:networking][:interfaces][name][:netmask] = ~IPAddr.new(interface[:address]).mask(0).mask(prefix)
   node.set[:networking][:interfaces][name][:network] = IPAddr.new(interface[:address]).mask(prefix)
 end
 
index 8d44e2b..f4c6016 100644 (file)
 package "nfs-common"
 
 node[:nfs].each do |mountpoint, details|
-  if details[:readonly]
-    mount_options = "ro,bg,soft,udp,rsize=8192,wsize=8192,nfsvers=3"
-  else
-    mount_options = "rw,bg,udp,rsize=8192,wsize=8192,nfsvers=3"
-  end
+  mount_options = if details[:readonly]
+                    "ro,bg,soft,udp,rsize=8192,wsize=8192,nfsvers=3"
+                  else
+                    "rw,bg,udp,rsize=8192,wsize=8192,nfsvers=3"
+                  end
 
   directory mountpoint do
     owner "root"
index f75e44e..33e5a31 100644 (file)
@@ -41,11 +41,11 @@ search(:node, "*:*") do |client|
     client.ipaddresses do |address|
       exports[mount[:path]] ||= {}
 
-      if mount[:readonly]
-        exports[mount[:path]][address] = "ro"
-      else
-        exports[mount[:path]][address] = "rw"
-      end
+      exports[mount[:path]][address] = if mount[:readonly]
+                                         "ro"
+                                       else
+                                         "rw"
+                                       end
     end
   end
 end
index 3a33040..4c85273 100644 (file)
@@ -34,21 +34,19 @@ def load_current_resource
 end
 
 action :install do
-  if new_resource.version
-    package_name = "#{new_resource.package_name}@#{new_resource.version}"
-  else
-    package_name = new_resource.package_name
-  end
+  package_name = if new_resource.version
+                   "#{new_resource.package_name}@#{new_resource.version}"
+                 else
+                   new_resource.package_name
+                 end
 
   if !@packages.include?(new_resource.package_name)
     shell_out!("npm install --global #{package_name}")
     new_resource.updated_by_last_action(true)
-  else
-    if new_resource.version &&
-       new_resource.version != @current_resource.version
-      shell_out!("npm install --global #{package_name}")
-      new_resource.updated_by_last_action(true)
-    end
+  elsif new_resource.version &&
+        new_resource.version != @current_resource.version
+    shell_out!("npm install --global #{package_name}")
+    new_resource.updated_by_last_action(true)
   end
 end
 
index c8e9966..8721ef0 100644 (file)
@@ -158,11 +158,11 @@ file "#{source_directory}/settings/ip_blocks.map" do
   mode 0664
 end
 
-if node[:nominatim][:enabled]
-  cron_action = :create
-else
-  cron_action = :delete
-end
+cron_action = if node[:nominatim][:enabled]
+                :create
+              else
+                :delete
+              end
 
 template "/etc/cron.d/nominatim" do
   action cron_action
index 6960ec9..266a7b8 100644 (file)
@@ -6,7 +6,7 @@ class Chef
 
     TABLE_PRIVILEGES = [
       :select, :insert, :update, :delete, :truncate, :references, :trigger
-    ]
+    ].freeze
 
     def initialize(cluster)
       @cluster = cluster
@@ -118,7 +118,7 @@ class Chef
         permissions[user] = {
           "a" => :insert, "r" => :select, "w" => :update, "d" => :delete,
           "D" => :truncate, "x" => :references, "t" => :trigger
-        }.values_at(*(privileges.chars)).compact
+        }.values_at(*privileges.chars).compact
       end
     end
   end
index 3170431..a3a7cbc 100644 (file)
@@ -36,11 +36,9 @@ action :create do
   if !@pg.databases.include?(new_resource.database)
     @pg.execute(:command => "CREATE DATABASE \"#{new_resource.database}\" OWNER \"#{new_resource.owner}\" TEMPLATE template0 ENCODING '#{new_resource.encoding}' LC_COLLATE '#{new_resource.collation}' LC_CTYPE '#{new_resource.ctype}'")
     new_resource.updated_by_last_action(true)
-  else
-    if new_resource.owner != @current_resource.owner
-      @pg.execute(:command => "ALTER DATABASE \"#{new_resource.database}\" OWNER TO \"#{new_resource.owner}\"")
-      new_resource.updated_by_last_action(true)
-    end
+  elsif new_resource.owner != @current_resource.owner
+    @pg.execute(:command => "ALTER DATABASE \"#{new_resource.database}\" OWNER TO \"#{new_resource.owner}\"")
+    new_resource.updated_by_last_action(true)
   end
 end
 
index f162347..b1dc675 100644 (file)
@@ -67,12 +67,10 @@ action :create do
               @pg.execute(:command => "GRANT #{privilege.to_s.upcase} ON #{@name} TO \"#{user}\"", :database => new_resource.database)
             end
           end
-        else
-          if current_privileges.include?(privilege)
-            converge_by("revoke #{privilege} for #{user} on #{new_resource}") do
-              Chef::Log.info("Revoking #{privilege} for #{user} on #{new_resource}")
-              @pg.execute(:command => "REVOKE #{privilege.to_s.upcase} ON #{@name} FROM \"#{user}\"", :database => new_resource.database)
-            end
+        elsif current_privileges.include?(privilege)
+          converge_by("revoke #{privilege} for #{user} on #{new_resource}") do
+            Chef::Log.info("Revoking #{privilege} for #{user} on #{new_resource}")
+            @pg.execute(:command => "REVOKE #{privilege.to_s.upcase} ON #{@name} FROM \"#{user}\"", :database => new_resource.database)
           end
         end
       end
index d695a0b..8a212aa 100755 (executable)
@@ -18,9 +18,9 @@ module Expire
   # the size of the meta tile blocks
   METATILE = 8
   # the directory root for meta tiles
-  HASH_ROOT = "/tiles/default/"
+  HASH_ROOT = "/tiles/default/".freeze
   # node cache file
-  NODE_CACHE_FILE = "/store/database/nodes"
+  NODE_CACHE_FILE = "/store/database/nodes".freeze
 
   # turns a spherical mercator coord into a tile coord
   def self.tile_from_merc(point, zoom)
@@ -143,7 +143,7 @@ module Expire
     set = Set.new nodes.values
 
     # expire tiles and shrink to the set of parents
-    (max_zoom).downto(min_zoom) do |_|
+    max_zoom.downto(min_zoom) do |_|
       # allow the block to work on the set, returning the set at the next
       # zoom level
       set = yield set
index f3d89d0..79a9cc8 100644 (file)
@@ -145,7 +145,7 @@ define :rails_port, :action => [:create, :enable] do
     end
 
     if params[:memcache_servers]
-      line.gsub!(/^( *)#memcache_servers:.*$/, "\\1memcache_servers: [ \"#{params[:memcache_servers].join("\", \"")}\" ]")
+      line.gsub!(/^( *)#memcache_servers:.*$/, "\\1memcache_servers: [ \"#{params[:memcache_servers].join('", "')}\" ]")
     end
 
     if params[:potlatch2_key]
index f4f17e2..a381ecf 100644 (file)
@@ -7,37 +7,39 @@ class Chef
     @api_responses = {}
     @svn_responses = {}
 
-    def self.current_version
-      core_version_check["offers"].first["current"]
-    end
+    class << self
+      def current_version
+        core_version_check["offers"].first["current"]
+      end
 
-    def self.current_plugin_version(name)
-      if svn_cat("http://plugins.svn.wordpress.org/#{name}/trunk/readme.txt") =~ /Stable tag:\s*([^\s\r]*)[\s\r]*/
-        Regexp.last_match[1]
-      else
-        "trunk"
+      def current_plugin_version(name)
+        if svn_cat("http://plugins.svn.wordpress.org/#{name}/trunk/readme.txt") =~ /Stable tag:\s*([^\s\r]*)[\s\r]*/
+          Regexp.last_match[1]
+        else
+          "trunk"
+        end
       end
-    end
 
-    private
+      private
 
-    def self.core_version_check
-      api_get("http://api.wordpress.org/core/version-check/1.6")
-    end
+      def core_version_check
+        api_get("http://api.wordpress.org/core/version-check/1.6")
+      end
 
-    def self.api_get(url)
-      @api_responses[url] ||= ::PHP.unserialize(::HTTPClient.new.get_content(url))
-    end
+      def api_get(url)
+        @api_responses[url] ||= ::PHP.unserialize(::HTTPClient.new.get_content(url))
+      end
 
-    def self.svn_cat(url)
-      unless @svn_responses[url]
-        status, stdout, stderr = output_of_command("svn cat #{url}", {})
-        handle_command_failures(status, "STDOUT: #{stdout}\nSTDERR: #{stderr}", :output_on_failure => true)
+      def svn_cat(url)
+        unless @svn_responses[url]
+          status, stdout, stderr = output_of_command("svn cat #{url}", {})
+          handle_command_failures(status, "STDOUT: #{stdout}\nSTDERR: #{stderr}", :output_on_failure => true)
 
-        @svn_responses[url] = stdout.force_encoding("UTF-8")
-      end
+          @svn_responses[url] = stdout.force_encoding("UTF-8")
+        end
 
-      @svn_responses[url]
+        @svn_responses[url]
+      end
     end
   end
 end