From 03f89ec2cc7aa969bd4bd6e898316eaa010ebf26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= Date: Wed, 20 Jul 2016 09:29:50 +0200 Subject: [PATCH] Add more directories under rubocop's control MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- .rubocop.yml | 4 --- bin/bundle | 4 +-- bin/client.rb | 37 +++++++++++++--------- bin/generate_test_data.rb | 8 ++--- bin/rails | 12 ++++--- bin/rake | 10 ++++-- bin/setup | 18 +++++------ bin/spring | 12 ++++--- config/environments/production.rb | 3 +- config/environments/staging.rb | 3 +- config/initializers/assets.rb | 2 +- config/initializers/backtrace_silencers.rb | 6 ++-- config/initializers/devise.rb | 6 ++-- config/initializers/mailer_url_options.rb | 6 ++-- config/initializers/version.rb | 12 ++++--- 15 files changed, 81 insertions(+), 62 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 13d605ef3..6dd9355a5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -38,8 +38,4 @@ AllCops: # default config of rubocop. - db/schema.rb - db/migrate/* - - bin/* - vendor/**/* - - tmp/**/* - - config/initializers/* - - config/environments/* diff --git a/bin/bundle b/bin/bundle index 66e9889e8..fe1874509 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -load Gem.bin_path('bundler', 'bundle') +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__) +load Gem.bin_path("bundler", "bundle") diff --git a/bin/client.rb b/bin/client.rb index 19a8a7e35..dc6afb15e 100644 --- a/bin/client.rb +++ b/bin/client.rb @@ -11,6 +11,25 @@ require "pp" +# Returns a boolean depending on what the user instructed to the ping +# command. If the arguments are not what we expect, then it prints an error +# message and exits the program. +def use_ssl? + use = false + + if ARGV.size == 2 + puts "Beware: use_ssl omitted, assuming false." + elsif ARGV.size == 3 + use = ARGV.last == "use_ssl" + puts "Beware: use \"use_ssl\", assuming false." unless use + else + puts "Usage: rails runner ping hostname:port [use_ssl]" + exit 1 + end + + use +end + registry = Registry.get if registry.nil? && ARGV.first != "ping" puts "No registry has been configured!" @@ -43,7 +62,8 @@ if ARGV[1].include?(":") name, tag = ARGV[1].split(":") else - name, tag = ARGV[1], "latest" + name = ARGV[1] + tag = "latest" end id, digest, manifest = registry.client.manifest(name, tag) @@ -52,20 +72,7 @@ puts JSON.pretty_generate(manifest) when "ping" # No registry was found, trying to ping another one. - if registry.nil? - if ARGV.size == 2 - use_ssl = false - puts "Beware: use_ssl omitted, assuming false." - elsif ARGV.size == 3 - use_ssl = ARGV.last == "use_ssl" - puts "Beware: use \"use_ssl\", assuming false." unless use_ssl - else - puts "Usage: rails runner ping hostname:port [use_ssl]" - exit 1 - end - - registry = Registry.new(hostname: ARGV[1], use_ssl: use_ssl) - end + registry = Registry.new(hostname: ARGV[1], use_ssl: use_ssl?) if registry.nil? if registry.client.reachable? puts "Registry reachable" diff --git a/bin/generate_test_data.rb b/bin/generate_test_data.rb index b6637f265..d0d1c6d9e 100644 --- a/bin/generate_test_data.rb +++ b/bin/generate_test_data.rb @@ -8,7 +8,7 @@ class TestData NUSERS = 100 # Name of the only user that is not created with a random name. - SPECIAL_USER = "admin" + SPECIAL_USER = "admin".freeze # Teams to be created. TEAM_NAMES = [ @@ -22,7 +22,7 @@ class TestData "security", "sitereliability", "ui" - ] + ].freeze # Create some random users + the admin. def create_users! @@ -129,7 +129,8 @@ def push_images! exit 1 end -hostname, ssl = ARGV.first.chomp, ARGV.last.chomp.downcase +hostname = ARGV.first.chomp +ssl = ARGV.last.chomp.downcase ssl = ssl == "y" || ssl == "yes" || ssl == "t" || ssl == "true" unless Rails.env.development? @@ -156,7 +157,6 @@ def push_images! admin: true ) - # # Generate test data. # diff --git a/bin/rails b/bin/rails index 62687aa33..0e5736861 100755 --- a/bin/rails +++ b/bin/rails @@ -1,8 +1,12 @@ #!/usr/bin/env ruby + +# rubocop:disable Lint/HandleExceptions begin - load File.expand_path('../spring', __FILE__) + load File.expand_path("../spring", __FILE__) rescue LoadError end -APP_PATH = File.expand_path('../../config/application', __FILE__) -require_relative '../config/boot' -require 'rails/commands' +# rubocop:enable Lint/HandleExceptions + +APP_PATH = File.expand_path("../../config/application", __FILE__) +require_relative "../config/boot" +require "rails/commands" diff --git a/bin/rake b/bin/rake index 2e9ece45c..a9209c892 100755 --- a/bin/rake +++ b/bin/rake @@ -1,8 +1,12 @@ #!/usr/bin/env ruby + +# rubocop:disable Lint/HandleExceptions begin - load File.expand_path('../spring', __FILE__) + load File.expand_path("../spring", __FILE__) rescue LoadError end -require_relative '../config/boot' -require 'rake' +# rubocop:enable Lint/HandleExceptions + +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/bin/setup b/bin/setup index 00ce4d30a..67e27f0a4 100755 --- a/bin/setup +++ b/bin/setup @@ -1,16 +1,16 @@ #!/usr/bin/env ruby -require 'pathname' +require "pathname" # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path("../../", __FILE__) Dir.chdir APP_ROOT do # This script is a starting point to setup your application. # Add necessary setup steps to this file: - puts '== Installing dependencies ==' - system 'gem install bundler --conservative' - system 'bundle check || bundle install' + puts "== Installing dependencies ==" + system "gem install bundler --conservative" + system "bundle check || bundle install" # puts "\n== Copying sample files ==" # unless File.exist?("config/database.yml") @@ -18,12 +18,12 @@ Dir.chdir APP_ROOT do # end puts "\n== Preparing database ==" - system 'bin/rake db:setup' + system "bin/rake db:setup" puts "\n== Removing old logs and tempfiles ==" - system 'rm -f log/*' - system 'rm -rf tmp/cache' + system "rm -f log/*" + system "rm -rf tmp/cache" puts "\n== Restarting application server ==" - system 'touch tmp/restart.txt' + system "touch tmp/restart.txt" end diff --git a/bin/spring b/bin/spring index 38ea0459d..6bd13be6b 100755 --- a/bin/spring +++ b/bin/spring @@ -4,12 +4,14 @@ # It gets overwritten when you run the `spring binstub` command. unless defined?(Spring) - require 'rubygems' - require 'bundler' + require "rubygems" + require "bundler" + # rubocop:disable Lint/AssignmentInCondition: if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m) - Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq } - gem 'spring', match[1] - require 'spring/binstub' + Gem.paths = { "GEM_PATH" => [Bundler.bundle_path.to_s, *Gem.path].uniq } + gem "spring", match[1] + require "spring/binstub" end + # rubocop:enable Lint/AssignmentInCondition: end diff --git a/config/environments/production.rb b/config/environments/production.rb index 809411a4d..2a796a64d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -35,7 +35,8 @@ # yet still be able to expire them through the digest params. config.assets.digest = true - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # `config.assets.precompile` and `config.assets.version` + # have moved to config/initializers/assets.rb # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 809411a4d..2a796a64d 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -35,7 +35,8 @@ # yet still be able to expire them through the digest params. config.assets.digest = true - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # `config.assets.precompile` and `config.assets.version` + # have moved to config/initializers/assets.rb # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index bd1387a10..a327d26d8 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,2 +1,2 @@ Rails.application.config.assets.version = "1.0" -Rails.application.config.assets.precompile += %w( auth/cover.js *.woff2 ) +Rails.application.config.assets.precompile += %w(auth/cover.js *.woff2) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cdf3..6413347a8 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,7 +1,9 @@ # Be sure to restart your server when you modify this file. -# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# You can add backtrace silencers for libraries that you're using but don't wish +# to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# You can also remove all the silencers if you're trying to debug a problem that +# might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 1b44f5595..950fb3557 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -4,7 +4,7 @@ # The secret key used by Devise. Devise uses this key to generate # random tokens. Changing this key will render invalid all existing # confirmation, reset password and unlock tokens in the database. - # config.secret_key = '12e07627921e47f083bbf7a805302f1ae7644cb8a55e5a22e55e55132e08aa6ab451f638fccf869c074fb77249e9cb8510093453ff76e230dd36fba0f3606e1f' + # config.secret_key = 'randomstring' # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, @@ -98,7 +98,7 @@ config.stretches = Rails.env.test? ? 1 : 10 # Setup a pepper to generate the encrypted password. - # config.pepper = '19384276bf95fb12cedef769c63ccc7e776004b9aac1fac3cdec70d08846a2cd339451d625712575d3e7fa64a65394a1e0d7d04fcaf8d5db228522139d4438eb' + # config.pepper = 'randomstring' # ==> Configuration for :confirmable # A period that the user is allowed to access the website even without @@ -177,7 +177,7 @@ config.maximum_attempts = 10 # Time interval to unlock the account if :time is enabled as unlock_strategy. - config.unlock_in = 5.hour + config.unlock_in = 5.hours # Warn on the last attempt before the account is locked. # config.last_attempt_warning = true diff --git a/config/initializers/mailer_url_options.rb b/config/initializers/mailer_url_options.rb index d33ec344e..06c8e69a2 100644 --- a/config/initializers/mailer_url_options.rb +++ b/config/initializers/mailer_url_options.rb @@ -1,10 +1,10 @@ # If you're on staging/production, then you must be using SSL. Otherwise, if # you're on development mode and you have set your own FQDN, then we assume # that SSL is in place too. Otherwise, SSL is not setup. -if !Rails.env.development? || !ENV["PORTUS_USE_SSL"].nil? - protocol = "https://" +protocol = if !Rails.env.development? || !ENV["PORTUS_USE_SSL"].nil? + "https://" else - protocol = "http://" + "http://" end host = APP_CONFIG["machine_fqdn"]["value"] diff --git a/config/initializers/version.rb b/config/initializers/version.rb index ee6ab7b90..dcf12ce55 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -6,7 +6,7 @@ module Version # otherwise. def self.git? # Check that the ".git" directory at least exists. - return false unless File.exists?(Rails.root.join(".git")) + return false unless File.exist?(Rails.root.join(".git")) # Check whether we have git in our system. paths = ENV["PATH"].split(":") @@ -14,24 +14,26 @@ def self.git? false end - BRANCH = Version.git? ? `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3 2>/dev/null`.chomp : nil COMMIT = Version.git? ? `git log --pretty=format:'%h' -n 1 2>/dev/null`.chomp : nil TAG = Version.git? ? `git tag --points-at $(git rev-parse HEAD) 2>/dev/null`.chomp : nil + BRANCH = if Version.git? + `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3 2>/dev/null`.chomp + end # Version.value returns the app version # Priority: git tag > git branch/commit > VERSION file def self.value if TAG.present? - "#{TAG}" + TAG.to_s elsif COMMIT.present? if BRANCH.present? "#{BRANCH}@#{COMMIT}" else - "#{COMMIT}" + COMMIT.to_s end else version = Rails.root.join("VERSION") - File.read(version).chomp if File.exists?(version) + File.read(version).chomp if File.exist?(version) end end end