Style/HashSyntax:
EnforcedStyle: hash_rockets
-Style/SingleSpaceBeforeFirstArg:
- Exclude:
- - '**/metadata.rb'
-
Style/StringLiterals:
EnforcedStyle: double_quotes
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
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
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
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"
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}"
:trkpts => "GPX trackpoints calls",
:web => "Web site traffic",
:other => "Other API calls"
-}
+}.freeze
def categorise_uri(line)
uri = line.split(" ")[1]
:trkpts => "GPX trackpoints calls",
:web => "Web site traffic",
:other => "Other API calls"
-}
+}.freeze
if ARGV[0] == "config"
puts "graph_title Requests processed"
"502" => "Bad Gateway",
"503" => "Service Unavailable",
"509" => "Bandwidth Limit Exceeded"
-}
+}.freeze
if ARGV[0] == "config"
puts "graph_title HTTP response codes"
:trkpts => "GPX trackpoints calls",
:web => "Web site traffic",
:other => "Other API calls"
-}
+}.freeze
def categorise_uri(line)
uri = line.split(" ")[1]
: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
@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
if block.nil?
interfaces << interface
else
- block.call(interface)
+ yield interface
end
end
if block.nil?
addresses << interface[:address]
else
- block.call(interface[:address])
+ yield interface[:address]
end
end
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
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"
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
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
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
TABLE_PRIVILEGES = [
:select, :insert, :update, :delete, :truncate, :references, :trigger
- ]
+ ].freeze
def initialize(cluster)
@cluster = cluster
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
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
@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
# 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)
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
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]
@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