Skip to content

Commit

Permalink
Finish with offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 2, 2025
1 parent 8bf83fd commit 81522e7
Show file tree
Hide file tree
Showing 41 changed files with 124 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Metrics/MethodLength:
Naming/FileName:
Exclude:
- "lib/dry-*.rb"
- "changeset/lib/rom-changeset.rb"
- "core/lib/rom-core.rb"
- "repository/lib/rom-repository.rb"

Naming/MemoizedInstanceVariableName:
Enabled: false
Expand Down
1 change: 0 additions & 1 deletion changeset/.rubocop.yml

This file was deleted.

2 changes: 1 addition & 1 deletion changeset/lib/rom/changeset/stateful.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def self.extend(*, &block)
#
# @return [Pipe]
def self.default_pipe(context)
!pipes.empty? ? pipes.map { |p| p.bind(context) }.reduce(:>>) : EMPTY_PIPE
pipes.empty? ? EMPTY_PIPE : pipes.map { |p| p.bind(context) }.reduce(:>>)
end

# @api private
Expand Down
5 changes: 4 additions & 1 deletion changeset/lib/rom/changeset/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def clean?
# @return [Hash]
#
# @api public
#
# rubocop:disable Metrics/AbcSize
def diff
@diff ||=
begin
Expand All @@ -73,9 +75,10 @@ def diff
new_tuple = data_tuple.to_a.select { |k, _| data_keys.include?(k) }
ori_tuple = source.to_a.select { |k, _| data_keys.include?(k) }

Hash[new_tuple - (new_tuple & ori_tuple)]
(new_tuple - (new_tuple & ori_tuple)).to_h
end
end
# rubocop:enable Metrics/AbcSize
end
end
end
3 changes: 2 additions & 1 deletion changeset/lib/rom/plugins/relation/changeset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def changeset(type, data = EMPTY_HASH)
end
rescue KeyError
raise ArgumentError,
"+#{type.inspect}+ is not a valid changeset type. Must be one of: #{TYPES.keys.inspect}"
"+#{type.inspect}+ is not a valid changeset type. " \
"Must be one of: #{TYPES.keys.inspect}"
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion changeset/rom-changeset.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ require File.expand_path('lib/rom/changeset/version', __dir__)
Gem::Specification.new do |gem|
gem.name = 'rom-changeset'
gem.summary = 'Changeset abstraction for rom-rb'
gem.description = 'rom-changeset adds support for preprocessing data on top of rom-rb repositories'
gem.description = 'rom-changeset adds support for preprocessing data on ' \
'top of rom-rb repositories'
gem.author = 'Piotr Solnica'
gem.email = '[email protected]'
gem.homepage = 'http://rom-rb.org'
Expand Down
6 changes: 3 additions & 3 deletions changeset/spec/integration/changeset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ def extend_tuple(tuple)
expect(result[:name]).not_to eql('Jane Doe')
expect(result[:posts].size).to be(2)

post_1, post_2 = result[:posts]
post1, post2 = result[:posts]

expect(post_1).to include(data[:posts][0])
expect(post_2).to include(data[:posts][1])
expect(post1).to include(data[:posts][0])
expect(post2).to include(data[:posts][1])
end
end
end
Expand Down
1 change: 1 addition & 0 deletions changeset/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
%w[pry-byebug debug pry].each do |gem|
require gem
rescue LoadError
# ignore
else
break
end
Expand Down
2 changes: 1 addition & 1 deletion changeset/spec/unit/associate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
end

before do
[:todos, :projects, :people].each { |table| conn.drop_table?(table) }
%i[todos projects people].each { |table| conn.drop_table?(table) }

conn.create_table :people do
primary_key :id
Expand Down
2 changes: 1 addition & 1 deletion core/lib/rom/associations/definitions/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Abstract
def self.new(source, target, **opts)
source_name = Relation::Name[source]
target_name = resolve_target_name(target, opts)
options = process_options(target_name, Hash[opts])
options = process_options(target_name, opts.to_h)

super(source_name, target_name, **options)
end
Expand Down
2 changes: 1 addition & 1 deletion core/lib/rom/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def [](key)

# @api private
def fetch_or_store(*args, &)
cache.fetch_or_store([namespace, args.hash].hash, &)
cache.fetch_or_store([namespace, args].hash, &)
end

# @api private
Expand Down
4 changes: 4 additions & 0 deletions core/lib/rom/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ def execute(*)
# This method will apply before/after hooks automatically
#
# @api public
#
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
def call(*args, &)
tuples =
if hooks?
Expand Down Expand Up @@ -298,6 +300,8 @@ def call(*args, &)
tuples
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity

alias_method :[], :call

# Curry this command with provided args
Expand Down
6 changes: 6 additions & 0 deletions core/lib/rom/command_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def visit(ast, *args)
private

# @api private
#
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
def visit_relation(node, parent_relation = nil)
name, header, meta = node
other = header.map { |attr| visit(attr, name) }.compact
Expand Down Expand Up @@ -167,6 +169,7 @@ def visit_relation(node, parent_relation = nil)
[name, id]
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity

# @api private
def visit_attribute(*_args)
Expand All @@ -187,6 +190,8 @@ def visit_attribute(*_args)
# @return [ROM::Command]
#
# @api private
#
# rubocop:disable Metrics/AbcSize
def register_command(rel_name, type, rel_meta, parent_relation = nil)
relation = relations[rel_name]

Expand Down Expand Up @@ -216,6 +221,7 @@ def register_command(rel_name, type, rel_meta, parent_relation = nil)
registry[rel_name][type] = klass.build(relation)
end
end
# rubocop:enable Metrics/AbcSize

# Return default result type
#
Expand Down
3 changes: 3 additions & 0 deletions core/lib/rom/commands/composite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Composite < Pipeline::Composite
# @return [Object]
#
# @api public
#
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def call(*args)
response = left.call(*args)

Expand All @@ -35,6 +37,7 @@ def call(*args)
end
end
alias_method :[], :call
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# @api private
def graph?
Expand Down
3 changes: 3 additions & 0 deletions core/lib/rom/commands/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Graph
# @return [Array] nested array with command results
#
# @api public
#
# rubocop:disable Metrics/PerceivedComplexity
def call(*args)
left = root.call(*args)

Expand All @@ -73,6 +75,7 @@ def call(*args)
[left, right]
end
end
# rubocop:enable Metrics/PerceivedComplexity

# @api private
def graph?
Expand Down
2 changes: 2 additions & 0 deletions core/lib/rom/commands/graph/class_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def build(registry, options, path = EMPTY_ARRAY)
end

# @api private
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
def build_command(registry, spec, other, path)
cmd_opts, nodes = other

Expand Down Expand Up @@ -58,6 +59,7 @@ def build_command(registry, spec, other, path)
command
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions core/lib/rom/commands/graph/input_evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def initialize(tuple_path, excluded_keys)
# @param [Integer] index Optional index
#
# @return [Hash]
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
def call(input, index = nil)
value =
begin
Expand All @@ -88,6 +89,7 @@ def call(input, index = nil)
value
end
end
# rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions core/lib/rom/commands/lazy/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Create < Lazy
# @return [Hash,Array<Hash>]
#
# @api public
# rubocop:disable Metrics/AbcSize
def call(*args)
first = args.first
last = args.last
Expand All @@ -29,6 +30,7 @@ def call(*args)
command.call(input, *args[1..size - 1])
end
end
# rubocop:enable Metrics/AbcSize
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions core/lib/rom/commands/lazy/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Update < Lazy
# @return [Hash, Array<Hash>]
#
# @api public
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
def call(*args)
first = args.first
last = args.last
Expand All @@ -40,6 +41,7 @@ def call(*args)
end
end
end
# rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions core/lib/rom/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def __define_with__
undef_method(:with) if method_defined?(:with)

class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
def with(**new_options)
if new_options.empty?
self
else
self.class.new(#{seq_names}**options, **new_options)
end
end
def with(**new_options) # def with(**new_options)
if new_options.empty? # if new_options.empty?
self # self
else # else
self.class.new(#{seq_names}**options, **new_options) # self.class.new(relation, **options, **new_options)
end # end
end # end
RUBY
end
end
Expand Down
3 changes: 2 additions & 1 deletion core/lib/rom/lint/enumerable_dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class EnumerableDataset < ROM::Lint::Linter
#
# @api public
def initialize(dataset, data)
super()
@dataset = dataset
@data = data
end
Expand All @@ -35,7 +36,7 @@ def initialize(dataset, data)
# @api public
def lint_each
result = []
dataset.each do |tuple|
dataset.each do |tuple| # rubocop:disable Style/MapIntoArray
result << tuple
end
return if result == data
Expand Down
4 changes: 3 additions & 1 deletion core/lib/rom/lint/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Gateway < ROM::Lint::Linter
# @param [Class] gateway
# @param [String] uri optional
def initialize(identifier, gateway, uri = nil)
super()
@identifier = identifier
@gateway = gateway
@uri = uri
Expand Down Expand Up @@ -89,7 +90,8 @@ def lint_transaction_support
# Lint: Ensure +gateway_instance+ returns adapter name
def lint_adapter_reader
if gateway_instance.adapter != identifier
complain "#{gateway_instance} must have the adapter identifier set to #{identifier.inspect}"
complain "#{gateway_instance} must have the adapter " \
"identifier set to #{identifier.inspect}"
end
rescue MissingAdapterIdentifierError
complain "#{gateway_instance} is missing the adapter identifier"
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 @@ -18,7 +18,7 @@ module Lint
# @api public
class Linter
# A failure raised by +complain+
Failure = Class.new(StandardError)
Failure = ::Class.new(::StandardError)

# Iterate over all lint methods
#
Expand Down
2 changes: 2 additions & 0 deletions core/lib/rom/mapper/attribute_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Mapper
# TODO: break this madness down into smaller pieces
#
# @api private
# rubocop:disable Metrics/ClassLength
class AttributeDSL
include ModelDSL

Expand Down Expand Up @@ -486,5 +487,6 @@ def ensure_mapper_configuration(method_name, args, block_present)
end
end
end
# rubocop:enable Metrics/ClassLength
end
end
2 changes: 2 additions & 0 deletions core/lib/rom/mapper_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def visit(node)
__send__("visit_#{name}", node)
end

# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
def visit_relation(node)
rel_name, header, meta_options = node
name = meta_options[:combine_name] || meta_options[:alias] || rel_name
Expand All @@ -68,6 +69,7 @@ def visit_relation(node)
options
end
end
# rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity

def visit_attribute(node)
name, _, meta_options = node
Expand Down
2 changes: 2 additions & 0 deletions core/lib/rom/memory/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Dataset
# @return [Dataset]
#
# @api public
# rubocop:disable Metrics/AbcSize
def join(*args)
left, right = args.size > 1 ? args : [self, args.first]

Expand All @@ -33,6 +34,7 @@ def join(*args)

self.class.new(tuples, **options)
end
# rubocop:enable Metrics/AbcSize

# Restrict a dataset
#
Expand Down
Loading

0 comments on commit 81522e7

Please sign in to comment.