Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt Standard for code style #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ruby_version: 2.3

ignore:
- lib/gel/support/**/*
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ gem "rake", "~> 12.0"
gem "minitest", "~> 5.0"
gem "mocha"
gem "webmock"
gem "standard"

gem "ronn", platform: :ruby
20 changes: 20 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,43 @@ GEM
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
hashdiff (0.3.7)
hpricot (0.8.6)
jaro_winkler (1.5.2)
metaclass (0.0.4)
minitest (5.10.3)
mocha (1.8.0)
metaclass (~> 0.0.1)
mustache (1.1.0)
parallel (1.17.0)
parser (2.6.2.1)
ast (~> 2.4.0)
psych (3.1.0)
pub_grub (0.5.0)
public_suffix (3.0.1)
rainbow (3.0.0)
rake (12.3.0)
rdiscount (2.2.0.1)
ronn (0.7.3)
hpricot (>= 0.8.2)
mustache (>= 0.7.0)
rdiscount (>= 1.5.8)
rubocop (0.67.2)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
psych (>= 3.1.0)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.6)
ruby-progressbar (1.10.0)
safe_yaml (1.0.4)
standard (0.0.39)
rubocop (~> 0.67.1)
unicode-display_width (1.5.0)
webmock (3.1.1)
addressable (>= 2.3.6)
crack (>= 0.3.2)
Expand All @@ -41,6 +60,7 @@ DEPENDENCIES
pub_grub (>= 0.5.0)
rake (~> 12.0)
ronn
standard
webmock

BUNDLED WITH
Expand Down
5 changes: 3 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "rake/testtask"
require "standard/rake"

Rake::TestTask.class_eval do
def rake_include_arg
Expand Down Expand Up @@ -39,7 +40,7 @@ MAN_PAGES = MAN_SOURCES.map { |source| source.delete(".ronn") }

file MAN_PAGES => :man

task :man => MAN_SOURCES do
task man: MAN_SOURCES do
sh "ronn --roff --manual 'Gel Manual' #{Shellwords.shelljoin MAN_SOURCES}"
end

Expand All @@ -51,4 +52,4 @@ task build: :man do
sh "gem build -o pkg/gel-#{version}.gem gel.gemspec"
end

task default: :test
task default: [:test, "standard:fix"]
4 changes: 2 additions & 2 deletions lib/gel/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def download_gem(name, version)
path
end

VARIANT_GEMS = %w(libv8)
VARIANT_GEMS = %w[libv8]
def guess_version(name, version)
if VARIANT_GEMS.include?(name)
[name, "#{version}-#{platform_specific_version}"]
Expand All @@ -109,7 +109,7 @@ def normalize_uri(uri)
uri = URI(uri).dup
uri.scheme = uri.scheme.downcase
uri.host = uri.host.downcase
if auth = Gel::Environment.config[uri.host]
if (auth = Gel::Environment.config[uri.host])
uri.userinfo = auth
end
uri.path = "/" if uri.path == ""
Expand Down
4 changes: 2 additions & 2 deletions lib/gel/catalog/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def gem_info(gem_name)
gems_to_refresh = []

@monitor.synchronize do
if info = _info(gem_name)
if (info = _info(gem_name))
gems_to_refresh = walk_gem_dependencies(gem_name, info)
return info
end
Expand Down Expand Up @@ -59,7 +59,7 @@ def walk_gem_dependencies(gem_name, info)

def _info(name)
raise @error if @error
if i = @gem_info[name]
if (i = @gem_info[name])
raise i if i.is_a?(Exception)
i
end
Expand Down
6 changes: 3 additions & 3 deletions lib/gel/catalog/compact_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ def refresh_gem(gem_name, immediate = true)
version, rest = line.split(" ", 2)
deps, attrs = rest.split("|", 2)

deps = deps.split(",").map do |entry|
deps = deps.split(",").map { |entry|
key, constraints = entry.split(":", 2)
constraints = constraints.split("&")
[key, constraints]
end
}

attributes = { dependencies: deps }
attributes = {dependencies: deps}
attrs.scan(/(\w+):((?:[^,]+|,(?!\w+:))*)/) do |key, value|
attributes[key.to_sym] = value
end
Expand Down
2 changes: 1 addition & 1 deletion lib/gel/catalog/dependency_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def refresh_some_gems(gems)
response =
begin
@catalog.send(:http_get, "api/v1/dependencies?gems=#{gem_list}")
rescue Exception => ex
rescue Exception => ex # rubocop:disable RescueException
@monitor.synchronize do
@error = ex
@refresh_cond.broadcast
Expand Down
12 changes: 6 additions & 6 deletions lib/gel/catalog/legacy_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def update
end
end

pinboard.async_file(uri("specs.4.8.gz"), tail: false, error: error, &spec_file_handler.(false))
pinboard.async_file(uri("prerelease_specs.4.8.gz"), tail: false, error: error, &spec_file_handler.(true))
pinboard.async_file(uri("specs.4.8.gz"), tail: false, error: error, &spec_file_handler.call(false))
pinboard.async_file(uri("prerelease_specs.4.8.gz"), tail: false, error: error, &spec_file_handler.call(true))

true
end
Expand All @@ -104,7 +104,7 @@ def refresh_gem(gem_name, immediate = true)
return
end

unless info = @gem_info[gem_name]
unless (info = @gem_info[gem_name])
@gem_info[gem_name] = {}
@refresh_cond.broadcast
return
Expand Down Expand Up @@ -133,7 +133,7 @@ def refresh_gem(gem_name, immediate = true)
spec = Marshal.load(data)

@monitor.synchronize do
loaded_data[v] = { dependencies: spec.dependencies, ruby: spec.required_ruby_version }
loaded_data[v] = {dependencies: spec.dependencies, ruby: spec.required_ruby_version}
if loaded_data.values.all?
@gem_info[gem_name].update loaded_data
@refresh_cond.broadcast
Expand All @@ -146,10 +146,10 @@ def refresh_gem(gem_name, immediate = true)
private

def _info(gem_name)
if i = super
if (i = super)
if i.values.all? { |v| v.is_a?(Hash) }
i
elsif e = i.values.grep(Exception).first
elsif (e = i.values.grep(Exception).first)
raise e
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/gel/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Gel::Command
def self.run(command_line)
command_line = command_line.dup
if command_name = extract_word(command_line)
if (command_name = extract_word(command_line))
const = command_name.downcase.sub(/^./, &:upcase).gsub(/[-_]./) { |s| s[1].upcase }
if Gel::Command.const_defined?(const, false)
command = Gel::Command.const_get(const, false).new
Expand All @@ -20,20 +20,20 @@ def self.run(command_line)
end
else
puts <<~EOF
Gel doesn't have a default command; please run `gel install`
Gel doesn't have a default command; please run `gel install`
EOF
end
rescue Exception => ex
raise if $DEBUG || (command && command.reraise)
rescue Exception => ex # rubocop:disable RescueException
raise if $DEBUG || (command&.reraise)
handle_error(ex)
end

def self.handle_error(ex)
case ex
when Gel::ReportableError
$stderr.puts "ERROR: #{ex.message}"
if more = ex.details
$stderr.puts more
warn "ERROR: #{ex.message}"
if (more = ex.details)
warn more
end

exit ex.exit_code
Expand Down Expand Up @@ -63,7 +63,7 @@ def self.handle_error(ex)
end

def self.extract_word(arguments)
if idx = arguments.index { |w| w =~ /^[^-]/ }
if (idx = arguments.index { |w| w =~ /^[^-]/ })
arguments.delete_at(idx)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/gel/command/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def expand_executable(original_command)
return [File.expand_path(original_command), :path]
end

if source = Gel::Environment.activate_for_executable([original_command])
if found = Gel::Environment.find_executable(original_command)
if (source = Gel::Environment.activate_for_executable([original_command]))
if (found = Gel::Environment.find_executable(original_command))
return [found, source]
end
end

path_attempts = ENV["PATH"].split(File::PATH_SEPARATOR).map { |e| File.join(e, original_command) }
if found = path_attempts.find { |path| File.executable?(path) }
if (found = path_attempts.find { |path| File.executable?(path) })
return [File.expand_path(found), :path]
end

Expand Down
10 changes: 5 additions & 5 deletions lib/gel/command/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def run(command_line)

until command_line.empty?
case argument = command_line.shift
when "--strict"; strict = true
when "--major"; mode = :major
when "--minor"; mode = :minor
when "--patch"; mode = :patch
when "--hold"; mode = :hold
when "--strict" then strict = true
when "--major" then mode = :major
when "--minor" then mode = :minor
when "--patch" then mode = :patch
when "--hold" then mode = :hold
when /\A--lockfile(?:=(.*))?\z/
options[:lockfile] = $1 || command_line.shift
when /\A((?!-)[A-Za-z0-9_-]+)(?:(?:[\ :\/]|(?=[<>~=]))([<>~=,\ 0-9A-Za-z.-]+))?\z/x
Expand Down
4 changes: 2 additions & 2 deletions lib/gel/compatibility/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def self.with_clean_env
end

def self.settings
if gemfile = Gel::Environment.gemfile
{ "gemfile" => gemfile.filename }
if (gemfile = Gel::Environment.gemfile)
{"gemfile" => gemfile.filename}
else
{}
end
Expand Down
23 changes: 10 additions & 13 deletions lib/gel/compatibility/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(name, requirement, type)

class Specification
def self.find_by_name(name, *requirements)
if g = Gel::Environment.find_gem(name, *requirements)
if (g = Gel::Environment.find_gem(name, *requirements))
new(g)
else
# TODO: Should probably be a Gel exception instead?
Expand Down Expand Up @@ -109,9 +109,9 @@ def self.loaded_specs
end

def self.find_files(pattern)
Gel::Environment.store.each.
flat_map(&:require_paths).
flat_map { |dir| Dir[File.join(dir, pattern)] }
Gel::Environment.store.each
.flat_map(&:require_paths)
.flat_map { |dir| Dir[File.join(dir, pattern)] }
end

def self.refresh
Expand All @@ -135,14 +135,11 @@ def self.activate_bin_path(gem_name, bin_name, version = nil)
exec RbConfig.ruby, "--", $0, *ARGV
end

if g = Gel::Environment.activated_gems[gem_name]
if (g = Gel::Environment.activated_gems[gem_name])
Gel::Environment.gem g.name, version if version
elsif g = Gel::Environment.find_gem(gem_name, *version) do |g|
g.executables.include?(bin_name)
end

elsif (g = Gel::Environment.find_gem(gem_name, *version) { |g| g.executables.include?(bin_name) })
Gel::Environment.gem g.name, g.version
elsif g = Gel::Environment.find_gem(gem_name, *version)
elsif (g = Gel::Environment.find_gem(gem_name, *version))
raise "#{g.name} (#{g.version}) doesn't contain executable #{bin_name.inspect}"
elsif version && Gel::Environment.find_gem(gem_name)
raise "#{gem_name} (#{version}) not available"
Expand All @@ -156,9 +153,9 @@ def self.activate_bin_path(gem_name, bin_name, version = nil)
# rubygems binstub. Detect that situation, and provide nicer error
# reporting.

raise unless locations = caller_locations(2, 2)
raise unless (locations = caller_locations(2, 2))
raise unless locations.size == 1
raise unless path = locations.first.absolute_path
raise unless (path = locations.first.absolute_path)
raise unless File.exist?(path) && File.readable?(path)
raise unless File.open(path, "rb") { |f| f.read(1024).include?("\n# This file was generated by RubyGems.\n") }

Expand All @@ -167,7 +164,7 @@ def self.activate_bin_path(gem_name, bin_name, version = nil)
end

def self.bin_path(gem_name, bin_name, version = nil)
if g = Gel::Environment.activated_gems[gem_name]
if (g = Gel::Environment.activated_gems[gem_name])
Gel::Environment.gem g.name, version if version

Gel::Environment.find_executable(bin_name, g.name, g.version)
Expand Down
6 changes: 3 additions & 3 deletions lib/gel/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ def config
@config ||= read
end

def [](group = nil, key)
def [](group = nil, key) # rubocop:disable OptionalArguments
if group.nil?
group, key = key.split(".", 2)
end

(group ? (config[group.to_s] || {}) : config)[key.to_s]
end

def []=(group = nil, key, value)
def []=(group = nil, key, value) # rubocop:disable OptionalArguments
if group.nil?
group, key = key.split(".", 2)
end
Expand Down Expand Up @@ -57,7 +57,7 @@ def write(data)
Dir.mkdir(@root) unless Dir.exist?(@root)

tempfile = File.join(@root, ".config.#{Process.pid}")
File.open(tempfile, "w", 0644) do |f|
File.open(tempfile, "w", 0o644) do |f|
data.each do |key, value|
next if value.is_a?(Hash)
f.puts("#{key}: #{value}")
Expand Down
Loading