Permalink
Browse files

Fix RuboCop offenses

  • Loading branch information...
1 parent a0c638a commit 61ad2ee2d9c5b63ffe3626e5a6051693bdadb9b4 @mshibuya mshibuya committed Jun 10, 2014
Showing with 142 additions and 163 deletions.
  1. +3 −3 .rubocop.yml
  2. +1 −1 Rakefile
  3. +9 −11 app/controllers/rails_admin/main_controller.rb
  4. +5 −6 app/helpers/rails_admin/application_helper.rb
  5. +8 −9 app/helpers/rails_admin/form_builder.rb
  6. +3 −4 lib/rails_admin/abstract_model.rb
  7. +2 −3 lib/rails_admin/adapters/active_record.rb
  8. +6 −7 lib/rails_admin/adapters/mongoid.rb
  9. +6 −9 lib/rails_admin/adapters/mongoid/association.rb
  10. +1 −1 lib/rails_admin/adapters/mongoid/extension.rb
  11. +1 −1 lib/rails_admin/bootstrap-sass/compass_functions.rb
  12. +2 −3 lib/rails_admin/config/actions/dashboard.rb
  13. +4 −4 lib/rails_admin/config/actions/index.rb
  14. +6 −8 lib/rails_admin/config/fields.rb
  15. +4 −5 lib/rails_admin/config/fields/base.rb
  16. +5 −6 lib/rails_admin/config/fields/factories/carrierwave.rb
  17. +5 −6 lib/rails_admin/config/fields/factories/devise.rb
  18. +5 −6 lib/rails_admin/config/fields/factories/dragonfly.rb
  19. +5 −5 lib/rails_admin/config/fields/factories/enum.rb
  20. +5 −6 lib/rails_admin/config/fields/factories/paperclip.rb
  21. +1 −1 lib/rails_admin/config/fields/types/enum.rb
  22. +2 −3 lib/rails_admin/config/fields/types/json.rb
  23. +2 −3 lib/rails_admin/config/fields/types/serialized.rb
  24. +3 −3 lib/rails_admin/config/fields/types/string.rb
  25. +3 −4 lib/rails_admin/config/has_fields.rb
  26. +1 −1 lib/rails_admin/config/model.rb
  27. +1 −1 lib/rails_admin/config/sections/base.rb
  28. +1 −1 lib/rails_admin/extensions/history/history.rb
  29. +3 −3 lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
  30. +2 −2 lib/rails_admin/support/core_extensions.rb
  31. +2 −2 lib/rails_admin/support/csv_converter.rb
  32. +1 −1 spec/controllers/rails_admin/application_controller_spec.rb
  33. +1 −1 spec/controllers/rails_admin/main_controller_spec.rb
  34. +1 −1 spec/dummy_app/app/active_record/player.rb
  35. +1 −1 spec/dummy_app/app/mongoid/player.rb
  36. +2 −2 spec/factories.rb
  37. +2 −2 spec/helpers/rails_admin/application_helper_spec.rb
  38. +1 −1 spec/helpers/rails_admin/form_builder_spec.rb
  39. +1 −1 spec/integration/authorization/cancan_spec.rb
  40. +2 −2 spec/integration/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb
  41. +1 −1 spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb
  42. +1 −1 spec/integration/basic/create/rails_admin_basic_create_spec.rb
  43. +1 −1 spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb
  44. +1 −1 spec/integration/basic/delete/rails_admin_basic_delete_spec.rb
  45. +1 −1 spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb
  46. +1 −1 spec/integration/basic/edit/rails_admin_basic_edit_spec.rb
  47. +1 −1 spec/integration/basic/export/rails_admin_basic_export_spec.rb
  48. +1 −1 spec/integration/basic/list/rails_admin_basic_list_spec.rb
  49. +1 −1 spec/integration/basic/new/rails_admin_basic_new_spec.rb
  50. +1 −1 spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb
  51. +1 −1 spec/integration/basic/show/rails_admin_basic_show_spec.rb
  52. +2 −2 spec/integration/basic/update/rails_admin_basic_update_spec.rb
  53. +1 −1 spec/integration/config/edit/rails_admin_config_edit_spec.rb
  54. +1 −1 spec/integration/config/list/rails_admin_config_list_spec.rb
  55. +2 −2 spec/integration/config/show/rails_admin_config_show_spec.rb
  56. +1 −1 spec/integration/rails_admin_spec.rb
  57. +1 −1 spec/integration/relation_spec.rb
  58. +1 −1 spec/orm/active_record.rb
  59. +1 −1 spec/orm/mongoid.rb
  60. +1 −1 spec/rails_admin/adapters/mongoid/property_spec.rb
  61. +1 −1 spec/rails_admin/config/fields/types/datetime_spec.rb
View
@@ -2,9 +2,9 @@ inherit_from: rubocop-todo.yml
AllCops:
Include:
- - 'Gemfile'
- - 'Rakefile'
- - 'rails_admin.gemspec'
+ - '/Gemfile'
+ - '/Rakefile'
+ - '/rails_admin.gemspec'
Exclude:
- 'spec/dummy_app/db/schema.rb'
View
@@ -13,7 +13,7 @@ task test: :spec
begin
require 'rubocop/rake_task'
- Rubocop::RakeTask.new
+ RuboCop::RakeTask.new
rescue LoadError
desc 'Run RuboCop'
task :rubocop do
@@ -86,21 +86,20 @@ def redirect_to_on_success
end
def satisfy_strong_params!
- if @abstract_model.model.ancestors.collect(&:to_s).include?('ActiveModel::ForbiddenAttributesProtection')
- params[@abstract_model.param_key].try :permit!
- end
+ return unless @abstract_model.model.ancestors.collect(&:to_s).include?('ActiveModel::ForbiddenAttributesProtection')
+ params[@abstract_model.param_key].try :permit!
end
- def sanitize_params_for!(action, model_config = @model_config, _params = params[@abstract_model.param_key])
- return unless _params.present?
+ def sanitize_params_for!(action, model_config = @model_config, target_params = params[@abstract_model.param_key])
+ return unless target_params.present?
fields = model_config.send(action).with(controller: self, view: view_context, object: @object).visible_fields
allowed_methods = fields.collect do|f|
f.allowed_methods
end.flatten.uniq.collect(&:to_s) << 'id' << '_destroy'
- fields.each { |f| f.parse_input(_params) }
- _params.slice!(*allowed_methods)
+ fields.each { |f| f.parse_input(target_params) }
+ target_params.slice!(*allowed_methods)
fields.select(&:nested_form).each do |association|
- children_params = association.multiple? ? _params[association.method_name].try(:values) : [_params[association.method_name]].compact
+ children_params = association.multiple? ? target_params[association.method_name].try(:values) : [target_params[association.method_name]].compact
(children_params || []).each do |children_param|
sanitize_params_for!(:nested, association.associated_model_config, children_param)
end
@@ -118,9 +117,8 @@ def handle_save_error(whereto = :new)
end
def check_for_cancel
- if params[:_continue] || (params[:bulk_action] && !params[:bulk_ids])
- redirect_to(back_or_index, flash: {info: t('admin.flash.noaction')})
- end
+ return unless params[:_continue] || (params[:bulk_action] && !params[:bulk_ids])
+ redirect_to(back_or_index, flash: {info: t('admin.flash.noaction')})
end
def get_collection(model_config, scope, pagination)
@@ -31,10 +31,9 @@ def edit_user_link
end
def logout_path
- if defined?(Devise)
- scope = Devise::Mapping.find_scope!(_current_user)
- main_app.send("destroy_#{scope}_session_path") rescue false
- end
+ return unless defined?(Devise)
+ scope = Devise::Mapping.find_scope!(_current_user)
+ main_app.send("destroy_#{scope}_session_path") rescue false
end
def wording_for(label, action = @action, abstract_model = @abstract_model, object = @object)
@@ -87,7 +86,7 @@ def navigation(nodes_stack, nodes, level = 0)
end.join.html_safe
end
- def breadcrumb(action = @action, acc = [])
+ def breadcrumb(action = @action, _acc = [])
begin
(parent_actions ||= []) << action
end while action.breadcrumb_parent && (action = action(*action.breadcrumb_parent)) # rubocop:disable Loop
@@ -120,7 +119,7 @@ def menu_for(parent, abstract_model = nil, object = nil, only_icon = false) # pe
<li title="#{wording if only_icon}" rel="#{'tooltip' if only_icon}" class="icon #{action.key}_#{parent}_link #{'active' if current_action?(action)}">
<a class="#{action.pjax? ? 'pjax' : ''}" href="#{url_for(action: action.action_name, controller: 'rails_admin/main', model_name: abstract_model.try(:to_param), id: (object.try(:persisted?) && object.try(:id) || nil))}">
<i class="#{action.link_icon}"></i>
- <span#{only_icon ? " style='display:none'" : ""}>#{wording}</span>
+ <span#{only_icon ? " style='display:none'" : ''}>#{wording}</span>
</a>
</li>
)
@@ -19,14 +19,13 @@ def generate(options = {})
end
def fieldset_for(fieldset, nested_in)
- if (fields = fieldset.with(form: self, object: @object, view: @template, controller: @template.controller).visible_fields).length > 0
- @template.content_tag :fieldset do
- contents = []
- contents << @template.content_tag(:legend, %(<i class="icon-chevron-#{(fieldset.active? ? 'down' : 'right')}"></i> #{fieldset.label}).html_safe, style: "#{fieldset.name == :default ? 'display:none' : ''}")
- contents << @template.content_tag(:p, fieldset.help) if fieldset.help.present?
- contents << fields.collect { |field| field_wrapper_for(field, nested_in) }.join
- contents.join.html_safe
- end
+ return unless (fields = fieldset.with(form: self, object: @object, view: @template, controller: @template.controller).visible_fields).length > 0
+ @template.content_tag :fieldset do
+ contents = []
+ contents << @template.content_tag(:legend, %(<i class="icon-chevron-#{(fieldset.active? ? 'down' : 'right')}"></i> #{fieldset.label}).html_safe, style: "#{fieldset.name == :default ? 'display:none' : ''}")
+ contents << @template.content_tag(:p, fieldset.help) if fieldset.help.present?
+ contents << fields.collect { |field| field_wrapper_for(field, nested_in) }.join
+ contents.join.html_safe
end
end
@@ -120,7 +119,7 @@ def visible_groups(model_config, action)
def without_field_error_proc_added_div
default_field_error_proc = ::ActionView::Base.field_error_proc
begin
- ::ActionView::Base.field_error_proc = proc { |html_tag, instance| html_tag }
+ ::ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
yield
ensure
::ActionView::Base.field_error_proc = default_field_error_proc
@@ -147,9 +147,8 @@ def build_statement_for_integer_decimal_or_float
case @value
when Array then
val, range_begin, range_end = *@value.collect do |v|
- if v.to_i.to_s == v || v.to_f.to_s == v
- @type == :integer ? v.to_i : v.to_f
- end
+ next unless v.to_i.to_s == v || v.to_f.to_s == v
+ @type == :integer ? v.to_i : v.to_f
end
case @operator
when 'between'
@@ -179,7 +178,7 @@ def unary_operators
fail('You must override unary_operators in your StatementBuilder')
end
- def range_filter(min, max)
+ def range_filter(_min, _max)
fail('You must override range_filter in your StatementBuilder')
end
@@ -13,9 +13,8 @@ def new(params = {})
end
def get(id)
- if object = model.where(primary_key => id).first
- AbstractObject.new object
- end
+ return unless object = model.where(primary_key => id).first
+ AbstractObject.new object
end
def scoped
@@ -11,7 +11,7 @@ module Mongoid
ObjectId = defined?(Moped::BSON) ? Moped::BSON::ObjectId : BSON::ObjectId # rubocop:disable ConstantName
def new(params = {})
- AbstractObject.new(model.new)
+ AbstractObject.new(model.new(params))
end
def get(id)
@@ -66,8 +66,8 @@ def associations
end
def properties
- fields = model.fields.reject { |name, field| DISABLED_COLUMN_TYPES.include?(field.type.to_s) }
- fields.collect do |name, field|
+ fields = model.fields.reject { |_name, field| DISABLED_COLUMN_TYPES.include?(field.type.to_s) }
+ fields.collect do |_name, field|
Property.new(field, model)
end
end
@@ -103,10 +103,9 @@ def make_field_conditions(field, value, operator)
field.searchable_columns.each do |column_infos|
collection_name, column_name = parse_collection_name(column_infos[:column])
statement = build_statement(column_name, column_infos[:type], value, operator)
- if statement
- conditions_per_collection[collection_name] ||= []
- conditions_per_collection[collection_name] << statement
- end
+ next unless statement
+ conditions_per_collection[collection_name] ||= []
+ conditions_per_collection[collection_name] << statement
end
conditions_per_collection
end
@@ -44,21 +44,18 @@ def primary_key
end
def foreign_key
- if [:embeds_one, :embeds_many].exclude?(macro.to_sym)
- association.foreign_key.to_sym rescue nil
- end
+ return unless [:embeds_one, :embeds_many].exclude?(macro.to_sym)
+ association.foreign_key.to_sym rescue nil
end
def foreign_type
- if polymorphic? && [:referenced_in, :belongs_to].include?(macro)
- association.inverse_type.try(:to_sym) || :"#{name}_type"
- end
+ return unless polymorphic? && [:referenced_in, :belongs_to].include?(macro)
+ association.inverse_type.try(:to_sym) || :"#{name}_type"
end
def foreign_inverse_of
- if polymorphic? && [:referenced_in, :belongs_to].include?(macro)
- inverse_of_field.try(:to_sym)
- end
+ return unless polymorphic? && [:referenced_in, :belongs_to].include?(macro)
+ inverse_of_field.try(:to_sym)
end
def as
@@ -20,7 +20,7 @@ def rails_admin_default_object_label_method
end
def safe_send(value)
- if attributes.detect { |k, v| k.to_s == value.to_s }
+ if attributes.detect { |k, _v| k.to_s == value.to_s }
read_attribute(value)
else
send(value)
@@ -1,7 +1,7 @@
module Sass
module Script
module Functions
- def image_path(source, options = {})
+ def image_path(source, _options = {})
if defined?(::Sprockets)
::Sass::Script::String.new sprockets_context.image_path(source.value).to_s, :string
elsif defined?(::Compass)
@@ -26,9 +26,8 @@ class Dashboard < RailsAdmin::Config::Actions::Base
current_count = t.count({}, scope)
@max = current_count > @max ? current_count : @max
@count[t.pretty_name] = current_count
- if t.properties.detect { |c| c.name == :updated_at }
- @most_recent_changes[t.pretty_name] = t.first(sort: "#{t.table_name}.updated_at").try(:updated_at)
- end
+ next unless t.properties.detect { |c| c.name == :updated_at }
+ @most_recent_changes[t.pretty_name] = t.first(sort: "#{t.table_name}.updated_at").try(:updated_at)
end
end
render @action.template_name, status: (flash[:error].present? ? :not_found : 200)
@@ -54,7 +54,7 @@ class Index < RailsAdmin::Config::Actions::Base
@objects.to_json(@schema)
end
if params[:send_data]
- send_data output, filename: "#{params[:model_name]}_#{DateTime.now.strftime("%Y-%m-%d_%Hh%Mm%S")}.json"
+ send_data output, filename: "#{params[:model_name]}_#{DateTime.now.strftime('%Y-%m-%d_%Hh%Mm%S')}.json"
else
render json: output, root: false
end
@@ -63,7 +63,7 @@ class Index < RailsAdmin::Config::Actions::Base
format.xml do
output = @objects.to_xml(@schema)
if params[:send_data]
- send_data output, filename: "#{params[:model_name]}_#{DateTime.now.strftime("%Y-%m-%d_%Hh%Mm%S")}.xml"
+ send_data output, filename: "#{params[:model_name]}_#{DateTime.now.strftime('%Y-%m-%d_%Hh%Mm%S')}.xml"
else
render xml: output
end
@@ -73,8 +73,8 @@ class Index < RailsAdmin::Config::Actions::Base
header, encoding, output = CSVConverter.new(@objects, @schema).to_csv(params[:csv_options])
if params[:send_data]
send_data output,
- type: "text/csv; charset=#{encoding}; #{"header=present" if header}",
- disposition: "attachment; filename=#{params[:model_name]}_#{DateTime.now.strftime("%Y-%m-%d_%Hh%Mm%S")}.csv"
+ type: "text/csv; charset=#{encoding}; #{'header=present' if header}",
+ disposition: "attachment; filename=#{params[:model_name]}_#{DateTime.now.strftime('%Y-%m-%d_%Hh%Mm%S')}.csv"
else
render text: output
end
@@ -49,18 +49,16 @@ def self.factory(parent)
parent.abstract_model.properties.each do |properties|
# Unless a previous factory has already loaded current field as well
- unless fields.detect { |f| f.name == properties.name }
- # Loop through factories until one returns true
- @@registry.detect { |factory| factory.call(parent, properties, fields) }
- end
+ next if fields.detect { |f| f.name == properties.name }
+ # Loop through factories until one returns true
+ @@registry.detect { |factory| factory.call(parent, properties, fields) }
end
# Load fields for all associations (relations)
parent.abstract_model.associations.select { |a| a.type != :belongs_to }.each do |association| # :belongs_to are created by factory for belongs_to fields
# Unless a previous factory has already loaded current field as well
- unless fields.detect { |f| f.name == association.name }
- # Loop through factories until one returns true
- @@registry.detect { |factory| factory.call(parent, association, fields) }
- end
+ next if fields.detect { |f| f.name == association.name }
+ # Loop through factories until one returns true
+ @@registry.detect { |factory| factory.call(parent, association, fields) }
end
fields
end
@@ -199,9 +199,8 @@ def virtual?
register_instance_option :visible? do
returned = true
(RailsAdmin.config.default_hidden_fields || {}).each do |section, fields|
- if self.section.is_a?("RailsAdmin::Config::Sections::#{section.to_s.camelize}".constantize)
- returned = false if fields.include?(name)
- end
+ next unless self.section.is_a?("RailsAdmin::Config::Sections::#{section.to_s.camelize}".constantize)
+ returned = false if fields.include?(name)
end
returned
end
@@ -287,7 +286,7 @@ def generic_field_help
(translated.is_a?(Hash) ? translated.to_a.first[1] : translated).html_safe
end
- def parse_input(params)
+ def parse_input(_params)
# overriden
end
@@ -321,7 +320,7 @@ def inspect
else
"#{v}=#{value.inspect}"
end
- end.join(", ")
+ end.join(', ')
}>"
end
end
@@ -10,12 +10,11 @@
fields << field
children_fields = []
columns.each do |children_column_name|
- if child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
- children_field = fields.detect { |f| f.name == children_column_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields)
- children_field.hide unless field == children_field
- children_field.filterable(false) unless field == children_field
- children_fields << children_field.name
- end
+ next unless child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
+ children_field = fields.detect { |f| f.name == children_column_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields)
+ children_field.hide unless field == children_field
+ children_field.filterable(false) unless field == children_field
+ children_fields << children_field.name
end
field.children_fields(children_fields)
true
@@ -10,13 +10,12 @@
fields << RailsAdmin::Config::Fields::Types.load(:password).new(parent, :password_confirmation, properties)
extensions.each do |ext|
properties = parent.abstract_model.properties.detect { |p| ext == p.name }
- if properties
- unless field = fields.detect { |f| f.name == ext }
- RailsAdmin::Config::Fields.default_factory.call(parent, properties, fields)
- field = fields.last
- end
- field.hide
+ next unless properties
+ unless field = fields.detect { |f| f.name == ext }
+ RailsAdmin::Config::Fields.default_factory.call(parent, properties, fields)
+ field = fields.last
end
+ field.hide
end
true
else
@@ -9,12 +9,11 @@
children_fields = []
extensions.each do |ext|
children_column_name = "#{attachment_name}_#{ext}".to_sym
- if child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
- children_field = fields.detect { |f| f.name == children_column_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields)
- children_field.hide
- children_field.filterable(false)
- children_fields << children_field.name
- end
+ next unless child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
+ children_field = fields.detect { |f| f.name == children_column_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields)
+ children_field.hide
+ children_field.filterable(false)
+ children_fields << children_field.name
end
field.children_fields(children_fields)
fields << field
Oops, something went wrong.

0 comments on commit 61ad2ee

Please sign in to comment.