Skip to content

Commit

Permalink
Update the code style across the project (thoughtbot#242)
Browse files Browse the repository at this point in the history
Eventually, we'll move to standard, but this is a nice improvement which
makes working with Appraisal much more pleasant.

This commit does the following:

* use double quotes everywhere
* use the new Ruby 1.9 hash syntax
* use uppercase heredoc delimiters
* add parentheses to nested method call
* add missing frozen string literal comment
* %w-literals should be delimited by [ and ]
* space inside } is missing
* fix indentation
* avoid comma after the last parameter of a method call
* remove unnecessary disabling of Layout/LineLength
* remove unnecessary spacing
* use hash literal {} instead of Hash.new
* place the . on the next line, together with the method name
* use 2 spaces for indentation in a heredoc by using <<~ instead of <<-
* make sure that the block will be associated with the PARTS.map method call
* use class << self instead of def self. to define class methods
* add missing space
  • Loading branch information
n-rodriguez authored Sep 23, 2024
1 parent 92e5e98 commit a075b0a
Show file tree
Hide file tree
Showing 48 changed files with 575 additions and 516 deletions.
14 changes: 8 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
# frozen_string_literal: true

require "bundler/setup"
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new do |t|
t.pattern = 'spec/**/*_spec.rb'
t.pattern = "spec/**/*_spec.rb"
t.ruby_opts = %w[-w]
t.verbose = false
end

desc 'Default: run the rspec examples'
task :default => [:spec]
desc "Default: run the rspec examples"
task default: [:spec]
22 changes: 11 additions & 11 deletions appraisal.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
require_relative "lib/appraisal/version"

Gem::Specification.new do |s|
s.name = 'appraisal'
s.name = "appraisal"
s.version = Appraisal::VERSION.dup
s.platform = Gem::Platform::RUBY
s.authors = ['Joe Ferris', 'Prem Sichanugrist']
s.email = ['[email protected]', '[email protected]']
s.homepage = 'http://github.com/thoughtbot/appraisal'
s.summary = 'Find out what your Ruby gems are worth'
s.authors = ["Joe Ferris", "Prem Sichanugrist"]
s.email = ["[email protected]", "[email protected]"]
s.homepage = "http://github.com/thoughtbot/appraisal"
s.summary = "Find out what your Ruby gems are worth"
s.description = 'Appraisal integrates with bundler and rake to test your library against different versions of dependencies in repeatable scenarios called "appraisals."'
s.license = 'MIT'
s.license = "MIT"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- exe/*`.split("\n").map{ |f| File.basename(f) }
s.bindir = 'exe'
s.executables = `git ls-files -- exe/*`.split("\n").map { |f| File.basename(f) }
s.bindir = "exe"

s.required_ruby_version = ">= 2.3.0"

s.add_dependency('rake')
s.add_dependency('bundler')
s.add_dependency('thor', '>= 0.14.0')
s.add_dependency("rake")
s.add_dependency("bundler")
s.add_dependency("thor", ">= 0.14.0")
end
10 changes: 6 additions & 4 deletions exe/appraisal
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'appraisal'
require 'appraisal/cli'
# frozen_string_literal: true

require "rubygems"
require "bundler/setup"
require "appraisal"
require "appraisal/cli"

begin
Appraisal::CLI.start
Expand Down
6 changes: 4 additions & 2 deletions lib/appraisal.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'appraisal/version'
require 'appraisal/task'
# frozen_string_literal: true

require "appraisal/version"
require "appraisal/task"

Appraisal::Task.new
34 changes: 18 additions & 16 deletions lib/appraisal/appraisal.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require 'appraisal/gemfile'
require 'appraisal/command'
# frozen_string_literal: true

require "appraisal/gemfile"
require "appraisal/command"
require "appraisal/customize"
require 'appraisal/utils'
require 'fileutils'
require 'pathname'
require "appraisal/utils"
require "fileutils"
require "pathname"

module Appraisal
# Represents one appraisal and its dependencies
Expand Down Expand Up @@ -79,15 +81,15 @@ def install(options = {})
command = commands.join(" || ")

if Bundler.settings[:path]
env = { 'BUNDLE_DISABLE_SHARED_GEMS' => '1' }
Command.new(command, :env => env).run
env = { "BUNDLE_DISABLE_SHARED_GEMS" => "1" }
Command.new(command, env: env).run
else
Command.new(command).run
end
end

def update(gems = [])
Command.new(update_command(gems), :gemfile => gemfile_path).run
Command.new(update_command(gems), gemfile: gemfile_path).run
end

def gemfile_path
Expand All @@ -107,10 +109,10 @@ def relativize
relative_path = current_directory.relative_path_from(gemfile_root).cleanpath
lockfile_content = File.read(lockfile_path)

File.open(lockfile_path, 'w') do |file|
File.open(lockfile_path, "w") do |file|
file.write lockfile_content.gsub(
/ #{current_directory}/,
" #{relative_path}",
" #{relative_path}"
)
end
end
Expand All @@ -119,16 +121,16 @@ def relativize

def check_command
gemfile_option = "--gemfile='#{gemfile_path}'"
['bundle', 'check', gemfile_option]
["bundle", "check", gemfile_option]
end

def install_command(options = {})
gemfile_option = "--gemfile='#{gemfile_path}'"
['bundle', 'install', gemfile_option, bundle_options(options)].compact
["bundle", "install", gemfile_option, bundle_options(options)].compact
end

def update_command(gems)
['bundle', 'update', *gems].compact
["bundle", "update", *gems].compact
end

def gemfile_root
Expand All @@ -148,7 +150,7 @@ def lockfile_path
end

def clean_name
name.gsub(/[^\w\.]/, '_')
name.gsub(/[^\w\.]/, "_")
end

def bundle_options(options)
Expand All @@ -159,8 +161,8 @@ def bundle_options(options)
if Utils.support_parallel_installation?
options_strings << "--jobs=#{jobs}"
else
warn 'Your current version of Bundler does not support parallel installation. Please ' +
'upgrade Bundler to version >= 1.4.0, or invoke `appraisal` without `--jobs` option.'
warn "Your current version of Bundler does not support parallel installation. Please " +
"upgrade Bundler to version >= 1.4.0, or invoke `appraisal` without `--jobs` option."
end
end

Expand Down
12 changes: 7 additions & 5 deletions lib/appraisal/appraisal_file.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'appraisal/appraisal'
# frozen_string_literal: true

require "appraisal/appraisal"
require "appraisal/customize"
require 'appraisal/errors'
require 'appraisal/gemfile'
require "appraisal/errors"
require "appraisal/gemfile"

module Appraisal
# Loads and parses Appraisals file
Expand All @@ -15,7 +17,7 @@ def self.each(&block)
def initialize
@appraisals = []
@gemfile = Gemfile.new
@gemfile.load(ENV['BUNDLE_GEMFILE'] || 'Gemfile')
@gemfile.load(ENV["BUNDLE_GEMFILE"] || "Gemfile")

if File.exist? path
run IO.read(path)
Expand Down Expand Up @@ -45,7 +47,7 @@ def run(definitions)
end

def path
'Appraisals'
"Appraisals"
end
end
end
23 changes: 12 additions & 11 deletions lib/appraisal/bundler_dsl.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# frozen_string_literal: true

require "appraisal/dependency_list"

module Appraisal
class BundlerDSL
attr_reader :dependencies

PARTS = %w(source ruby_version gits paths dependencies groups
platforms source_blocks install_if gemspec)
PARTS = %w[source ruby_version gits paths dependencies groups
platforms source_blocks install_if gemspec]

def initialize
@sources = []
@ruby_version = nil
@dependencies = DependencyList.new
@gemspecs = []
@groups = Hash.new
@platforms = Hash.new
@gits = Hash.new
@paths = Hash.new
@source_blocks = Hash.new
@groups = {}
@platforms = {}
@gits = {}
@paths = {}
@source_blocks = {}
@git_sources = {}
@install_if = {}
end
Expand Down Expand Up @@ -80,11 +82,11 @@ def path(source, options = {}, &block)
end

def to_s
Utils.join_parts PARTS.map { |part| send("#{part}_entry") }
Utils.join_parts(PARTS.map { |part| send("#{part}_entry") })
end

def for_dup
Utils.join_parts PARTS.map { |part| send("#{part}_entry_for_dup") }
Utils.join_parts(PARTS.map { |part| send("#{part}_entry_for_dup") })
end

def gemspec(options = {})
Expand Down Expand Up @@ -134,8 +136,7 @@ def dependencies_entry_for_dup
@dependencies.for_dup
end

%i[gits paths platforms groups source_blocks install_if].
each do |method_name|
%i[gits paths platforms groups source_blocks install_if].each do |method_name|
class_eval <<-METHODS, __FILE__, __LINE__
private
Expand Down
84 changes: 44 additions & 40 deletions lib/appraisal/cli.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
require 'thor'
require 'fileutils'
# frozen_string_literal: true

require "thor"
require "fileutils"

module Appraisal
class CLI < Thor
default_task :install
map ["-v", "--version"] => "version"

# Override help command to print out usage
def self.help(shell, subcommand = false)
shell.say strip_heredoc(<<-help)
Appraisal: Find out what your Ruby gems are worth.
class << self
# Override help command to print out usage
def help(shell, subcommand = false)
shell.say strip_heredoc(<<-HELP)
Appraisal: Find out what your Ruby gems are worth.
Usage:
appraisal [APPRAISAL_NAME] EXTERNAL_COMMAND
Usage:
appraisal [APPRAISAL_NAME] EXTERNAL_COMMAND
If APPRAISAL_NAME is given, only run that EXTERNAL_COMMAND against the given
appraisal, otherwise it runs the EXTERNAL_COMMAND against all appraisals.
help
If APPRAISAL_NAME is given, only run that EXTERNAL_COMMAND against the given
appraisal, otherwise it runs the EXTERNAL_COMMAND against all appraisals.
HELP

if File.exist?('Appraisals')
shell.say
shell.say 'Available Appraisal(s):'
if File.exist?("Appraisals")
shell.say
shell.say "Available Appraisal(s):"

AppraisalFile.each do |appraisal|
shell.say " - #{appraisal.name}"
AppraisalFile.each do |appraisal|
shell.say " - #{appraisal.name}"
end
end
end

shell.say
shell.say

super
end
super
end

def self.exit_on_failure?
true
def exit_on_failure?
true
end
end

desc 'install', 'Resolve and install dependencies for each appraisal'
method_option 'jobs', :aliases => 'j', :type => :numeric, :default => 1,
:banner => 'SIZE',
:desc => 'Install gems in parallel using the given number of workers.'
method_option 'retry', :type => :numeric, :default => 1,
:desc => 'Retry network and git requests that have failed'
method_option "without", :banner => "GROUP_NAMES",
:desc => "A space-separated list of groups referencing gems to skip " +
desc "install", "Resolve and install dependencies for each appraisal"
method_option "jobs", aliases: "j", type: :numeric, default: 1,
banner: "SIZE",
desc: "Install gems in parallel using the given number of workers."
method_option "retry", type: :numeric, default: 1,
desc: "Retry network and git requests that have failed"
method_option "without", banner: "GROUP_NAMES",
desc: "A space-separated list of groups referencing gems to skip " +
"during installation. Bundler will remember this option."
method_option "full-index", :type => :boolean,
:desc => "Run bundle install with the " \
method_option "full-index", type: :boolean,
desc: "Run bundle install with the " \
"full-index argument."
method_option "path", type: :string,
desc: "Install gems in the specified directory. " \
Expand All @@ -61,19 +65,19 @@ def install
end
end

desc 'generate', 'Generate a gemfile for each appraisal'
desc "generate", "Generate a gemfile for each appraisal"
def generate
AppraisalFile.each do |appraisal|
appraisal.write_gemfile
end
end

desc 'clean', 'Remove all generated gemfiles and lockfiles from gemfiles folder'
desc "clean", "Remove all generated gemfiles and lockfiles from gemfiles folder"
def clean
FileUtils.rm_f Dir['gemfiles/*.{gemfile,gemfile.lock}']
FileUtils.rm_f Dir["gemfiles/*.{gemfile,gemfile.lock}"]
end

desc 'update [LIST_OF_GEMS]', 'Remove all generated gemfiles and lockfiles, resolve, and install dependencies again'
desc "update [LIST_OF_GEMS]", "Remove all generated gemfiles and lockfiles, resolve, and install dependencies again"
def update(*gems)
invoke :generate, []

Expand All @@ -82,7 +86,7 @@ def update(*gems)
end
end

desc 'list', 'List the names of the defined appraisals'
desc "list", "List the names of the defined appraisals"
def list
AppraisalFile.new.appraisals.each { |appraisal| puts appraisal.name }
end
Expand All @@ -100,17 +104,17 @@ def method_missing(name, *args, &block)
end

if matching_appraisal
Command.new(args, :gemfile => matching_appraisal.gemfile_path).run
Command.new(args, gemfile: matching_appraisal.gemfile_path).run
else
AppraisalFile.each do |appraisal|
Command.new(ARGV, :gemfile => appraisal.gemfile_path).run
Command.new(ARGV, gemfile: appraisal.gemfile_path).run
end
end
end

def self.strip_heredoc(string)
indent = string.scan(/^[ \t]*(?=\S)/).min.size || 0
string.gsub(/^[ \t]{#{indent}}/, '')
string.gsub(/^[ \t]{#{indent}}/, "")
end
end
end
Loading

0 comments on commit a075b0a

Please sign in to comment.