Skip to content

Commit 1b7b900

Browse files
committed
Address all offenses except two files
1 parent e693fe2 commit 1b7b900

32 files changed

+281
-99
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Lint/ConstantDefinitionInBlock:
4343

4444
Lint/EmptyBlock:
4545
Exclude:
46+
- "lib/rom/sql/migration/template.rb"
4647
- "spec/**/*.rb"
4748
- "tmp/**/*.rb"
4849

@@ -179,6 +180,9 @@ Style/OpenStructUse:
179180
Style/ParallelAssignment:
180181
Enabled: false
181182

183+
Style/SafeNavigation:
184+
MaxChainLength: 1
185+
182186
Style/StabbyLambdaParentheses:
183187
Enabled: false
184188

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'rspec/core/rake_task'
24

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

lib/rom/plugins/relation/sql/auto_restrictions.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ module AutoRestrictions
3939
end
4040

4141
# @api private
42+
#
43+
# rubocop:disable Metrics/AbcSize
4244
def self.restriction_methods(schema)
4345
mod = Module.new
4446

@@ -72,6 +74,7 @@ def self.restriction_methods(schema)
7274
[methods, mod]
7375
end
7476
end
77+
# rubocop:enable Metrics/AbcSize
7578
end
7679
end
7780
end

lib/rom/plugins/relation/sql/postgres/explain.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Explain
2626
#
2727
# @api public
2828
def explain(format: :text, **options)
29-
bool_options = options.map { |opt, value| "#{opt.to_s.upcase} #{!!value}" }
29+
bool_options = options.map { "#{_1.to_s.upcase} #{!!_2}" } # rubocop:disable Style/DoubleNegation
3030
format_option = "FORMAT #{format.to_s.upcase}"
3131
explain_value = [format_option, *bool_options].join(', ')
3232

lib/rom/plugins/relation/sql/postgres/full_text_search.rb

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,40 @@ module FullTextSearch
1313
# By default, searching for the inclusion of any of the terms in any of the cols.
1414
#
1515
# @example
16-
# posts.full_text_search([:title, :content], 'apples', language: 'english') # => Relation which match the 'apples' phrase
16+
# posts.full_text_search([:title, :content], 'apples', language: 'english')
17+
# # => Relation which match the 'apples' phrase
1718
#
18-
# @option :headline [String] Append a expression to the selected columns aliased to headline that contains an extract of the matched text.
19+
# @option :headline [String]
20+
# Append a expression to the selected columns aliased
21+
# to headline that contains an extract of the matched text.
1922
#
20-
# @option :language [String] The language to use for the search (default: 'simple')
23+
# @option :language [String]
24+
# The language to use for the search (default: 'simple')
2125
#
22-
# @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.
26+
# @option :plain [Boolean]
27+
# Whether a plain search should be used (default: false).
28+
# In this case, terms should be a single string, and it will do a search
29+
# where cols contains all of the words in terms.
30+
# This ignores search operators in terms.
2331
#
24-
# @option :phrase [Boolean] Similar to :plain, but also adding an ILIKE filter to ensure that returned rows also include the exact phrase used.
32+
# @option :phrase [Boolean]
33+
# Similar to :plain, but also adding an ILIKE filter to ensure
34+
# that returned rows also include the exact phrase used.
2535
#
26-
# @option :rank [Boolean] Set to true to order by the rank, so that closer matches are returned first.
36+
# @option :rank [Boolean]
37+
# Set to true to order by the rank, so that closer matches are returned first.
2738
#
28-
# @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.
39+
# @option :to_tsquery [Symbol]
40+
# Can be set to :plain or :phrase to specify the function to use
41+
# to convert the terms to a ts_query.
2942
#
30-
# @option :tsquery [Boolean] Specifies the terms argument is already a valid SQL expression returning a tsquery, and can be used directly in the query.
43+
# @option :tsquery [Boolean]
44+
# Specifies the terms argument is already a valid SQL expression returning a tsquery,
45+
# and can be used directly in the query.
3146
#
32-
# @option :tsvector [Boolean] Specifies the cols argument is already a valid SQL expression returning a tsvector, and can be used directly in the query.
47+
# @option :tsvector [Boolean]
48+
# Specifies the cols argument is already a valid SQL expression returning a tsvector,
49+
# and can be used directly in the query.
3350
#
3451
# @return [Relation]
3552
#

lib/rom/sql/associations/many_to_many.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class ManyToMany < ROM::Associations::ManyToMany
1212
include Associations::SelfRef
1313

1414
# @api public
15+
#
16+
# rubocop:disable Metrics/AbcSize
1517
def call(target: self.target)
1618
left = join_assoc.(target: target)
1719

@@ -34,6 +36,7 @@ def call(target: self.target)
3436
schema.(relation)
3537
end
3638
end
39+
# rubocop:enable Metrics/AbcSize
3740

3841
# @api public
3942
def join(type, source = self.source, target = self.target)

lib/rom/sql/associations/many_to_one.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class ManyToOne < ROM::Associations::ManyToOne
1212
include Associations::SelfRef
1313

1414
# @api public
15+
#
16+
# rubocop:disable Metrics/AbcSize
1517
def call(target: self.target, preload: false)
1618
if preload
1719
schema = target.schema.qualified
@@ -41,6 +43,7 @@ def call(target: self.target, preload: false)
4143
schema.(relation)
4244
end
4345
end
46+
# rubocop:enable Metrics/AbcSize
4447

4548
# @api public
4649
def join(type, source = self.source, target = self.target)

lib/rom/sql/attribute.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module SQL
1515
# Extended schema attributes tailored for SQL databases
1616
#
1717
# @api public
18+
#
19+
# rubocop:disable Metrics/ClassLength
1820
class Attribute < ROM::Attribute
1921
include AttributeWrapping
2022
include AttributeAliasing
@@ -59,7 +61,9 @@ def qualified(table_alias = nil)
5961
return meta(qualified: false) unless qualifiable?
6062

6163
case sql_expr
62-
when Sequel::SQL::AliasedExpression, Sequel::SQL::Identifier, Sequel::SQL::QualifiedIdentifier
64+
when ::Sequel::SQL::AliasedExpression,
65+
::Sequel::SQL::Identifier,
66+
::Sequel::SQL::QualifiedIdentifier
6367
attr = meta(qualified: table_alias || true)
6468
attr.meta(sql_expr: attr.to_sql_name)
6569
else
@@ -334,7 +338,7 @@ def meta_options_ast
334338
#
335339
# @api private
336340
def unwrap
337-
cleaned_meta = meta.reject { |k, _| META_KEYS.include?(k) }
341+
cleaned_meta = meta.except(*META_KEYS)
338342
type = optional? ? right : self.type
339343

340344
self.class.new(type.with(meta: cleaned_meta), **options)
@@ -383,6 +387,15 @@ def sql_expr
383387
@sql_expr ||= meta[:sql_expr] || to_sql_name
384388
end
385389

390+
# @api private
391+
def respond_to_missing?(meth, _include_private = false)
392+
if OPERATORS.include?(meth) || extensions.key?(meth) || sql_expr.respond_to?(meth)
393+
true
394+
else
395+
super
396+
end
397+
end
398+
386399
# Delegate to sql expression if it responds to a given method
387400
#
388401
# @api private
@@ -436,5 +449,6 @@ def extensions
436449

437450
memoize :joined, :to_sql_name, :table_name, :canonical
438451
end
452+
# rubocop:enable Metrics/ClassLength
439453
end
440454
end

lib/rom/sql/dsl.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def `(value)
5959
#
6060
# @example
6161
# users.where { exists(users.where(name: 'John')) }
62-
# users.select_append { |r| exists(r[:posts].where(r[:posts][:user_id] => id)).as(:has_posts) }
62+
# users.select_append { |r|
63+
# exists(r[:posts].where(r[:posts][:user_id] => id)).as(:has_posts)
64+
# }
6365
#
6466
# @api public
6567
def exists(relation)

lib/rom/sql/extensions/postgres/types/json.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,15 @@ def inspect
7777
end
7878
else
7979
JSON = Type('json') do
80-
(SQL::Types::Array | SQL::Types::Hash).constructor(Sequel.method(:pg_json)).meta(read: JSONRead)
80+
(SQL::Types::Array | SQL::Types::Hash).constructor(
81+
::Sequel.method(:pg_json)
82+
).meta(read: JSONRead)
8183
end
8284

8385
JSONB = Type('jsonb') do
84-
(SQL::Types::Array | SQL::Types::Hash).constructor(Sequel.method(:pg_jsonb)).meta(read: JSONRead)
86+
(SQL::Types::Array | SQL::Types::Hash).constructor(
87+
::Sequel.method(:pg_jsonb)
88+
).meta(read: JSONRead)
8589
end
8690
end
8791

@@ -265,7 +269,9 @@ def contained_by(_type, expr, value)
265269
end
266270

267271
def has_key(_type, expr, key)
268-
Attribute[SQL::Types::Bool].meta(sql_expr: wrap(expr).has_key?(key))
272+
Attribute[SQL::Types::Bool].meta(
273+
sql_expr: wrap(expr).has_key?(key) # rubocop:disable Style/PreferredHashMethods
274+
)
269275
end
270276

271277
def has_any_key(_type, expr, *keys)

0 commit comments

Comments
 (0)