Skip to content

Commit

Permalink
rubocop -a
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 3, 2025
1 parent cd28e66 commit e693fe2
Show file tree
Hide file tree
Showing 57 changed files with 545 additions and 386 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ Naming/MethodName:
Naming/MethodParameterName:
Enabled: false

Style/MultilineBlockChain:
Exclude:
- "spec/**/*.rb"

Style/MutableConstant:
Exclude:
- "spec/**/*.rb"
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "rspec/core/rake_task"
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

Expand Down
2 changes: 1 addition & 1 deletion lib/rom/plugins/relation/sql/auto_restrictions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def self.restriction_methods(schema)
next if index.partial?

attributes = index.to_a
meth_name = :"by_#{ attributes.map(&:name).join('_and_') }"
meth_name = :"by_#{attributes.map(&:name).join("_and_")}"

next if generated.include?(meth_name)

Expand Down
8 changes: 6 additions & 2 deletions lib/rom/plugins/relation/sql/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ module Instrumentation
subscribe('configuration.relations.registry.created') do |event|
registry = event[:registry]

relations = registry.select { |_, r| r.adapter == :sql && r.respond_to?(:notifications) }.to_h
db_notifications = relations.values.map { |r| [r.dataset.db, r.notifications] }.uniq.to_h
relations = registry.select { |_, r|
r.adapter == :sql && r.respond_to?(:notifications)
}.to_h
db_notifications = relations.values.map { |r|
[r.dataset.db, r.notifications]
}.uniq.to_h

db_notifications.each do |db, notifications|
next if db.respond_to?(:rom_instrumentation?)
Expand Down
8 changes: 5 additions & 3 deletions lib/rom/plugins/relation/sql/postgres/full_text_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ module FullTextSearch
# @see https://www.postgresql.org/docs/current/textsearch.html PostgreSQL docs
#
# @api public
def full_text_search(*args, &block)
new dataset.__send__(__method__, *args, &block)
def full_text_search(...)
new dataset.__send__(__method__, ...)
end
end
end
Expand All @@ -48,6 +48,8 @@ def full_text_search(*args, &block)

ROM.plugins do
adapter :sql do
register :pg_full_text_search, ROM::Plugins::Relation::SQL::Postgres::FullTextSearch, type: :relation
register :pg_full_text_search,
ROM::Plugins::Relation::SQL::Postgres::FullTextSearch,
type: :relation
end
end
12 changes: 6 additions & 6 deletions lib/rom/plugins/relation/sql/postgres/streaming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ module Streaming

class StreamingNotSupportedError < StandardError; end

subscribe("configuration.gateway.connected") do |opts|
subscribe('configuration.gateway.connected') do |opts|
conn = opts[:connection]

next unless conn.database_type.to_sym == :postgres

next if defined?(JRUBY_VERSION)

begin
require "sequel_pg"
require 'sequel_pg'
rescue LoadError
raise StreamingNotSupportedError, "add sequel_pg to Gemfile to use pg_streaming"
raise StreamingNotSupportedError, 'add sequel_pg to Gemfile to use pg_streaming'
end

unless Sequel::Postgres.supports_streaming?
raise StreamingNotSupportedError, "postgres version does not support streaming"
raise StreamingNotSupportedError, 'postgres version does not support streaming'
end

conn.extension(:pg_streaming)
Expand All @@ -52,7 +52,7 @@ def self.included(klass)
#
# @api publicY_VERSION
def stream_each
raise StreamingNotSupportedError, "not supported on jruby"
raise StreamingNotSupportedError, 'not supported on jruby'
end
else
# Allows you to stream returned rows one at a time, instead of
Expand Down Expand Up @@ -80,7 +80,7 @@ def stream_each

module Combined
def stream_each
raise StreamingNotSupportedError, "not supported on combined relations"
raise StreamingNotSupportedError, 'not supported on combined relations'
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/rom/sql/associations/many_to_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def call(target: self.target)

schema =
if left.schema.key?(foreign_key)
if target != self.target
target.schema.merge(join_schema)
else
if target == self.target
left.schema.uniq.project(*columns)
else
target.schema.merge(join_schema)
end
else
target_schema
Expand Down
12 changes: 6 additions & 6 deletions lib/rom/sql/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ def in(*args)
# @return [SQL::Function]
#
# @api public
def func(&block)
ProjectionDSL.new(name => self).call(&block).first
def func(&)
ProjectionDSL.new(name => self).call(&).first
end

# Create a CONCAT function from the attribute
Expand Down Expand Up @@ -380,19 +380,19 @@ def case(mapping)
#
# @api private
def sql_expr
@sql_expr ||= (meta[:sql_expr] || to_sql_name)
@sql_expr ||= meta[:sql_expr] || to_sql_name
end

# Delegate to sql expression if it responds to a given method
#
# @api private
def method_missing(meth, *args, &block)
def method_missing(meth, *args, &)
if OPERATORS.include?(meth)
__cmp__(meth, args[0])
elsif extensions.key?(meth)
extensions[meth].(type, sql_expr, *args, &block)
extensions[meth].(type, sql_expr, *args, &)
elsif sql_expr.respond_to?(meth)
meta(sql_expr: sql_expr.__send__(meth, *args, &block))
meta(sql_expr: sql_expr.__send__(meth, *args, &))
else
super
end
Expand Down
13 changes: 7 additions & 6 deletions lib/rom/sql/attribute_aliasing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def aliased(alias_name)
sql_expr: alias_sql_expr(sql_expr, new_alias_name)
)
end
alias as aliased

alias_method :as, :aliased

# Return true if this attribute is an aliased projection
#
Expand All @@ -46,16 +45,18 @@ def aliased(alias_name)
#
# @api private
def aliased_projection?
self.meta[:sql_expr].is_a?(Sequel::SQL::AliasedExpression)
meta[:sql_expr].is_a?(::Sequel::SQL::AliasedExpression)
end

private

# @api private
def alias_sql_expr(sql_expr, new_alias)
case sql_expr
when Sequel::SQL::AliasedExpression
Sequel::SQL::AliasedExpression.new(sql_expr.expression, new_alias, sql_expr.columns)
when ::Sequel::SQL::AliasedExpression
::Sequel::SQL::AliasedExpression.new(
sql_expr.expression, new_alias, sql_expr.columns
)
else
sql_expr.as(new_alias)
end
Expand All @@ -70,7 +71,7 @@ def extract_alias_names(alias_name)
# attribute in a way that will map the the requested alias name.
# Without this, the attribute will silently ignore the requested alias
# name and default to the pre-existing name.
new_name = "#{meta[:wrapped]}_#{options[:alias]}".to_sym
new_name = :"#{meta[:wrapped]}_#{options[:alias]}"

# Essentially, this makes it so "wrapped" attributes aren't true
# aliases, in that we actually alias the wrapped attribute, we use
Expand Down
7 changes: 4 additions & 3 deletions lib/rom/sql/commands/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ def multi_insert(tuples)
# Yields tuples for insertion or return an enumerator
#
# @api private
def with_input_tuples(tuples)
input_tuples = Array([tuples]).flatten(1).map
def with_input_tuples(tuples, &)
input_tuples = [tuples].flatten(1).map
return input_tuples unless block_given?
input_tuples.each { |tuple| yield(tuple) }

input_tuples.each(&)
end
end
end
Expand Down
7 changes: 4 additions & 3 deletions lib/rom/sql/commands/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ def primary_key
# Yields tuples for insertion or return an enumerator
#
# @api private
def with_input_tuples(tuples)
input_tuples = Array([tuples]).flatten(1).map
def with_input_tuples(tuples, &)
input_tuples = [tuples].flatten(1).map
return input_tuples unless block_given?
input_tuples.each { |tuple| yield(tuple) }

input_tuples.each(&)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rom/sql/extensions/active_support_notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def instrumentation_name
end
end

Sequel::Database.send(:prepend, ROM::SQL::ActiveSupportInstrumentation)
Sequel::Database.prepend ROM::SQL::ActiveSupportInstrumentation
14 changes: 7 additions & 7 deletions lib/rom/sql/extensions/postgres/type_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ module Postgres
class TypeBuilder < Schema::TypeBuilder
defines :db_numeric_types, :db_type_mapping, :db_array_type_matcher

db_numeric_types %w[
smallint integer bigint
decimal numeric real
double\ precision serial bigserial
db_numeric_types [
'smallint', 'integer', 'bigint',
'decimal', 'numeric', 'real',
'double precision', 'serial', 'bigserial'
].to_set.freeze

db_type_mapping(
'uuid' => Types::UUID,
'uuid' => Types::UUID,
'money' => Types::Money,
'bytea' => Types::Bytea,
'json' => Types::JSON,
'json' => Types::JSON,
'jsonb' => Types::JSONB,
'xml' => Types::XML,
'inet' => Types::IPAddress,
Expand All @@ -39,7 +39,7 @@ class TypeBuilder < Schema::TypeBuilder
'ltree' => Types::LTree
).freeze

db_array_type_matcher '[]'.freeze
db_array_type_matcher '[]'

def map_pk_type(type, db_type, **options)
if numeric?(type, db_type)
Expand Down
4 changes: 2 additions & 2 deletions lib/rom/sql/extensions/postgres/type_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class TypeSerializer < ROM::SQL::TypeSerializer

def call(type)
super do
if type.respond_to?(:primitive) && type.primitive.equal?(Array)
"#{ type.meta[:type] }[]"
if type.respond_to?(:primitive) && type.primitive.equal?(::Array)
"#{type.meta[:type]}[]"
end
end
end
Expand Down
24 changes: 12 additions & 12 deletions lib/rom/sql/extensions/postgres/types/geometric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Types
Point = Type('point') do
SQL::Types.define(Values::Point) do
input do |point|
"(#{ point.x },#{ point.y })"
"(#{point.x},#{point.y})"
end

output do |point|
Expand All @@ -50,7 +50,7 @@ module Types
Line = Type('line') do
SQL::Types.define(Values::Line) do
input do |line|
"{#{ line.a },#{ line.b },#{line.c}}"
"{#{line.a},#{line.b},#{line.c}}"
end

output do |line|
Expand All @@ -63,7 +63,7 @@ module Types
Circle = Type('circle') do
SQL::Types.define(Values::Circle) do
input do |circle|
"<(#{ circle.center.x },#{ circle.center.y }),#{ circle.radius }>"
"<(#{circle.center.x},#{circle.center.y}),#{circle.radius}>"
end

output do |circle|
Expand All @@ -77,8 +77,8 @@ module Types
Box = Type('box') do
SQL::Types.define(Values::Box) do
input do |box|
"((#{ box.upper_right.x },#{ box.upper_right.y }),"\
"(#{ box.lower_left.x },#{ box.lower_left.y }))"
"((#{box.upper_right.x},#{box.upper_right.y})," \
"(#{box.lower_left.x},#{box.lower_left.y}))"
end

output do |box|
Expand All @@ -93,8 +93,8 @@ module Types
LineSegment = Type('lseg') do
SQL::Types.define(Values::LineSegment) do
input do |segment|
"[(#{ segment.begin.x },#{ segment.begin.y }),"\
"(#{ segment.end.x },#{ segment.end.y })]"
"[(#{segment.begin.x},#{segment.begin.y})," \
"(#{segment.end.x},#{segment.end.y})]"
end

output do |segment|
Expand All @@ -109,8 +109,8 @@ module Types
Polygon = Type('polygon') do
SQL::Types.define(::Array) do
input do |points|
points_joined = points.map { |p| "(#{ p.x },#{ p.y })" }.join(',')
"(#{ points_joined })"
points_joined = points.map { |p| "(#{p.x},#{p.y})" }.join(',')
"(#{points_joined})"
end

output do |polygon|
Expand All @@ -123,12 +123,12 @@ module Types
Path = Type('path') do
SQL::Types.define(Values::Path) do
input do |path|
points_joined = path.to_a.map { |p| "(#{ p.x },#{ p.y })" }.join(',')
points_joined = path.to_a.map { |p| "(#{p.x},#{p.y})" }.join(',')

if path.open?
"[#{ points_joined }]"
"[#{points_joined}]"
else
"(#{ points_joined })"
"(#{points_joined})"
end
end

Expand Down
Loading

0 comments on commit e693fe2

Please sign in to comment.