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 1a21eab commit c9452c4
Show file tree
Hide file tree
Showing 36 changed files with 183 additions and 105 deletions.
42 changes: 38 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ AllCops:
NewCops: enable
TargetRubyVersion: 3.1

Gemspec/RequiredRubyVersion:
Exclude:
- "rom.gemspec"
- "repository/rom-repository.gemspec"
- "changeset/rom-changeset.gemspec"
- "core/rom-core.gemspec"

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent

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

Lint/ConstantDefinitionInBlock:
Exclude:
- "spec/**/*_spec.rb"
- "core/spec/**/*_spec.rb"
- "repository/spec/**/*_spec.rb"
- "changeset/spec/**/*_spec.rb"
- "spec/**/*.rb"
- "core/spec/**/*.rb"
- "repository/spec/**/*.rb"
- "changeset/spec/**/*.rb"

Lint/EmptyBlock:
Exclude:
- "spec/**/*.rb"
- "core/spec/**/*.rb"
- "repository/spec/**/*.rb"
- "changeset/spec/**/*.rb"

Lint/EmptyClass:
Exclude:
- "spec/**/*.rb"
- "core/spec/**/*.rb"
- "repository/spec/**/*.rb"
- "changeset/spec/**/*.rb"

Lint/SuppressedException:
Exclude:
Expand Down Expand Up @@ -57,6 +78,9 @@ Naming/MemoizedInstanceVariableName:
Naming/MethodName:
Enabled: false

Naming/MethodParameterName:
Enabled: false

Naming/PredicateName:
Enabled: false

Expand Down Expand Up @@ -110,6 +134,16 @@ Style/IfUnlessModifier:
Style/LambdaCall:
Enabled: false

Style/MapIntoArray:
Exclude:
- "core/spec/**/*.rb"

Style/OpenStructUse:
Exclude:
- "core/spec/**/*.rb"
- "repository/spec/**/*.rb"
- "changeset/spec/**/*.rb"

Style/StabbyLambdaParentheses:
Enabled: false

Expand Down
3 changes: 0 additions & 3 deletions changeset/rom-changeset.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,4 @@ Gem::Specification.new do |gem|
gem.add_dependency 'dry-core', '~> 1.0'
gem.add_dependency 'rom-core', '~> 5.3'
gem.add_dependency 'transproc', '~> 1.0', '>= 1.1.0'

gem.add_development_dependency 'rake', '~> 11.2'
gem.add_development_dependency 'rspec', '~> 3.5'
end
4 changes: 2 additions & 2 deletions core/lib/rom/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ module InstanceMethods
#
# @api public
def options
@__options__ ||= self.class.dry_initializer.definitions.values.each_with_object({}) do |item, obj|
obj[item.target] = instance_variable_get(item.ivar)
@__options__ ||= self.class.dry_initializer.definitions.values.to_h do |item|
[item.target, instance_variable_get(item.ivar)]
end
end

Expand Down
1 change: 1 addition & 0 deletions core/lib/rom/memory/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Gateway < ROM::Gateway

# @api private
def initialize
super
@connection = Storage.new
end

Expand Down
1 change: 1 addition & 0 deletions core/lib/rom/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Processor
#
# @api private
def self.inherited(processor)
super
Mapper.register_processor(processor)
end

Expand Down
1 change: 1 addition & 0 deletions core/lib/rom/processor/transproc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def self.build(mapper, header)

# @api private
def initialize(mapper, header)
super()
@mapper = mapper
@header = header
@model = header.model
Expand Down
19 changes: 12 additions & 7 deletions core/lib/rom/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ class Relation
# @!attribute [r] name
# @return [Object] The relation name
# @api public
option :name, default: -> { self.class.schema ? self.class.schema.name : self.class.default_name }
option :name, default: lambda {
self.class.schema ? self.class.schema.name : self.class.default_name
}

# @!attribute [r] input_schema
# @return [Object#[]] tuple processing function, uses schema or defaults to Hash[]
Expand Down Expand Up @@ -191,12 +193,14 @@ class Relation
#
# @example accessing canonical attribute
# users[:id]
# # => #<ROM::SQL::Attribute[Integer] primary_key=true name=:id source=ROM::Relation::Name(users)>
# # => #<ROM::SQL::Attribute[Integer] primary_key=true
# # name=:id source=ROM::Relation::Name(users)>
#
# @example accessing joined attribute
# tasks_with_users = tasks.join(users).select_append(tasks[:title])
# tasks_with_users[:title, :tasks]
# # => #<ROM::SQL::Attribute[String] primary_key=false name=:title source=ROM::Relation::Name(tasks)>
# # => #<ROM::SQL::Attribute[String] primary_key=false
# # name=:title source=ROM::Relation::Name(tasks)>
#
# @return [Attribute]
#
Expand All @@ -214,11 +218,11 @@ def [](name)
# @return [Enumerator] if block is not provided
#
# @api public
def each
def each(&)
return to_enum unless block_given?

if auto_map?
mapper.(dataset.map { |tuple| output_schema[tuple] }).each { |struct| yield(struct) }
mapper.(dataset.map { |tuple| output_schema[tuple] }).each(&)
else
dataset.each { |tuple| yield(output_schema[tuple]) }
end
Expand Down Expand Up @@ -420,7 +424,7 @@ def new(dataset, **new_opts)
if new_opts.empty?
options
elsif new_opts.key?(:schema)
options.merge(new_opts).reject { |k, _| k == :input_schema || k == :output_schema }
options.merge(new_opts).reject { |k, _| %i[input_schema output_schema].include?(k) }
else
options.merge(new_opts)
end
Expand Down Expand Up @@ -476,7 +480,8 @@ def attr_ast

# @api private
def meta_ast
meta = self.meta.merge(dataset: name.dataset, alias: name.aliaz, struct_namespace: options[:struct_namespace])
meta = self.meta.merge(dataset: name.dataset, alias: name.aliaz,
struct_namespace: options[:struct_namespace])
meta[:model] = false unless auto_struct? || meta[:model]
meta
end
Expand Down
8 changes: 5 additions & 3 deletions core/lib/rom/schema/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def attribute(name, type_or_options, options = EMPTY_HASH)
# @return [AssociationDSL]
#
# @api public
def associations(&block)
@associations_dsl = AssociationsDSL.new(relation, &block)
def associations(&)
@associations_dsl = AssociationsDSL.new(relation, &)
end

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

# Specify which key(s) should be the primary key
Expand Down
2 changes: 1 addition & 1 deletion core/lib/rom/setup/auto_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def mappers
#
# @api private
def load_entities(entity)
Dir[globs[entity]].sort.map do |file|
Dir[globs[entity]].map do |file|
require file
klass_name =
case namespace
Expand Down
13 changes: 10 additions & 3 deletions core/lib/rom/setup/finalize/finalize_relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ def run!
"Relation with name #{key.inspect} registered more than once"
end

klass.use(:registry_reader, klass: klass, relation_readers_module: relation_readers_module)
klass.use(:registry_reader, klass: klass,
relation_readers_module: relation_readers_module)

notifications.trigger('configuration.relations.class.ready', relation: klass, adapter: klass.adapter)
notifications.trigger('configuration.relations.class.ready', relation: klass,
adapter: klass.adapter)

relations[key] = build_relation(klass, registry)
end
Expand Down Expand Up @@ -116,7 +118,12 @@ def build_relation(klass, registry)
dataset: dataset, relation: klass, adapter: klass.adapter
)

options = { __registry__: registry, mappers: mapper_registry(rel_key, klass), schema: schema, **plugin_options }
options = {
__registry__: registry,
mappers: mapper_registry(rel_key, klass),
schema: schema,
**plugin_options
}

klass.new(dataset, **options)
end
Expand Down
4 changes: 3 additions & 1 deletion core/lib/rom/support/memoizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ def self.included(klass)
attr_reader :__memoized__

# @api private
class Memoizer < Module
class Memoizer < ::Module
attr_reader :klass

attr_reader :names

# @api private
def initialize(klass, names)
super()
@names = names
@klass = klass
define_memoizable_names!
Expand Down
1 change: 1 addition & 0 deletions core/rakelib/rubocop.rake
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ begin
end
end
rescue LoadError
# ignore
end
3 changes: 0 additions & 3 deletions core/rom-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,4 @@ Gem::Specification.new do |gem|
gem.add_dependency 'dry-struct', '~> 1.0'
gem.add_dependency 'dry-types', '~> 1.6'
gem.add_dependency 'transproc', '~> 1.0', '>= 1.1.0'

gem.add_development_dependency 'rake', '~> 10.3'
gem.add_development_dependency 'rspec', '~> 3.5'
end
4 changes: 2 additions & 2 deletions core/spec/integration/commands/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class Test::TaskMapper < ROM::Mapper
end

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

expect(result.call).to eql(name: 'Piotr', title: 'Finish command-api')
end
Expand Down
5 changes: 4 additions & 1 deletion core/spec/integration/mapper/reusing_mappers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class Test::TaskMapper < ROM::Mapper
end

mapper = Test::TaskMapper.build
relation = [{ title: 'Task One', priority: { value: '1' } }, { title: 'Task Two', priority: { value: '2' } }]
relation = [
{ title: 'Task One', priority: { value: '1' } },
{ title: 'Task Two', priority: { value: '2' } }
]
result = mapper.call(relation)

expect(result).to eql([
Expand Down
1 change: 1 addition & 0 deletions core/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
26 changes: 13 additions & 13 deletions core/spec/unit/rom/auto_curry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ def self.curried(*)

def initialize(*); end

def arity_0
def arity0
0
end

def arity_1(x)
x
def arity1(foo)
foo
end

def arity_2(x, y)
[x, y]
def arity2(foo, bar)
[foo, bar]
end

def arity_many(*args)
Expand All @@ -35,11 +35,11 @@ def yielding_block(arg)
yield(arg)
end

def repeated(x); end
def repeated(xyz); end

undef repeated

def repeated(x); end
def repeated(xyz); end

protected

Expand All @@ -51,21 +51,21 @@ def leave_me_alone(foo)

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

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

it 'auto-curries method with arity == 1' do
expect(object.arity_1).to be_instance_of(klass)
expect(object.arity_1(1)).to be(1)
expect(object.arity1).to be_instance_of(klass)
expect(object.arity1(1)).to be(1)
end

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

it 'auto-curries method with arity < 0' do
Expand Down
Loading

0 comments on commit c9452c4

Please sign in to comment.