Skip to content

Commit

Permalink
Satisfy Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Jul 6, 2024
1 parent d7506e7 commit 9540e55
Show file tree
Hide file tree
Showing 22 changed files with 31 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ Style/RaiseArgs:
Style/RedundantArgument:
Enabled: true

Style/RedundantParentheses:
Enabled: false

Style/RedundantSelfAssignmentBranch:
Enabled: true

Expand Down
5 changes: 3 additions & 2 deletions lib/rails_admin/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def query_scope(scope, query, fields = config.list.fields.select(&:queryable?))
# "0055" is the filter index, no use here. o is the operator, v the value
def filter_scope(scope, filters, fields = config.list.fields.select(&:filterable?))
filters.each_pair do |field_name, filters_dump|
filters_dump.each do |_, filter_dump|
filters_dump.each_value do |filter_dump|
wb = WhereBuilder.new(scope)
field = fields.detect { |f| f.name.to_s == field_name }
value = parse_field_value(field, filter_dump[:v])
Expand Down Expand Up @@ -256,7 +256,8 @@ def build_statement_for_type

def build_statement_for_boolean
return ["(#{@column} IS NULL OR #{@column} = ?)", false] if %w[false f 0].include?(@value)
return ["(#{@column} = ?)", true] if %w[true t 1].include?(@value)

["(#{@column} = ?)", true] if %w[true t 1].include?(@value)
end

def column_for_value(value)
Expand Down
4 changes: 2 additions & 2 deletions lib/rails_admin/adapters/active_record/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def foreign_inverse_of
def key_accessor
case type
when :has_many, :has_and_belongs_to_many
"#{name.to_s.singularize}_ids".to_sym
:"#{name.to_s.singularize}_ids"
when :has_one
"#{name}_id".to_sym
:"#{name}_id"
else
foreign_key
end
Expand Down
5 changes: 3 additions & 2 deletions lib/rails_admin/adapters/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def filter_scope(scope, filters, fields = config.list.fields.select(&:filterable
statements = []

filters.each_pair do |field_name, filters_dump|
filters_dump.each do |_, filter_dump|
filters_dump.each_value do |filter_dump|
field = fields.detect { |f| f.name.to_s == field_name }
next unless field

Expand Down Expand Up @@ -251,7 +251,8 @@ def build_statement_for_type

def build_statement_for_boolean
return {@column => false} if %w[false f 0].include?(@value)
return {@column => true} if %w[true t 1].include?(@value)

{@column => true} if %w[true t 1].include?(@value)
end

def column_for_value(value)
Expand Down
4 changes: 2 additions & 2 deletions lib/rails_admin/adapters/mongoid/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def foreign_inverse_of
def key_accessor
case macro.to_sym
when :has_many
"#{name.to_s.singularize}_ids".to_sym
:"#{name.to_s.singularize}_ids"
when :has_one
"#{name}_id".to_sym
:"#{name}_id"
when :embedded_in, :embeds_one, :embeds_many
nil
else
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/fields/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def generic_help

def generic_field_help
model = abstract_model.model_name.underscore
model_lookup = "admin.help.#{model}.#{name}".to_sym
model_lookup = :"admin.help.#{model}.#{name}"
translated = I18n.translate(model_lookup, help: generic_help, default: [generic_help])
(translated.is_a?(Hash) ? translated.to_a.first[1] : translated).html_safe
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rails_admin/config/fields/factories/active_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
fields << field
associations =
if properties.type == :has_many
["#{name}_attachments".to_sym, "#{name}_blobs".to_sym]
[:"#{name}_attachments", :"#{name}_blobs"]
else
["#{name}_attachment".to_sym, "#{name}_blob".to_sym]
[:"#{name}_attachment", :"#{name}_blob"]
end
children_fields = associations.map do |child_name|
child_association = parent.abstract_model.associations.detect { |p| p.name.to_sym == child_name }
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/fields/factories/carrierwave.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
model = parent.abstract_model.model
if defined?(::CarrierWave) && model.is_a?(CarrierWave::Mount) && model.uploaders.include?(attachment_name = properties.name.to_s.chomp('_file_name').to_sym)
columns = [model.uploader_options[attachment_name][:mount_on] || attachment_name, "#{attachment_name}_content_type".to_sym, "#{attachment_name}_file_size".to_sym]
columns = [model.uploader_options[attachment_name][:mount_on] || attachment_name, :"#{attachment_name}_content_type", :"#{attachment_name}_file_size"]
field = RailsAdmin::Config::Fields::Types.load(
%i[serialized json].include?(properties.type) ? :multiple_carrierwave : :carrierwave,
).new(parent, attachment_name, properties)
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/fields/factories/dragonfly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
field = RailsAdmin::Config::Fields::Types.load(:dragonfly).new(parent, attachment_name, properties)
children_fields = []
extensions.each do |ext|
children_column_name = "#{attachment_name}_#{ext}".to_sym
children_column_name = :"#{attachment_name}_#{ext}"
child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
next unless child_properties

Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/fields/factories/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
field = RailsAdmin::Config::Fields::Types.load(:paperclip).new(parent, attachment_name, properties)
children_fields = []
extensions.each do |ext|
children_column_name = "#{attachment_name}_#{ext}".to_sym
children_column_name = :"#{attachment_name}_#{ext}"
child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
next unless child_properties

Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/fields/factories/shrine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
field = RailsAdmin::Config::Fields::Types.load(:shrine).new(parent, attachment_name, properties)
fields << field

data_field_name = "#{attachment_name}_data".to_sym
data_field_name = :"#{attachment_name}_data"
child_properties = parent.abstract_model.properties.detect { |p| p.name == data_field_name }
next true unless child_properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def selected_id
end

def method_name
nested_form ? "#{name}_attributes".to_sym : super
nested_form ? :"#{name}_attributes" : super
end

def multiple?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class HasManyAssociation < RailsAdmin::Config::Fields::Association
end

def method_name
nested_form ? "#{name}_attributes".to_sym : super
nested_form ? :"#{name}_attributes" : super
end

# Reader for validation errors of the bound object
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/fields/types/has_one_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def selected_id
end

def method_name
nested_form ? "#{name}_attributes".to_sym : super
nested_form ? :"#{name}_attributes" : super
end

def multiple?
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def listing_for_model_or_object(model, object, query, sort, sort_reverse, all, p
versions = object.nil? ? versions_for_model(model) : object.public_send(model.model.versions_association_name)
versions = versions.where('event LIKE ?', "%#{query}%") if query.present?
versions = versions.order(sort)
versions = all ? versions : versions.send(Kaminari.config.page_method_name, current_page).per(per_page)
versions = versions.send(Kaminari.config.page_method_name, current_page).per(per_page) unless all
paginated_proxies = Kaminari.paginate_array([], total_count: versions.try(:total_count) || versions.count)
paginated_proxies = paginated_proxies.send(
paginated_proxies.respond_to?(Kaminari.config.page_method_name) ? Kaminari.config.page_method_name : :page,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# ApplicationController.renderer.defaults.merge!(
Expand Down
1 change: 1 addition & 0 deletions spec/dummy_app/config/initializers/backtrace_silencers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
Expand Down
1 change: 1 addition & 0 deletions spec/dummy_app/config/initializers/cors.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Avoid CORS issues when API is called from the frontend app.
Expand Down
1 change: 1 addition & 0 deletions spec/dummy_app/config/initializers/inflections.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Add new inflection rules using the following format. Inflections
Expand Down
1 change: 1 addition & 0 deletions spec/dummy_app/config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Add new mime types for use in respond_to blocks:
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/fields/multiple_file_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def resource_url(_thumb = false)
delete_method 'boolean_field'
reorderable true
def value
bindings[:object].safe_send(name)&.split(' ')
bindings[:object].safe_send(name)&.split
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

CI_TARGET_ORMS.each do |orm|
if orm == CI_ORM
config.filter_run_excluding "skip_#{orm}".to_sym => true
config.filter_run_excluding "skip_#{orm}": true
else
config.filter_run_excluding orm => true
end
Expand Down

0 comments on commit 9540e55

Please sign in to comment.