Skip to content

Commit

Permalink
Address rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 2, 2025
1 parent 92047a0 commit 8bf83fd
Show file tree
Hide file tree
Showing 23 changed files with 82 additions and 64 deletions.
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ task default: :spec
begin
require 'yard-junk/rake'
YardJunk::Rake.define_task(:text)
rescue LoadError; end
rescue LoadError
# ignore
end
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require 'dry/monitor'
%w[pry-byebug debug pry].each do |gem|
require gem
rescue LoadError
# ignore
else
break
end
Expand Down
3 changes: 2 additions & 1 deletion core/benchmarks/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
begin
require 'byebug'
rescue LoadError
# ignore
end

require_relative 'gc_suite'
Expand Down Expand Up @@ -277,7 +278,7 @@ class Tags < ROM::Relation[:sql]
end
}.flatten

def seed
def seed # rubocop:disable Metrics/AbcSize
hr

puts "SEEDING #{USER_SEED.count} users"
Expand Down
10 changes: 5 additions & 5 deletions core/lib/rom/array_dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def self.included(klass)
map! combination cycle delete_if keep_if permutation reject!
select! sort_by!
].each do |method|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args, &block)
return to_enum unless block
self.class.new(data.send(:#{method}, *args, &block), **options)
end
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
def #{method}(*args, &) # def map!(*args, &)
return to_enum unless block_given? # return to_enum unless block_given?
self.class.new(data.__send__(:#{method}, *args, &), **options) # self.class.new(data.__send__(:map!, *args, &), **options)
end # end
RUBY
end
end
Expand Down
6 changes: 4 additions & 2 deletions core/lib/rom/associations/definitions/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ class Abstract
# @option opts [Symbol] :as The name of the association (defaults to target)
# @option opts [Symbol] :relation The name of the target relation (defaults to target)
# @option opts [Symbol] :foreign_key The name of a custom foreign key
# @option opts [Symbol] :view The name of a custom relation view on the target's relation side
# @option opts [TrueClass,FalseClass] :override Whether provided :view should override association's default view
# @option opts [Symbol] :view The name of a custom relation view
# on the target's relation side
# @option opts [true, false] :override Whether provided :view should override
# association's default view
#
# @api public
def self.new(source, target, **opts)
Expand Down
3 changes: 2 additions & 1 deletion core/lib/rom/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Attribute
META_OPTIONS = %i[primary_key foreign_key source target relation].freeze

# @!attribute [r] type
# @return [Dry::Types::Nominal, Dry::Types::Sum, Dry::Types::Constrained] The attribute's type object
# @return [Dry::Types::Nominal, Dry::Types::Sum, Dry::Types::Constrained] The attribute's
# type object
param :type

# @!attribute [r] name
Expand Down
8 changes: 4 additions & 4 deletions core/lib/rom/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def execute(*)
# This method will apply before/after hooks automatically
#
# @api public
def call(*args, &block)
def call(*args, &)
tuples =
if hooks?
prepared =
Expand All @@ -275,7 +275,7 @@ def call(*args, &block)
apply_hooks(before_hooks, *args)
end

result = prepared ? execute(prepared, &block) : execute(&block)
result = prepared ? execute(prepared, &) : execute(&)

if curried?
if !args.empty?
Expand All @@ -286,10 +286,10 @@ def call(*args, &block)
apply_hooks(after_hooks, result)
end
else
apply_hooks(after_hooks, result, *args[1..args.size - 1])
apply_hooks(after_hooks, result, *args.drop(1))
end
else
execute(*(curry_args + args), &block)
execute(*(curry_args + args), &)
end

if one?
Expand Down
20 changes: 10 additions & 10 deletions core/lib/rom/commands/class_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,16 @@ def options
def relation_methods_mod(relation_class)
Module.new do
relation_class.view_methods.each do |meth|
module_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{meth}(*args, **kwargs)
response = relation.public_send(:#{meth}, *args, **kwargs)
if response.is_a?(relation.class)
new(response)
else
response
end
end
module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
def #{meth}(*args, **kwargs) # def create(*args, **kwargs)
response = relation.public_send(:#{meth}, *args, **kwargs) # response = relation.public_send(:create, *args, **kwargs)
#
if response.is_a?(relation.class) # if response.is_a?(relation.class)
new(response) # new(response)
else # else
response # response
end # end
end # end
RUBY
end
end
Expand Down
12 changes: 9 additions & 3 deletions core/lib/rom/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class Configuration
# @return [Notifications] Notification bus instance
attr_reader :notifications

def_delegators :@setup, :register_relation, :register_command, :register_mapper, :register_plugin,
def_delegators :@setup, :register_relation, :register_command,
:register_mapper, :register_plugin,
:command_classes, :mapper_classes,
:auto_registration

Expand Down Expand Up @@ -89,7 +90,7 @@ def [](name)
# Hook for respond_to? used internally
#
# @api private
def respond_to?(name, include_all = false)
def respond_to?(name, ...)
gateways.key?(name) || super
end

Expand Down Expand Up @@ -122,12 +123,17 @@ def default_adapter

private

# @api private
def respond_to_missing?(name, ...)
gateways.key?(name) || super
end

# Returns gateway if method is a name of a registered gateway
#
# @return [Gateway]
#
# @api private
def method_missing(name, *)
def method_missing(name, ...)
gateways.fetch(name) { super }
end
end
Expand Down
24 changes: 12 additions & 12 deletions core/lib/rom/data_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ def forward(*methods)
# FIXME: we should probably raise if one of the non-forwardable methods
# was provided
(methods - NON_FORWARDABLE).each do |method_name|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method_name}(*args, &block)
response = data.public_send(#{method_name.inspect}, *args, &block)
if response.equal?(data)
self
elsif response.is_a?(data.class)
self.class.new(response)
else
response
end
end
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
def #{method_name}(...) # def find_all(...)
response = data.public_send(:#{method_name}, ...) # response = data.public_send(:find_all, ...)
#
if response.equal?(data) # if response.equal?(data)
self # self
elsif response.is_a?(data.class) # elsif response.is_a?(data.class)
self.class.new(response) # self.class.new(response)
else # else
response # response
end # end
end # end
RUBY
end
end
Expand Down
10 changes: 5 additions & 5 deletions core/lib/rom/enumerable_dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def self.included(klass)
chunk collect collect_concat drop_while find_all flat_map
grep map reject select sort sort_by take_while
].each do |method|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args, &block)
return to_enum unless block
self.class.new(super(*args, &block), **options)
end
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
def #{method}(...) # def collect(...)
return to_enum unless block_given? # return to_enum unless block_given?
self.class.new(super(...), **options) # self.class.new(super(...), **options)
end # end
RUBY
end
end
Expand Down
4 changes: 2 additions & 2 deletions core/lib/rom/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def initialize(attributes, options = {})
# @yield [Attribute]
#
# @api private
def each
attributes.each_value { |attribute| yield(attribute) }
def each(&)
attributes.each_value(&)
end

# Return if there are any aliased attributes
Expand Down
2 changes: 1 addition & 1 deletion core/lib/rom/lint/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def lint(name)
# @return [String]
#
# @api private
def self.lints
private_class_method def self.lints
public_instance_methods(true).grep(/^lint_/).map(&:to_s)
end

Expand Down
2 changes: 1 addition & 1 deletion core/lib/rom/memory/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Create < ROM::Commands::Create

# @see ROM::Commands::Create#execute
def execute(tuples)
Array([tuples]).flatten.map { |tuple|
[tuples].flatten.map { |tuple|
attributes = input[tuple]
relation.insert(attributes.to_h)
attributes
Expand Down
2 changes: 1 addition & 1 deletion core/lib/rom/memory/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def join(*args)
left, right = args.size > 1 ? args : [self, args.first]

join_map = left.each_with_object({}) { |tuple, h|
others = right.to_a.find_all { |t| (tuple.to_a & t.to_a).any? }
others = right.to_a.find_all { |t| tuple.to_a.intersect?(t.to_a) }
(h[tuple] ||= []).concat(others)
}

Expand Down
8 changes: 4 additions & 4 deletions core/lib/rom/model_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ def define_class(attrs)

@klass.send(:attr_reader, *attrs)

@klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def initialize(params)
#{attrs.map { |name| "@#{name} = params[:#{name}]" }.join("\n")}
end
@klass.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
def initialize(params) # def initialize(params)
#{attrs.map { |name| "@#{name} = params[:#{name}]" }.join("\n")} # @name = params[:name]
end # end
RUBY

self
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 @@ -22,19 +22,20 @@ module Command
# result[:created_at] #=> Time.now.utc
#
# @api public
class Timestamps < Module
class Timestamps < ::Module
attr_reader :timestamps

attr_reader :datestamps

def initialize(timestamps: [], datestamps: [])
super()
@timestamps = store_attributes(timestamps)
@datestamps = store_attributes(datestamps)
end

# @api private
def store_attributes(attr)
attr.is_a?(Array) ? attr : Array[attr]
attr.is_a?(Array) ? attr : [attr]
end

# @api private
Expand Down
1 change: 1 addition & 0 deletions core/lib/rom/plugins/relation/registry_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RegistryReader < ::Module

# @api private
def initialize(klass:, relation_readers_module:)
super()
klass.include relation_readers_module
end

Expand Down
8 changes: 4 additions & 4 deletions core/lib/rom/relation/class_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ def dataset(&block)
# @param [Boolean] infer Whether to do an automatic schema inferring
#
# @api public
def schema(dataset = nil, as: nil, infer: false, &block)
if defined?(@schema) && !block && !infer
def schema(dataset = nil, as: nil, infer: false, &)
if defined?(@schema) && !block_given? && !infer
@schema
elsif block || infer
elsif block_given? || infer
raise MissingSchemaClassError, self unless schema_class

ds_name = dataset || schema_opts.fetch(:dataset, default_name.dataset)
Expand All @@ -110,7 +110,7 @@ def schema(dataset = nil, as: nil, infer: false, &block)
schema_class: schema_class,
attr_class: schema_attr_class,
inferrer: schema_inferrer.with(enabled: infer),
&block
&
).call(*args, &inner_block)
end
end
Expand Down
4 changes: 2 additions & 2 deletions core/lib/rom/relation/combined.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def call(*args)
# @return [Relation]
#
# @api public
def node(name, &block)
def node(name, &)
if name.is_a?(Symbol) && !nodes.map { |n| n.name.key }.include?(name)
raise ArgumentError, "#{name.inspect} is not a valid aggregate node name"
end
Expand All @@ -107,7 +107,7 @@ def node(name, &block)
when Hash
other, *rest = name.flatten(1)
if other == node.name.key
nodes.detect { |n| n.name.key == other }.node(*rest, &block)
nodes.detect { |n| n.name.key == other }.node(*rest, &)
else
node
end
Expand Down
2 changes: 1 addition & 1 deletion core/spec/unit/rom/commands/graph_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def associate(tasks, user)
before :associate

def associate(tags, tasks)
Array([tasks]).flatten.map { |task|
[tasks].flatten.map { |task|
tags.map { |tag| tag.merge(task: task[:title]) }
}.flatten
end
Expand Down
3 changes: 2 additions & 1 deletion core/spec/unit/rom/create_container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def orange?
expect { container }.not_to raise_error
end

it "doesn't raise an error when registering same mapper twice for different relation when no relation specify" do
it "doesn't raise an error when registering same mapper " \
'twice for different relation when no relation specify' do
configuration

users_mapper = Class.new(ROM::Mapper) do
Expand Down
4 changes: 3 additions & 1 deletion core/spec/unit/rom/relation/combined/map_with_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

RSpec.describe ROM::Relation::Combined, '#map_with' do
subject(:relation) do
ROM::Relation::Combined.new(users, [tasks.to_node(:tasks, type: :many, keys: { id: :user_id }).for_users])
ROM::Relation::Combined.new(
users, [tasks.to_node(:tasks, type: :many, keys: { id: :user_id }).for_users]
)
end

let(:users) do
Expand Down

0 comments on commit 8bf83fd

Please sign in to comment.