Skip to content

Commit

Permalink
Fix some rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 1, 2025
1 parent 31d89dd commit 099f985
Show file tree
Hide file tree
Showing 33 changed files with 161 additions and 90 deletions.
4 changes: 3 additions & 1 deletion .simplecov
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

SimpleCov.command_name "spec:#{SPEC_ROOT.join('..').basename}"

SimpleCov.root(SPEC_ROOT.join('../..').to_s)
Expand All @@ -6,4 +8,4 @@ SimpleCov.start do
add_filter '/spec/'
add_filter '/rom-sql/'
add_filter '/lint/'
end
end
20 changes: 11 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# frozen_string_literal: true

source 'https://rubygems.org'

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

gemspec

eval_gemfile "Gemfile.devtools"
eval_gemfile 'Gemfile.devtools'

unless defined?(COMPONENTS)
COMPONENTS = %w(core repository changeset)
COMPONENTS = %w[core repository changeset].freeze
end

COMPONENTS.each do |component|
Expand All @@ -23,13 +25,13 @@ if ENV['USE_DRY_INITIALIZER_MAIN'].eql?('true')
end

group :sql do
gem 'sequel', '~> 5.0'
gem 'sqlite3', platforms: :ruby
gem 'jdbc-sqlite3', platforms: :jruby
gem 'jdbc-postgres', platforms: :jruby
gem 'pg', platforms: :ruby
gem 'dry-events', '~> 1.0'
gem 'dry-monitor', '~> 1.0'
gem 'jdbc-postgres', platforms: :jruby
gem 'jdbc-sqlite3', platforms: :jruby
gem 'pg', platforms: :ruby
gem 'sequel', '~> 5.0'
gem 'sqlite3', platforms: :ruby

# if ENV['USE_ROM_SQL_MASTER'].eql?('true')
# gem 'rom-sql', github: 'rom-rb/rom-sql', branch: 'master'
Expand All @@ -40,8 +42,8 @@ group :sql do
end

group :test do
gem 'rspec', '~> 3.6'
gem 'codacy-coverage', require: false
gem 'rspec', '~> 3.6'
gem 'simplecov', platforms: :ruby
gem 'warning'
end
Expand All @@ -65,6 +67,6 @@ end

group :benchmarks do
# gem 'hotch', platforms: :ruby
gem 'benchmark-ips'
gem 'activerecord', '~> 5.0'
gem 'benchmark-ips'
end
10 changes: 6 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require "bundler/gem_tasks"
# frozen_string_literal: true

SPEC_RESULTS = {}
require 'bundler/gem_tasks'

SPEC_RESULTS = {}.freeze

desc 'Run all specs'
task :spec do
%w(core repository changeset rom).map do |name|
%w[core repository changeset rom].map do |name|
Rake::Task["spec:#{name}"].execute
end

Expand Down Expand Up @@ -40,4 +42,4 @@ task default: :spec
begin
require 'yard-junk/rake'
YardJunk::Rake.define_task(:text)
rescue LoadError;end
rescue LoadError; end
18 changes: 10 additions & 8 deletions changeset/lib/rom/changeset/extensions/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ module Extensions
# Changeset extenions for combined relations
#
# @api public
class Relation::Graph
# Build a changeset for a combined relation
#
# @raise NotImplementedError
#
# @api public
def changeset(*)
raise NotImplementedError, "Changeset doesn't support combined relations yet"
module Relation
class Graph
# Build a changeset for a combined relation
#
# @raise NotImplementedError
#
# @api public
def changeset(*)
raise NotImplementedError, "Changeset doesn't support combined relations yet"
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions changeset/spec/integration/changeset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class User < Dry::Struct
private

def extend_tuple(tuple)
tuple.merge(title: tuple[:title] + ", yes really")
tuple.merge(title: "#{tuple[:title]}, yes really")
end
end

Expand Down Expand Up @@ -197,7 +197,7 @@ def extend_tuple(tuple)
private

def extend_tuple(tuple)
tuple.merge(title: tuple[:title] + ', yes really')
tuple.merge(title: "#{tuple[:title]}, yes really")
end
end

Expand Down
6 changes: 4 additions & 2 deletions changeset/spec/shared/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
include_context 'database setup'

before do
%i[tags tasks books posts_labels posts users labels
reactions messages].each { |table| conn.drop_table?(table) }
%i[
tags tasks books posts_labels posts users labels
reactions messages
].each { |table| conn.drop_table?(table) }

conn.create_table :users do
primary_key :id
Expand Down
8 changes: 6 additions & 2 deletions changeset/spec/shared/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

conn[:tags].insert task_id: task_id, name: 'red'

jane_post_id = conn[:posts].insert author_id: jane_id, title: 'Hello From Jane', body: 'Jane Post'
joe_post_id = conn[:posts].insert author_id: joe_id, title: 'Hello From Joe', body: 'Joe Post'
jane_post_id = conn[:posts].insert(
author_id: jane_id,
title: 'Hello From Jane',
body: 'Jane Post'
)
joe_post_id = conn[:posts].insert(author_id: joe_id, title: 'Hello From Joe', body: 'Joe Post')

red_id = conn[:labels].insert name: 'red'
green_id = conn[:labels].insert name: 'green'
Expand Down
12 changes: 9 additions & 3 deletions changeset/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@
Dry::Core::Deprecations.set_logger!(SPEC_ROOT.join('../log/deprecations.log'))

# Make inference errors quiet
class ROM::SQL::Schema::Inferrer
def self.on_error(*args)
# shush
module ROM
module SQL
module Schema
class Inferrer
def self.on_error(*args)
# shush
end
end
end
end
end

Expand Down
4 changes: 3 additions & 1 deletion changeset/spec/unit/changeset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
it 'uses piped data for diff' do
expect(relation).to receive(:one).and_return(jane)

changeset = ROM::Changeset::Update.new(relation).data(name: 'Jane').map { |t| { name: t[:name].upcase } }
changeset = ROM::Changeset::Update.new(relation).data(name: 'Jane').map do |t|
{ name: t[:name].upcase }
end

expect(changeset).to be_diff
end
Expand Down
18 changes: 11 additions & 7 deletions changeset/spec/unit/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ def default_command_type
end

it 'sets up custom data pipe' do
expect(changeset.to_h)
.to eql(name: 'Jane', address_street: 'Street 1', address_city: 'NYC', address_country: 'US')
expect(changeset.to_h).to eql(
name: 'Jane',
address_street: 'Street 1',
address_city: 'NYC',
address_country: 'US'
)
end
end

Expand All @@ -35,11 +39,11 @@ def default_command_type
end

it 'sets up custom data pipe' do
expect(changeset.to_a)
.to eql([
{ name: 'Jane', address_street: 'Street 1', address_city: 'NYC', address_country: 'US' },
{ name: 'Joe', address_street: 'Street 2', address_city: 'KRK', address_country: 'PL' }
])
expect(changeset.to_a).to eql([
{ name: 'Jane', address_street: 'Street 1', address_city: 'NYC',
address_country: 'US' },
{ name: 'Joe', address_street: 'Street 2', address_city: 'KRK', address_country: 'PL' }
])
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion core/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

eval_gemfile '../Gemfile'
eval_gemfile '../Gemfile'
4 changes: 3 additions & 1 deletion core/Guardfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

group :red_green_refactor, halt_on_fail: true do
guard :rspec, cmd: "rspec", all_on_start: true do
guard :rspec, cmd: 'rspec', all_on_start: true do
# run all specs if Gemfile.lock is modified
watch('Gemfile.lock') { 'spec' }

Expand Down
3 changes: 1 addition & 2 deletions core/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ task :"spec:isolation" do
end
end

desc 'Run CI tasks'
if RUBY_ENGINE != 'ruby'
desc 'Run CI tasks'
task ci: %i[spec lint]
else
desc 'Run CI tasks'
task ci: %i[spec lint spec:isolation]
end

Expand Down
11 changes: 9 additions & 2 deletions core/benchmarks/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ def verify(&block)
end
end

DATABASE_URL = ENV.fetch('DATABASE_URL', RUBY_ENGINE == 'jruby' ? 'jdbc:postgresql://localhost/rom' : 'postgres://localhost/rom')
DATABASE_URL = ENV.fetch(
'DATABASE_URL',
if RUBY_ENGINE == 'jruby'
'jdbc:postgresql://localhost/rom'
else
'postgres://localhost/rom'
end
)

setup = ROM::Configuration.new(:sql, DATABASE_URL)

Expand Down Expand Up @@ -244,7 +251,7 @@ class Tags < ROM::Relation[:sql]

ROM_ENV = ROM.container(setup)

VERIFY = ENV.fetch('VERIFY') { false }
VERIFY = ENV.fetch('VERIFY', false)
COUNT = ENV.fetch('COUNT', 1000).to_i

USER_SEED = COUNT.times.map { |i|
Expand Down
1 change: 0 additions & 1 deletion core/lib/rom/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
require 'rom/create_container'

# register known plugin types
require 'rom/schema_plugin'

ROM::Plugins.register(:command)
ROM::Plugins.register(:mapper)
Expand Down
8 changes: 3 additions & 5 deletions core/lib/rom/lint/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ module Test
# @api private
def define_test_method(name, &block)
define_method "test_#{name}" do
begin
instance_eval(&block)
rescue ROM::Lint::Linter::Failure => f
raise Minitest::Assertion, f.message
end
instance_eval(&block)
rescue ROM::Lint::Linter::Failure => e
raise Minitest::Assertion, e.message
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions core/lib/rom/plugins/command/timestamps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Command
# @api public
class Timestamps < Module
attr_reader :timestamps, :datestamps

def initialize(timestamps: [], datestamps: [])
@timestamps = store_attributes(timestamps)
@datestamps = store_attributes(datestamps)
Expand Down Expand Up @@ -117,7 +118,7 @@ module ClassInterface
def timestamps(*names)
timestamp_columns timestamp_columns.merge(names)
end
alias timestamp timestamps
alias_method :timestamp, :timestamps

# Set up attributes to datestamp when the command is called
#
Expand All @@ -139,7 +140,7 @@ def timestamps(*names)
def datestamps(*names)
datestamp_columns datestamp_columns.merge(names)
end
alias datestamp datestamps
alias_method :datestamp, :datestamps
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions core/lib/rom/relation/class_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def relation_name
#
# @api public
def view(*args, &block)
if args.size == 1 && block.arity > 0
if args.size == 1 && block.arity.positive?
raise ArgumentError, 'schema attribute names must be provided as the second argument'
end

Expand All @@ -206,7 +206,7 @@ def view(*args, &block)
new_schema_fn
end

if relation_block.arity > 0
if relation_block.arity.positive?
auto_curry_guard do
define_method(name, &relation_block)

Expand Down
4 changes: 2 additions & 2 deletions core/lib/rom/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def respond_to_missing?(*)

def method_missing(*)
super
rescue NameError => error
raise MissingAttribute.new { "#{error.message} (attribute not loaded?)" }
rescue NameError => e
raise(MissingAttribute.new { "#{e.message} (attribute not loaded?)" })
end
end
end
2 changes: 1 addition & 1 deletion core/lib/rom/support/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ROM
# @api private
module Configurable
class Config
WRITER_REGEXP = /=$/.freeze
WRITER_REGEXP = /=$/

# @!attribute [r] settings
# @return [Hash] A hash with defined settings
Expand Down
9 changes: 3 additions & 6 deletions core/lib/rom/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module ROM
#
# @api public
#
# rubocop:disable Naming/MethodName
module Types
include Dry::Types(default: :nominal)

Expand Down Expand Up @@ -44,11 +43,9 @@ def ForeignKey(relation, type = Types::Integer)
# @api public
def Coercible.JSONHash(symbol_keys: false, type: Types::Hash)
Types.Constructor(type) do |value|
begin
::JSON.parse(value.to_s, symbolize_names: symbol_keys)
rescue ::JSON::ParserError
value
end
::JSON.parse(value.to_s, symbolize_names: symbol_keys)
rescue ::JSON::ParserError
value
end
end

Expand Down
4 changes: 2 additions & 2 deletions repository/benchmarks/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def benchmark(title)
x.config(suite: GCSuite.new)
def x.verify(*); end

def x.prepare(*)
yield
def x.prepare(*)
yield
end
yield x
x.compare!
Expand Down
Loading

0 comments on commit 099f985

Please sign in to comment.