Skip to content

Commit 644e41b

Browse files
committed
Fix rubocop offenses
1 parent f2ea475 commit 644e41b

File tree

13 files changed

+46
-43
lines changed

13 files changed

+46
-43
lines changed

.rubocop.yml

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ AllCops:
55
- 'spec/dummy_app/db/schema.rb'
66
- 'vendor/bundle/**/*'
77

8+
Metrics/AbcSize:
9+
Max: 69.98 # TODO: Lower to 15
10+
811
Metrics/BlockNesting:
912
Max: 3
1013

app/helpers/rails_admin/application_helper.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def authorized?(action, abstract_model = nil, object = nil)
1919

2020
def current_action?(action, abstract_model = @abstract_model, object = @object)
2121
@action.custom_key == action.custom_key &&
22-
abstract_model.try(:to_param) == @abstract_model.try(:to_param) &&
23-
(@object.try(:persisted?) ? @object.id == object.try(:id) : !object.try(:persisted?))
22+
abstract_model.try(:to_param) == @abstract_model.try(:to_param) &&
23+
(@object.try(:persisted?) ? @object.id == object.try(:id) : !object.try(:persisted?))
2424
end
2525

2626
def action(key, abstract_model = nil, object = nil)
@@ -116,7 +116,7 @@ def breadcrumb(action = @action, _acc = [])
116116
o = a.send(:eval, 'bindings[:object]')
117117
content_tag(:li, class: current_action?(a, am, o) && 'active') do
118118
crumb = begin
119-
if not current_action?(a, am, o)
119+
if !current_action?(a, am, o)
120120
if a.http_methods.include?(:get)
121121
link_to url_for(action: a.action_name, controller: 'rails_admin/main', model_name: am.try(:to_param), id: (o.try(:persisted?) && o.try(:id) || nil)), class: 'pjax' do
122122
wording_for(:breadcrumb, a, am, o)
@@ -155,13 +155,13 @@ def bulk_menu(abstract_model = @abstract_model)
155155
return '' if actions.empty?
156156
content_tag :li, class: 'dropdown', style: 'float:right' do
157157
content_tag(:a, class: 'dropdown-toggle', :'data-toggle' => 'dropdown', href: '#') { t('admin.misc.bulk_menu_title').html_safe + '<b class="caret"></b>'.html_safe } +
158-
content_tag(:ul, class: 'dropdown-menu', style: 'left:auto; right:0;') do
159-
actions.collect do |action|
160-
content_tag :li do
161-
link_to wording_for(:bulk_link, action), '#', onclick: "jQuery('#bulk_action').val('#{action.action_name}'); jQuery('#bulk_form').submit(); return false;"
162-
end
163-
end.join.html_safe
164-
end
158+
content_tag(:ul, class: 'dropdown-menu', style: 'left:auto; right:0;') do
159+
actions.collect do |action|
160+
content_tag :li do
161+
link_to wording_for(:bulk_link, action), '#', onclick: "jQuery('#bulk_action').val('#{action.action_name}'); jQuery('#bulk_form').submit(); return false;"
162+
end
163+
end.join.html_safe
164+
end
165165
end.html_safe
166166
end
167167
end

app/helpers/rails_admin/form_builder.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ def generate(options = {})
1212
)
1313

1414
object_infos +
15-
visible_groups(options[:model_config], generator_action(options[:action], options[:nested_in])).collect do |fieldset|
16-
fieldset_for fieldset, options[:nested_in]
17-
end.join.html_safe +
18-
(options[:nested_in] ? '' : @template.render(partial: 'rails_admin/main/submit_buttons'))
15+
visible_groups(options[:model_config], generator_action(options[:action], options[:nested_in])).collect do |fieldset|
16+
fieldset_for fieldset, options[:nested_in]
17+
end.join.html_safe +
18+
(options[:nested_in] ? '' : @template.render(partial: 'rails_admin/main/submit_buttons'))
1919
end
2020
end
2121

@@ -36,7 +36,7 @@ def field_wrapper_for(field, nested_in)
3636
unless nested_field_association?(field, nested_in)
3737
@template.content_tag(:div, class: "form-group control-group #{field.type_css_class} #{field.css_class} #{'error' if field.errors.present?}", id: "#{dom_id(field)}_field") do
3838
label(field.method_name, capitalize_first_letter(field.label), class: 'col-sm-2 control-label') +
39-
(field.nested_form ? field_for(field) : input_for(field))
39+
(field.nested_form ? field_for(field) : input_for(field))
4040
end
4141
end
4242
else
@@ -49,8 +49,8 @@ def input_for(field)
4949
css += ' has-error' if field.errors.present?
5050
@template.content_tag(:div, class: css) do
5151
field_for(field) +
52-
errors_for(field) +
53-
help_for(field)
52+
errors_for(field) +
53+
help_for(field)
5454
end
5555
end
5656

lib/rails_admin/adapters/active_record.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def associations
5656
def properties
5757
columns = model.columns.reject do |c|
5858
c.type.blank? ||
59-
DISABLED_COLUMN_TYPES.include?(c.type.to_sym) ||
60-
c.try(:array)
59+
DISABLED_COLUMN_TYPES.include?(c.type.to_sym) ||
60+
c.try(:array)
6161
end
6262
columns.collect do |property|
6363
Property.new(property, model)

lib/rails_admin/adapters/mongoid/property.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def read_only?
7171

7272
def object_field_type
7373
if [:belongs_to, :referenced_in, :embedded_in].
74-
include?(model.relations.values.detect { |r| r.foreign_key.try(:to_sym) == name }.try(:macro).try(:to_sym))
74+
include?(model.relations.values.detect { |r| r.foreign_key.try(:to_sym) == name }.try(:macro).try(:to_sym))
7575
:bson_object_id
7676
else
7777
:string

lib/rails_admin/config/configurable.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module ClassMethods
2929
# accessed by an instance method. Both go by the name of the option.
3030
def register_instance_option(option_name, scope = self, &default)
3131
options = scope.instance_variable_get('@config_options') ||
32-
scope.instance_variable_set('@config_options', {})
32+
scope.instance_variable_set('@config_options', {})
3333

3434
option_name = option_name.to_s
3535
options[option_name] = nil

lib/rails_admin/config/fields/factories/enum.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
# NOTICE: _method_name could be `to_enum` and this method defined in Object.
1010
if !Object.respond_to?(method_name) && \
11-
(model.respond_to?(method_name) || \
12-
model.method_defined?(method_name))
11+
(model.respond_to?(method_name) || \
12+
model.method_defined?(method_name))
1313
fields << RailsAdmin::Config::Fields::Types::Enum.new(parent, properties.name, properties)
1414
true
1515
else

lib/rails_admin/extensions/paper_trail/auditing_adapter.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def listing_for_model_or_object(model, object, query, sort, sort_reverse, all, p
107107

108108
def version_class_for(model_name)
109109
klass = model_name.constantize.
110-
try(:version_class_name).
111-
try(:constantize)
110+
try(:version_class_name).
111+
try(:constantize)
112112

113113
klass || @version_class
114114
end

lib/rails_admin/support/csv_converter.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,23 @@ def generate_csv_header
8080
@fields.collect do |field|
8181
::I18n.t('admin.export.csv.header_for_root_methods', name: field.label, model: @abstract_model.pretty_name)
8282
end +
83-
@associations.flat_map do |_association_name, option_hash|
84-
option_hash[:fields].collect do |field|
85-
::I18n.t('admin.export.csv.header_for_association_methods', name: field.label, association: option_hash[:association].label)
83+
@associations.flat_map do |_association_name, option_hash|
84+
option_hash[:fields].collect do |field|
85+
::I18n.t('admin.export.csv.header_for_association_methods', name: field.label, association: option_hash[:association].label)
86+
end
8687
end
87-
end
8888
end
8989

9090
def generate_csv_row(object)
9191
@fields.collect do |field|
9292
field.with(object: object).export_value
9393
end +
94-
@associations.flat_map do |association_name, option_hash|
95-
associated_objects = [object.send(association_name)].flatten.compact
96-
option_hash[:fields].collect do |field|
97-
associated_objects.collect { |ao| field.with(object: ao).export_value.presence || @empty }.join(',')
94+
@associations.flat_map do |association_name, option_hash|
95+
associated_objects = [object.send(association_name)].flatten.compact
96+
option_hash[:fields].collect do |field|
97+
associated_objects.collect { |ao| field.with(object: ao).export_value.presence || @empty }.join(',')
98+
end
9899
end
99-
end
100100
end
101101
end
102102
end

spec/helpers/rails_admin/application_helper_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def initialize(_user)
6969
member :test_bindings do
7070
visible do
7171
bindings[:controller].is_a?(ActionView::TestCase::TestController) &&
72-
bindings[:abstract_model].model == Team &&
73-
bindings[:object].is_a?(Team)
72+
bindings[:abstract_model].model == Team &&
73+
bindings[:object].is_a?(Team)
7474
end
7575
end
7676
end
@@ -97,8 +97,8 @@ def initialize(_user)
9797
member :test_bindings do
9898
visible do
9999
bindings[:controller].is_a?(ActionView::TestCase::TestController) &&
100-
bindings[:abstract_model].model == Team &&
101-
bindings[:object].is_a?(Team)
100+
bindings[:abstract_model].model == Team &&
101+
bindings[:object].is_a?(Team)
102102
end
103103
end
104104
end

spec/integration/basic/export/rails_admin_basic_export_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
# and Mongoid with ActiveModel 3.1 does not support to_xml's :include options
7979
# (due change of implementation in ActiveModel::Serializers between 3.1 and 3.2)
8080
if RUBY_VERSION =~ /1\.9/ &&
81-
(CI_ORM != :mongoid || (CI_ORM == :mongoid && ActiveModel::VERSION::STRING >= '3.2'))
81+
(CI_ORM != :mongoid || (CI_ORM == :mongoid && ActiveModel::VERSION::STRING >= '3.2'))
8282
is_expected.to have_content @player.team.name
8383
end
8484
end

spec/rails_admin/adapters/active_record_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
before do
9696
@abstract_model = RailsAdmin::AbstractModel.new('Team')
9797
@teams = [{}, {name: 'somewhere foos'}, {manager: 'foo junior'}].
98-
collect { |h| FactoryGirl.create :team, h }
98+
collect { |h| FactoryGirl.create :team, h }
9999
end
100100

101101
it 'makes correct query' do
@@ -122,7 +122,7 @@
122122
@abstract_model = RailsAdmin::AbstractModel.new('Team')
123123
@division = FactoryGirl.create :division, name: 'bar division'
124124
@teams = [{}, {division: @division}, {name: 'somewhere foos', division: @division}, {name: 'nowhere foos'}].
125-
collect { |h| FactoryGirl.create :team, h }
125+
collect { |h| FactoryGirl.create :team, h }
126126
end
127127

128128
context 'without configuration' do

spec/rails_admin/adapters/mongoid_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
before do
193193
@abstract_model = RailsAdmin::AbstractModel.new('Player')
194194
@players = [{}, {name: 'Many foos'}, {position: 'foo shortage'}].
195-
collect { |h| FactoryGirl.create :player, h }
195+
collect { |h| FactoryGirl.create :player, h }
196196
end
197197

198198
it 'makes correct query' do
@@ -205,7 +205,7 @@
205205
@abstract_model = RailsAdmin::AbstractModel.new('Player')
206206
@team = FactoryGirl.create :team, name: 'king of bar'
207207
@players = [{}, {team: @team}, {name: 'Many foos', team: @team}, {name: 'Great foo'}].
208-
collect { |h| FactoryGirl.create :player, h }
208+
collect { |h| FactoryGirl.create :player, h }
209209
end
210210

211211
it 'makes correct query' do

0 commit comments

Comments
 (0)