Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #999 from mssola/more-rubocop
Browse files Browse the repository at this point in the history
Add more directories under rubocop's control
  • Loading branch information
monstermunchkin authored Jul 20, 2016
2 parents 3c389d6 + 03f89ec commit 2f5b7d0
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 62 deletions.
4 changes: 0 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,4 @@ AllCops:
# default config of rubocop.
- db/schema.rb
- db/migrate/*
- bin/*
- vendor/**/*
- tmp/**/*
- config/initializers/*
- config/environments/*
4 changes: 2 additions & 2 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -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")
37 changes: 22 additions & 15 deletions bin/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down Expand Up @@ -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)
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions bin/generate_test_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -22,7 +22,7 @@ class TestData
"security",
"sitereliability",
"ui"
]
].freeze

# Create some random users + the admin.
def create_users!
Expand Down Expand Up @@ -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?
Expand All @@ -156,7 +157,6 @@ def push_images!
admin: true
)


#
# Generate test data.
#
Expand Down
12 changes: 8 additions & 4 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 7 additions & 3 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -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
18 changes: 9 additions & 9 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#!/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")
# system "cp config/database.yml.sample config/database.yml"
# 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
12 changes: 7 additions & 5 deletions bin/spring
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 4 additions & 2 deletions config/initializers/backtrace_silencers.rb
Original file line number Diff line number Diff line change
@@ -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!
6 changes: 3 additions & 3 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions config/initializers/mailer_url_options.rb
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
12 changes: 7 additions & 5 deletions config/initializers/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,34 @@ 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(":")
paths.each { |p| return true if File.executable?(File.join(p, "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

0 comments on commit 2f5b7d0

Please sign in to comment.