Skip to content

Commit b63a0e1

Browse files
authored
Merge pull request #189 from kbrock/rubocops
fix rubocops
2 parents 5bce810 + 18ce271 commit b63a0e1

File tree

8 files changed

+24
-24
lines changed

8 files changed

+24
-24
lines changed

lib/active_record/virtual_attributes/virtual_arel.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,3 @@ def define_virtual_arel(name, arel) # :nodoc:
117117
end
118118
end
119119
end
120-

lib/active_record/virtual_attributes/virtual_delegates.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def define_virtual_delegate(method_name, col, options)
8383
end
8484

8585
# see activesupport module/delegation.rb
86+
# rubocop:disable Style/TernaryParentheses
8687
def define_delegate(method_name, method, to: nil, allow_nil: nil, default: nil) # rubocop:disable Naming/MethodParameterName
8788
location = caller_locations(2, 1).first
8889
file, line = location.path, location.lineno
@@ -128,6 +129,7 @@ def #{method_name}(#{definition})
128129
method_def = method_def.split("\n").map(&:strip).join(';')
129130
module_eval(method_def, file, line)
130131
end
132+
# rubocop:enable Style/TernaryParentheses
131133

132134
def virtual_delegate_name_prefix(prefix, to) # rubocop:disable Naming/MethodParameterName
133135
"#{prefix == true ? to : prefix}_" if prefix

lib/active_record/virtual_attributes/virtual_fields.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class Base
143143

144144
module Associations
145145
class Preloader
146-
prepend(Module.new {
146+
prepend(Module.new do
147147
# preloader is called with virtual attributes - need to resolve
148148
def call
149149
# Possibly overkill since all records probably have the same class and associations
@@ -165,13 +165,14 @@ def call
165165
end
166166
end
167167
end
168-
})
168+
end)
169169

170170
class Branch
171-
prepend(Module.new {
171+
prepend(Module.new do
172172
# from branched.rb 7.0
173173
# not going to modify rails code for rubocops
174174
# rubocop:disable Lint/AmbiguousOperatorPrecedence
175+
# rubocop:disable Layout/EmptyLineAfterGuardClause
175176
def grouped_records
176177
h = {}
177178
polymorphic_parent = !root? && parent.polymorphic?
@@ -186,6 +187,7 @@ def grouped_records
186187
end
187188
h
188189
end
190+
# rubocop:enable Layout/EmptyLineAfterGuardClause
189191
# rubocop:enable Lint/AmbiguousOperatorPrecedence
190192

191193
# branched.rb 7.0
@@ -209,13 +211,13 @@ def preloaders_for_reflection(reflection, reflection_records)
209211
preloader_for(reflection).new(rhs_klass, rs, reflection, scope, reflection_scope, associate_by_default)
210212
end
211213
end
212-
})
214+
end)
213215
end
214216
end
215217
end
216218

217219
class Relation
218-
include(Module.new {
220+
include(Module.new do
219221
# From ActiveRecord::QueryMethods (rails 5.2 - 6.1)
220222
def build_select(arel)
221223
if select_values.any?
@@ -246,6 +248,6 @@ def construct_join_dependency(associations, join_type) # :nodoc:
246248
associations = klass.replace_virtual_fields(associations) || {}
247249
super
248250
end
249-
})
251+
end)
250252
end
251253
end

lib/active_record/virtual_attributes/virtual_reflections.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module VirtualReflections
55
include ActiveRecord::VirtualAttributes::VirtualIncludes
66

77
module ClassMethods
8-
98
#
109
# Definition
1110
#

spec/db/models.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
class VirtualTotalTestBase < ActiveRecord::Base
1+
class VirtualTotalTestBase < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord
22
self.abstract_class = true
33

44
include VirtualFields
55
end
66

77
class Author < VirtualTotalTestBase
88
# basically a :parent_id relationship
9-
belongs_to :teacher, :foreign_key => :teacher_id, :class_name => "Author"
9+
belongs_to :teacher, :class_name => "Author"
1010
has_many :students, :foreign_key => :teacher_id, :class_name => "Author"
1111
has_many :books
1212
has_many :ordered_books, -> { ordered }, :class_name => "Book"

spec/support/database.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ class Database
66
VALID_ADAPTERS = %w[sqlite3 postgresql mysql2].freeze
77

88
def self.adapter
9-
# Handle missing and short-form DB values
10-
case ENV['DB']
11-
when nil, "sqlite" then ENV['DB'] = "sqlite3"
12-
when "pg" then ENV['DB'] = "postgresql"
13-
when "mysql" then ENV['DB'] = "mysql2"
9+
case ENV.fetch('DB', "sqlite")
10+
when "sqlite", "sqlite3" then ENV['DB'] = "sqlite3"
11+
when "pg", "postgresql" then ENV['DB'] = "postgresql"
12+
when "mysql", "mysql2" then ENV['DB'] = "mysql2"
13+
else
14+
raise "ENV['DB'] value invalid, must be one of: #{VALID_ADAPTERS.join(", ")}"
1415
end
15-
raise "ENV['DB'] value invalid, must be one of: #{VALID_ADAPTERS.join(", ")}" unless VALID_ADAPTERS.include?(ENV['DB'])
16-
17-
ENV['DB']
1816
end
1917

2018
attr_accessor :dirname

spec/virtual_attributes_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,9 @@ def lc
871871
end
872872

873873
it "distinct orders by has_one with an order clause" do
874-
Author.all.order(:id).each_with_index do |author, i|
874+
Author.order(:id).each_with_index do |author, i|
875875
author.photos.create(:description => "photo#{i}") # ignored photo
876-
author.photos.create(:description => "photo#{5-i}") # reverse order
876+
author.photos.create(:description => "photo#{5 - i}") # reverse order
877877
end
878878

879879
expect(Author.select(Arel.star, :current_photo_description).distinct.order(:current_photo_description)).to eq(authors.reverse)

spec/virtual_delegates_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
Author.create(:name => "c2", :teacher_id => p.id)
3535

3636
ret = Author.select(:name, :teacher_teacher_name, :teacher_name).order(:id).where(:teacher_id => p.id)
37-
expect(ret.map { |c| [c.teacher_teacher_name, c.teacher_name, c.name]}).to eq([["grand", "parent", "c1"],["grand", "parent", "c2"]])
37+
expect(ret.map { |c| [c.teacher_teacher_name, c.teacher_name, c.name] }).to eq([["grand", "parent", "c1"], ["grand", "parent", "c2"]])
3838
end
3939

4040
context "invalid" do
@@ -45,7 +45,7 @@
4545
end
4646

4747
it "expects a ':type' for delegation" do
48-
expect(ActiveRecord::VirtualAttributes.deprecator).to receive(:warn).with(/type/, anything())
48+
expect(ActiveRecord::VirtualAttributes.deprecator).to receive(:warn).with(/type/, anything)
4949
TestClass.virtual_delegate :col1, :to => :ref1
5050
TestClass.new
5151
end
@@ -146,7 +146,7 @@
146146
context "with has_one and order (and many records)" do
147147
before do
148148
# OperatingSystem (child)
149-
class TestOtherClass < ActiveRecord::Base
149+
class TestOtherClass < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord
150150
def self.connection
151151
TestClassBase.connection
152152
end
@@ -176,7 +176,7 @@ def self.connection
176176

177177
context "with relation in foreign table" do
178178
before do
179-
class TestOtherClass < ActiveRecord::Base
179+
class TestOtherClass < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord
180180
def self.connection
181181
TestClassBase.connection
182182
end

0 commit comments

Comments
 (0)