Skip to content

Commit c9452c4

Browse files
committed
Address rubocop offenses
1 parent 1a21eab commit c9452c4

36 files changed

+183
-105
lines changed

.rubocop.yml

+38-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ AllCops:
44
NewCops: enable
55
TargetRubyVersion: 3.1
66

7+
Gemspec/RequiredRubyVersion:
8+
Exclude:
9+
- "rom.gemspec"
10+
- "repository/rom-repository.gemspec"
11+
- "changeset/rom-changeset.gemspec"
12+
- "core/rom-core.gemspec"
13+
714
Layout/FirstArrayElementIndentation:
815
EnforcedStyle: consistent
916

@@ -22,10 +29,24 @@ Lint/BooleanSymbol:
2229

2330
Lint/ConstantDefinitionInBlock:
2431
Exclude:
25-
- "spec/**/*_spec.rb"
26-
- "core/spec/**/*_spec.rb"
27-
- "repository/spec/**/*_spec.rb"
28-
- "changeset/spec/**/*_spec.rb"
32+
- "spec/**/*.rb"
33+
- "core/spec/**/*.rb"
34+
- "repository/spec/**/*.rb"
35+
- "changeset/spec/**/*.rb"
36+
37+
Lint/EmptyBlock:
38+
Exclude:
39+
- "spec/**/*.rb"
40+
- "core/spec/**/*.rb"
41+
- "repository/spec/**/*.rb"
42+
- "changeset/spec/**/*.rb"
43+
44+
Lint/EmptyClass:
45+
Exclude:
46+
- "spec/**/*.rb"
47+
- "core/spec/**/*.rb"
48+
- "repository/spec/**/*.rb"
49+
- "changeset/spec/**/*.rb"
2950

3051
Lint/SuppressedException:
3152
Exclude:
@@ -57,6 +78,9 @@ Naming/MemoizedInstanceVariableName:
5778
Naming/MethodName:
5879
Enabled: false
5980

81+
Naming/MethodParameterName:
82+
Enabled: false
83+
6084
Naming/PredicateName:
6185
Enabled: false
6286

@@ -110,6 +134,16 @@ Style/IfUnlessModifier:
110134
Style/LambdaCall:
111135
Enabled: false
112136

137+
Style/MapIntoArray:
138+
Exclude:
139+
- "core/spec/**/*.rb"
140+
141+
Style/OpenStructUse:
142+
Exclude:
143+
- "core/spec/**/*.rb"
144+
- "repository/spec/**/*.rb"
145+
- "changeset/spec/**/*.rb"
146+
113147
Style/StabbyLambdaParentheses:
114148
Enabled: false
115149

changeset/rom-changeset.gemspec

-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,4 @@ Gem::Specification.new do |gem|
2424
gem.add_dependency 'dry-core', '~> 1.0'
2525
gem.add_dependency 'rom-core', '~> 5.3'
2626
gem.add_dependency 'transproc', '~> 1.0', '>= 1.1.0'
27-
28-
gem.add_development_dependency 'rake', '~> 11.2'
29-
gem.add_development_dependency 'rspec', '~> 3.5'
3027
end

core/lib/rom/initializer.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ module InstanceMethods
6262
#
6363
# @api public
6464
def options
65-
@__options__ ||= self.class.dry_initializer.definitions.values.each_with_object({}) do |item, obj|
66-
obj[item.target] = instance_variable_get(item.ivar)
65+
@__options__ ||= self.class.dry_initializer.definitions.values.to_h do |item|
66+
[item.target, instance_variable_get(item.ivar)]
6767
end
6868
end
6969

core/lib/rom/memory/gateway.rb

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Gateway < ROM::Gateway
2424

2525
# @api private
2626
def initialize
27+
super
2728
@connection = Storage.new
2829
end
2930

core/lib/rom/processor.rb

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Processor
1313
#
1414
# @api private
1515
def self.inherited(processor)
16+
super
1617
Mapper.register_processor(processor)
1718
end
1819

core/lib/rom/processor/transproc.rb

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def self.build(mapper, header)
8484

8585
# @api private
8686
def initialize(mapper, header)
87+
super()
8788
@mapper = mapper
8889
@header = header
8990
@model = header.model

core/lib/rom/relation.rb

+12-7
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ class Relation
144144
# @!attribute [r] name
145145
# @return [Object] The relation name
146146
# @api public
147-
option :name, default: -> { self.class.schema ? self.class.schema.name : self.class.default_name }
147+
option :name, default: lambda {
148+
self.class.schema ? self.class.schema.name : self.class.default_name
149+
}
148150

149151
# @!attribute [r] input_schema
150152
# @return [Object#[]] tuple processing function, uses schema or defaults to Hash[]
@@ -191,12 +193,14 @@ class Relation
191193
#
192194
# @example accessing canonical attribute
193195
# users[:id]
194-
# # => #<ROM::SQL::Attribute[Integer] primary_key=true name=:id source=ROM::Relation::Name(users)>
196+
# # => #<ROM::SQL::Attribute[Integer] primary_key=true
197+
# # name=:id source=ROM::Relation::Name(users)>
195198
#
196199
# @example accessing joined attribute
197200
# tasks_with_users = tasks.join(users).select_append(tasks[:title])
198201
# tasks_with_users[:title, :tasks]
199-
# # => #<ROM::SQL::Attribute[String] primary_key=false name=:title source=ROM::Relation::Name(tasks)>
202+
# # => #<ROM::SQL::Attribute[String] primary_key=false
203+
# # name=:title source=ROM::Relation::Name(tasks)>
200204
#
201205
# @return [Attribute]
202206
#
@@ -214,11 +218,11 @@ def [](name)
214218
# @return [Enumerator] if block is not provided
215219
#
216220
# @api public
217-
def each
221+
def each(&)
218222
return to_enum unless block_given?
219223

220224
if auto_map?
221-
mapper.(dataset.map { |tuple| output_schema[tuple] }).each { |struct| yield(struct) }
225+
mapper.(dataset.map { |tuple| output_schema[tuple] }).each(&)
222226
else
223227
dataset.each { |tuple| yield(output_schema[tuple]) }
224228
end
@@ -420,7 +424,7 @@ def new(dataset, **new_opts)
420424
if new_opts.empty?
421425
options
422426
elsif new_opts.key?(:schema)
423-
options.merge(new_opts).reject { |k, _| k == :input_schema || k == :output_schema }
427+
options.merge(new_opts).reject { |k, _| %i[input_schema output_schema].include?(k) }
424428
else
425429
options.merge(new_opts)
426430
end
@@ -476,7 +480,8 @@ def attr_ast
476480

477481
# @api private
478482
def meta_ast
479-
meta = self.meta.merge(dataset: name.dataset, alias: name.aliaz, struct_namespace: options[:struct_namespace])
483+
meta = self.meta.merge(dataset: name.dataset, alias: name.aliaz,
484+
struct_namespace: options[:struct_namespace])
480485
meta[:model] = false unless auto_struct? || meta[:model]
481486
meta
482487
end

core/lib/rom/schema/dsl.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def attribute(name, type_or_options, options = EMPTY_HASH)
111111
# @return [AssociationDSL]
112112
#
113113
# @api public
114-
def associations(&block)
115-
@associations_dsl = AssociationsDSL.new(relation, &block)
114+
def associations(&)
115+
@associations_dsl = AssociationsDSL.new(relation, &)
116116
end
117117

118118
# Builds a representation of the information needed to create an
@@ -146,7 +146,9 @@ def build_type(type, options = EMPTY_HASH)
146146
type.meta(source: relation, read: type.meta[:read].optional)
147147
else
148148
type.meta(source: relation)
149-
end.meta(Attribute::META_OPTIONS.map { |opt| [opt, options[opt]] if options.key?(opt) }.compact.to_h)
149+
end.meta(Attribute::META_OPTIONS.map { |opt|
150+
[opt, options[opt]] if options.key?(opt)
151+
}.compact.to_h)
150152
end
151153

152154
# Specify which key(s) should be the primary key

core/lib/rom/setup/auto_registration.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def mappers
7878
#
7979
# @api private
8080
def load_entities(entity)
81-
Dir[globs[entity]].sort.map do |file|
81+
Dir[globs[entity]].map do |file|
8282
require file
8383
klass_name =
8484
case namespace

core/lib/rom/setup/finalize/finalize_relations.rb

+10-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ def run!
5656
"Relation with name #{key.inspect} registered more than once"
5757
end
5858

59-
klass.use(:registry_reader, klass: klass, relation_readers_module: relation_readers_module)
59+
klass.use(:registry_reader, klass: klass,
60+
relation_readers_module: relation_readers_module)
6061

61-
notifications.trigger('configuration.relations.class.ready', relation: klass, adapter: klass.adapter)
62+
notifications.trigger('configuration.relations.class.ready', relation: klass,
63+
adapter: klass.adapter)
6264

6365
relations[key] = build_relation(klass, registry)
6466
end
@@ -116,7 +118,12 @@ def build_relation(klass, registry)
116118
dataset: dataset, relation: klass, adapter: klass.adapter
117119
)
118120

119-
options = { __registry__: registry, mappers: mapper_registry(rel_key, klass), schema: schema, **plugin_options }
121+
options = {
122+
__registry__: registry,
123+
mappers: mapper_registry(rel_key, klass),
124+
schema: schema,
125+
**plugin_options
126+
}
120127

121128
klass.new(dataset, **options)
122129
end

core/lib/rom/support/memoizable.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ def self.included(klass)
2626
attr_reader :__memoized__
2727

2828
# @api private
29-
class Memoizer < Module
29+
class Memoizer < ::Module
3030
attr_reader :klass
31+
3132
attr_reader :names
3233

3334
# @api private
3435
def initialize(klass, names)
36+
super()
3537
@names = names
3638
@klass = klass
3739
define_memoizable_names!

core/rakelib/rubocop.rake

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ begin
1616
end
1717
end
1818
rescue LoadError
19+
# ignore
1920
end

core/rom-core.gemspec

-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,4 @@ Gem::Specification.new do |gem|
3131
gem.add_dependency 'dry-struct', '~> 1.0'
3232
gem.add_dependency 'dry-types', '~> 1.6'
3333
gem.add_dependency 'transproc', '~> 1.0', '>= 1.1.0'
34-
35-
gem.add_development_dependency 'rake', '~> 10.3'
36-
gem.add_development_dependency 'rspec', '~> 3.5'
3734
end

core/spec/integration/commands/create_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class Test::TaskMapper < ROM::Mapper
6868
end
6969

7070
it 'inserts user and associated task when things go well' do
71-
result = users.create.curry(name: 'Piotr', email: '[email protected]')
72-
.>> tasks.create.curry(title: 'Finish command-api')
71+
result = users.create.curry(name: 'Piotr', email: '[email protected]') >>
72+
tasks.create.curry(title: 'Finish command-api')
7373

7474
expect(result.call).to eql(name: 'Piotr', title: 'Finish command-api')
7575
end

core/spec/integration/mapper/reusing_mappers_spec.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class Test::TaskMapper < ROM::Mapper
3434
end
3535

3636
mapper = Test::TaskMapper.build
37-
relation = [{ title: 'Task One', priority: { value: '1' } }, { title: 'Task Two', priority: { value: '2' } }]
37+
relation = [
38+
{ title: 'Task One', priority: { value: '1' } },
39+
{ title: 'Task Two', priority: { value: '2' } }
40+
]
3841
result = mapper.call(relation)
3942

4043
expect(result).to eql([

core/spec/spec_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
%w[pry-byebug debug pry].each do |gem|
2222
require gem
2323
rescue LoadError
24+
# ignore
2425
else
2526
break
2627
end

core/spec/unit/rom/auto_curry_spec.rb

+13-13
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ def self.curried(*)
1515

1616
def initialize(*); end
1717

18-
def arity_0
18+
def arity0
1919
0
2020
end
2121

22-
def arity_1(x)
23-
x
22+
def arity1(foo)
23+
foo
2424
end
2525

26-
def arity_2(x, y)
27-
[x, y]
26+
def arity2(foo, bar)
27+
[foo, bar]
2828
end
2929

3030
def arity_many(*args)
@@ -35,11 +35,11 @@ def yielding_block(arg)
3535
yield(arg)
3636
end
3737

38-
def repeated(x); end
38+
def repeated(xyz); end
3939

4040
undef repeated
4141

42-
def repeated(x); end
42+
def repeated(xyz); end
4343

4444
protected
4545

@@ -51,21 +51,21 @@ def leave_me_alone(foo)
5151

5252
it 'registers auto-curried methods' do
5353
expect(object.class.auto_curried_methods)
54-
.to eql(%i[arity_1 arity_2 arity_many yielding_block repeated].to_set)
54+
.to eql(%i[arity1 arity2 arity_many yielding_block repeated].to_set)
5555
end
5656

5757
it 'auto-curries method with arity == 0' do
58-
expect(object.arity_0).to be(0)
58+
expect(object.arity0).to be(0)
5959
end
6060

6161
it 'auto-curries method with arity == 1' do
62-
expect(object.arity_1).to be_instance_of(klass)
63-
expect(object.arity_1(1)).to be(1)
62+
expect(object.arity1).to be_instance_of(klass)
63+
expect(object.arity1(1)).to be(1)
6464
end
6565

6666
it 'auto-curries method with arity > 0' do
67-
expect(object.arity_2).to be_instance_of(klass)
68-
expect(object.arity_2(1, 2)).to eql([1, 2])
67+
expect(object.arity2).to be_instance_of(klass)
68+
expect(object.arity2(1, 2)).to eql([1, 2])
6969
end
7070

7171
it 'auto-curries method with arity < 0' do

0 commit comments

Comments
 (0)