Skip to content

Commit

Permalink
Address some rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 2, 2025
1 parent aadead2 commit 1a21eab
Show file tree
Hide file tree
Showing 32 changed files with 173 additions and 86 deletions.
16 changes: 16 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ Layout/SpaceInLambdaLiteral:
Lint/BooleanSymbol:
Enabled: false

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

Lint/SuppressedException:
Exclude:
- "spec/spec_helper.rb"
Expand Down Expand Up @@ -53,6 +60,9 @@ Naming/MethodName:
Naming/PredicateName:
Enabled: false

Style/AccessorGrouping:
EnforcedStyle: separated

Style/AccessModifierDeclarations:
Enabled: false

Expand All @@ -69,6 +79,9 @@ Style/BlockDelimiters:
Style/ClassAndModuleChildren:
Exclude:
- "spec/**/*_spec.rb"
- "core/spec/**/*_spec.rb"
- "repository/spec/**/*_spec.rb"
- "changeset/spec/**/*_spec.rb"

Style/ConditionalAssignment:
Enabled: false
Expand All @@ -88,6 +101,9 @@ Style/FormatString:
Style/GuardClause:
Enabled: false

Style/HashAsLastArrayItem:
EnforcedStyle: no_braces

Style/IfUnlessModifier:
Enabled: false

Expand Down
4 changes: 3 additions & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ rom = ROM.container(config)
repo = UserRepo.new(rom)

class Context
attr_reader :rom, :repo
attr_reader :rom

attr_reader :repo

def initialize(rom, repo)
@rom = rom
Expand Down
14 changes: 7 additions & 7 deletions changeset/lib/rom/changeset/stateful.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def self.pipes
# @return [Changeset]
#
# @api public
def map(*steps, &block)
extend(*steps, for_diff: true, &block)
def map(*steps, &)
extend(*steps, for_diff: true, &)
end

# Pipe changeset's data using custom steps define on the pipe.
Expand All @@ -150,10 +150,10 @@ def map(*steps, &block)
# @api public
def extend(*steps, **options, &block)
if block
if !steps.empty?
extend(*steps, **options).extend(**options, &block)
else
if steps.empty?
with(pipe: pipe.compose(Pipe.new(block).bind(self), **options))
else
extend(*steps, **options).extend(**options, &block)
end
else
with(pipe: steps.reduce(pipe.with(**options)) { |a, e| a.compose(pipe[e], **options) })
Expand Down Expand Up @@ -266,9 +266,9 @@ def respond_to_missing?(meth, include_private = false)
end

# @api private
def method_missing(meth, *args, **kwargs, &block)
def method_missing(meth, ...)
if __data__.respond_to?(meth)
response = __data__.__send__(meth, *args, **kwargs, &block)
response = __data__.__send__(meth, ...)

if response.is_a?(__data__.class)
with(__data__: response)
Expand Down
14 changes: 11 additions & 3 deletions changeset/spec/shared/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ module Models
class User
include Dry::Equalizer(:id, :name)

attr_reader :id, :name
attr_reader :id

attr_reader :name

def initialize(attrs)
@id = attrs[:id]
Expand All @@ -22,7 +24,11 @@ def initialize(attrs)
class Task
include Dry::Equalizer(:id, :user_id, :title)

attr_reader :id, :user_id, :title
attr_reader :id

attr_reader :user_id

attr_reader :title

def initialize(attrs)
@id = attrs[:id]
Expand All @@ -34,7 +40,9 @@ def initialize(attrs)
class Tag
include Dry::Equalizer(:id, :task_id, :name)

attr_reader :id, :task_id, :name
attr_reader :id
attr_reader :task_id
attr_reader :name

def initialize(attrs)
@id = attrs[:id]
Expand Down
4 changes: 3 additions & 1 deletion core/lib/rom/command_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module ROM
#
# @api private
class CommandProxy
attr_reader :command, :root
attr_reader :command

attr_reader :root

# @api private
def initialize(command, root = Inflector.singularize(command.name.relation).to_sym)
Expand Down
6 changes: 5 additions & 1 deletion core/lib/rom/configuration_dsl/command_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ module ConfigurationDSL
#
# @private
class CommandDSL
attr_reader :relation, :adapter, :command_classes
attr_reader :relation

attr_reader :adapter

attr_reader :command_classes

# @api private
def initialize(relation, adapter = nil, &)
Expand Down
6 changes: 5 additions & 1 deletion core/lib/rom/configuration_dsl/mapper_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ module ConfigurationDSL
#
# @private
class MapperDSL
attr_reader :configuration, :mapper_classes, :defined_mappers
attr_reader :configuration

attr_reader :mapper_classes

attr_reader :defined_mappers

# @api private
def initialize(configuration, mapper_classes, block)
Expand Down
6 changes: 4 additions & 2 deletions core/lib/rom/configuration_dsl/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def self.build_class(name, options = EMPTY_HASH)
class_name = "ROM::Relation[#{Inflector.camelize(name)}]"
adapter = options.fetch(:adapter)

Dry::Core::ClassBuilder.new(name: class_name, parent: ROM::Relation[adapter]).call do |klass|
::Dry::Core::ClassBuilder.new(
name: class_name, parent: ::ROM::Relation[adapter]
).call do |klass|
klass.gateway(options.fetch(:gateway, :default))
klass.schema(name) {}
klass.schema(name) { nil }
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion core/lib/rom/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module ROM
class Environment
include Configurable

attr_reader :gateways, :gateways_map
attr_reader :gateways

attr_reader :gateways_map

# @api private
def initialize(*args)
Expand Down
26 changes: 18 additions & 8 deletions core/lib/rom/mapper/attribute_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ class Mapper
class AttributeDSL
include ModelDSL

attr_reader :attributes, :options, :copy_keys, :symbolize_keys, :reject_keys, :steps
attr_reader :attributes

attr_reader :options

attr_reader :copy_keys

attr_reader :symbolize_keys

attr_reader :reject_keys

attr_reader :steps

# @param [Array] attributes accumulator array
# @param [Hash] options
Expand Down Expand Up @@ -88,7 +98,7 @@ def attribute(name, options = EMPTY_HASH, &block)
end

def exclude(name)
attributes << [name, { exclude: true }]
attributes << [name, exclude: true]
end

# Perform transformations sequentially
Expand All @@ -101,8 +111,8 @@ def exclude(name)
# end
#
# @api public
def step(options = EMPTY_HASH, &block)
steps << new(options, &block)
def step(options = EMPTY_HASH, &)
steps << new(options, &)
end

# Define an embedded attribute
Expand Down Expand Up @@ -330,8 +340,8 @@ def unfold(name, options = EMPTY_HASH)
# @option options [Symbol] :type The type, either :array (default) or :hash
#
# @api public
def combine(name, options, &block)
dsl = new(options, &block)
def combine(name, options, &)
dsl = new(options, &)

attr_opts = {
type: options.fetch(:type, :array),
Expand Down Expand Up @@ -409,8 +419,8 @@ def dsl(name_or_attrs, options, &block)
# Used by embedded, wrap and group
#
# @api private
def attributes_from_block(name, options, &block)
dsl = new(options, &block)
def attributes_from_block(name, options, &)
dsl = new(options, &)
header = dsl.header
add_attribute(name, options.update(header: header))
header.each { |attr| remove(attr.key) unless name == attr.key }
Expand Down
6 changes: 5 additions & 1 deletion core/lib/rom/mapper/model_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ class Mapper
#
# @private
module ModelDSL
attr_reader :attributes, :builder, :klass
attr_reader :attributes

attr_reader :builder

attr_reader :klass

DEFAULT_TYPE = :poro

Expand Down
6 changes: 5 additions & 1 deletion core/lib/rom/model_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ module ROM
class ModelBuilder
attr_reader :name

attr_reader :const_name, :namespace, :klass
attr_reader :const_name

attr_reader :namespace

attr_reader :klass

# Return model builder subclass based on type
#
Expand Down
4 changes: 3 additions & 1 deletion core/lib/rom/plugins/command/timestamps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ module Command
#
# @api public
class Timestamps < Module
attr_reader :timestamps, :datestamps
attr_reader :timestamps

attr_reader :datestamps

def initialize(timestamps: [], datestamps: [])
@timestamps = store_attributes(timestamps)
Expand Down
1 change: 0 additions & 1 deletion core/lib/rom/relation/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def self.cache
attr_reader :dataset

attr_reader :aliaz

attr_reader :key

# @api private
Expand Down
8 changes: 4 additions & 4 deletions core/lib/rom/relation/view_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class ViewDSL
attr_reader :new_schema

# @api private
def initialize(name, schema, &block)
def initialize(name, schema, &)
@name = name
@schema = schema
@new_schema = nil
@relation_block = nil
instance_eval(&block)
instance_eval(&)
end

# Define a schema for a relation view
Expand All @@ -50,8 +50,8 @@ def schema(&block)
# @see Relation::ClassInterface.view
#
# @api public
def relation(&block)
@relation_block = proc(&block)
def relation(&)
@relation_block = proc(&)
end

# Return procs captured by the DSL
Expand Down
11 changes: 5 additions & 6 deletions core/lib/rom/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ def call(relation)
# @yield [Attribute]
#
# @api public
def each(&block)
attributes.each(&block)
def each(&)
attributes.each(&)
end

# Check if schema has any attributes
Expand Down Expand Up @@ -457,20 +457,19 @@ def set!(key, value)

# @api private
def count_index
map(&:name).map { |name| [name, count { |attr| attr.name == name }] }.to_h
map(&:name).to_h { |name| [name, count { |attr| attr.name == name }] }
end

# @api private
def name_index
map { |attr| [attr.name, attr] }.to_h
to_h { |attr| [attr.name, attr] }
end

# @api private
def source_index
select(&:source)
.group_by(&:source)
.map { |src, grp| [src.to_sym, grp.map { |attr| [attr.name, attr] }.to_h] }
.to_h
.to_h { |src, grp| [src.to_sym, grp.to_h { |attr| [attr.name, attr] }] }
end

# @api private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def call
# @api private
def name_error_message(attempted)
'required file does not define expected constant name; either ' \
'register your constant explicitly of try following the path' \
"naming convention like:\n\n\t- #{attempted.join("\n\t- ")}\n"
'register your constant explicitly of try following the path' \
"naming convention like:\n\n\t- #{attempted.join("\n\t- ")}\n"
end

# @api private
Expand Down
20 changes: 17 additions & 3 deletions core/lib/rom/setup/finalize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,23 @@ module ROM
#
# @private
class Finalize
attr_reader :gateways, :repo_adapter,
:relation_classes, :mapper_classes, :mapper_objects,
:command_classes, :plugins, :config, :notifications
attr_reader :gateways

attr_reader :repo_adapter

attr_reader :relation_classes

attr_reader :mapper_classes

attr_reader :mapper_objects

attr_reader :command_classes

attr_reader :plugins

attr_reader :config

attr_reader :notifications

# @api private
def initialize(options)
Expand Down
Loading

0 comments on commit 1a21eab

Please sign in to comment.