Skip to content

Commit

Permalink
[rubocop] address offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Mar 28, 2022
1 parent 60a0244 commit 03b97dc
Show file tree
Hide file tree
Showing 164 changed files with 1,370 additions and 1,062 deletions.
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 @@ -48,7 +48,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
4 changes: 2 additions & 2 deletions lib/rom/plugins/relation/sql/default_views.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def self.define_default_views!(target, schema)
target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
undef :by_pk if method_defined?(:by_pk)
def by_pk(#{schema.primary_key.map(&:name).join(', ')})
where(#{schema.primary_key.map { |attr| "schema.canonical[:#{attr.name}] => #{attr.name}" }.join(', ')})
def by_pk(#{schema.primary_key.map(&:name).join(", ")})
where(#{schema.primary_key.map { |attr| "schema.canonical[:#{attr.name}] => #{attr.name}" }.join(", ")})
end
RUBY
else
Expand Down
2 changes: 1 addition & 1 deletion lib/rom/plugins/relation/sql/postgres/explain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def explain(format: :text, **options)

query = "EXPLAIN (#{explain_value}) #{dataset.sql}"

rows = dataset.with_sql(query).map(:'QUERY PLAN')
rows = dataset.with_sql(query).map(:"QUERY PLAN")

case format
when :json
Expand Down
32 changes: 17 additions & 15 deletions lib/rom/plugins/relation/sql/postgres/full_text_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ module FullTextSearch
# By default, searching for the inclusion of any of the terms in any of the cols.
#
# @example
# posts.full_text_search([:title, :content], 'apples', language: 'english') # => Relation which match the 'apples' phrase
#
# @option :headline [String] Append a expression to the selected columns aliased to headline that contains an extract of the matched text.
# # => Relation which match the 'apples' phrase
# posts.full_text_search([:title, :content], 'apples', language: 'english')
#
# @option :headline [String] Append a expression to the selected columns aliased to headline that contains
# an extract of the matched text.
# @option :language [String] The language to use for the search (default: 'simple')
#
# @option :plain [Boolean] Whether a plain search should be used (default: false). In this case, terms should be a single string, and it will do a search where cols contains all of the words in terms. This ignores search operators in terms.
#
# @option :phrase [Boolean] Similar to :plain, but also adding an ILIKE filter to ensure that returned rows also include the exact phrase used.
#
# @option :plain [Boolean] Whether a plain search should be used (default: false). In this case, terms
# should be a single string, and it will do a search where cols contains all of the words in terms.
# This ignores search operators in terms.
# @option :phrase [Boolean] Similar to :plain, but also adding an ILIKE filter to ensure that returned rows
# also include the exact phrase used.
# @option :rank [Boolean] Set to true to order by the rank, so that closer matches are returned first.
#
# @option :to_tsquery [Symbol] Can be set to :plain or :phrase to specify the function to use to convert the terms to a ts_query.
#
# @option :tsquery [Boolean] Specifies the terms argument is already a valid SQL expression returning a tsquery, and can be used directly in the query.
#
# @option :tsvector [Boolean] Specifies the cols argument is already a valid SQL expression returning a tsvector, and can be used directly in the query.
# @option :to_tsquery [Symbol] Can be set to :plain or :phrase to specify the function to use to convert
# the terms to a ts_query.
# @option :tsquery [Boolean] Specifies the terms argument is already a valid SQL expression returning
# a tsquery, and can be used directly in the query.
# @option :tsvector [Boolean] Specifies the cols argument is already a valid SQL expression returning
# a tsvector, and can be used directly in the query.
#
# @return [Relation]
#
Expand All @@ -48,6 +49,7 @@ 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
2 changes: 1 addition & 1 deletion lib/rom/plugins/relation/sql/postgres/streaming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Streaming

class StreamingNotSupportedError < StandardError; end

def self.apply(target, **opts)
def self.apply(target, **_opts)
conn = registry.gateways[target.config.component.gateway].connection

return unless conn.database_type.to_sym == :postgres
Expand Down
8 changes: 4 additions & 4 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 Expand Up @@ -50,7 +50,7 @@ def join(type, source = self.source, target = self.target)

# @api public
def join_keys
{ source_attr => target_attr }
{source_attr => target_attr}
end

# @api public
Expand Down
2 changes: 1 addition & 1 deletion lib/rom/sql/associations/self_ref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.included(klass)

# @api public
def join_keys
{ source_attr => target_attr }
{source_attr => target_attr}
end

# @api public
Expand Down
5 changes: 2 additions & 3 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,7 +45,7 @@ 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
Expand Down
5 changes: 3 additions & 2 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)
def with_input_tuples(tuples, &block)
input_tuples = Array([tuples]).flatten(1).map
return input_tuples unless block_given?
input_tuples.each { |tuple| yield(tuple) }

input_tuples.each(&block)
end
end
end
Expand Down
5 changes: 3 additions & 2 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)
def with_input_tuples(tuples, &block)
input_tuples = Array([tuples]).flatten(1).map
return input_tuples unless block_given?
input_tuples.each { |tuple| yield(tuple) }

input_tuples.each(&block)
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
10 changes: 5 additions & 5 deletions lib/rom/sql/extensions/postgres/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,23 @@ class Upsert < SQL::Commands::Create

# @!attribute [r] constraint
# @return [Symbol] the name of the constraint expected to be violated
option :constraint, default: -> { self.config.constraint }
option :constraint, default: -> { config.constraint }

# @!attribute [r] conflict_target
# @return [Object] the column or expression to handle a violation on
option :conflict_target, default: -> { self.config.conflict_target }
option :conflict_target, default: -> { config.conflict_target }

# @!attribute [r] conflict_where
# @return [Object] the index filter, when using a partial index to determine uniqueness
option :conflict_where, default: -> { self.config.conflict_where }
option :conflict_where, default: -> { config.conflict_where }

# @!attribute [r] update_statement
# @return [Object] the update statement which will be executed in case of a violation
option :update_statement, default: -> { self.config.update_statement }
option :update_statement, default: -> { config.update_statement }

# @!attribute [r] update_where
# @return [Object] the WHERE clause to be added to the update
option :update_where, default: -> { self.config.update_where }
option :update_where, default: -> { config.update_where }

# Tries to insert provided tuples and do an update (or nothing)
# when the inserted record violates a unique constraint and hence
Expand Down
13 changes: 5 additions & 8 deletions lib/rom/sql/extensions/postgres/type_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ 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
].to_set.freeze
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 +36,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
2 changes: 1 addition & 1 deletion lib/rom/sql/extensions/postgres/type_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TypeSerializer < ROM::SQL::TypeSerializer
def call(type)
super do
if type.respond_to?(:primitive) && type.primitive.equal?(Array)
"#{ type.meta[:type] }[]"
"#{type.meta[:type]}[]"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rom/sql/extensions/postgres/types/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get(type, expr, idx)
end

def any(_type, expr, value)
Attribute[SQL::Types::Bool].meta(sql_expr: { value => expr.pg_array.any })
Attribute[SQL::Types::Bool].meta(sql_expr: {value => expr.pg_array.any})
end

def contained_by(type, expr, other)
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 03b97dc

Please sign in to comment.