Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Autocorrect all autocorrectable offenses

  • Loading branch information...
commit 03431bcb8f1778d273f8f11d93153e35905085ac 1 parent 71d6443
@sferik authored
Showing with 3,728 additions and 3,830 deletions.
  1. +0 −1  .travis.yml
  2. +8 −8 Gemfile
  3. +2 −2 Rakefile
  4. +12 −12 app/controllers/rails_admin/application_controller.rb
  5. +30 −35 app/controllers/rails_admin/main_controller.rb
  6. +36 −39 app/helpers/rails_admin/application_helper.rb
  7. +26 −25 app/helpers/rails_admin/form_builder.rb
  8. +10 −9 app/helpers/rails_admin/main_helper.rb
  9. +3 −3 config/initializers/active_record_extensions.rb
  10. +1 −1  config/initializers/haml.rb
  11. +7 −7 config/routes.rb
  12. +5 −5 lib/generators/rails_admin/install_generator.rb
  13. +1 −1  lib/generators/rails_admin/templates/initializer.erb
  14. +4 −3 lib/generators/rails_admin/utils.rb
  15. +29 −27 lib/rails_admin/abstract_model.rb
  16. +36 −36 lib/rails_admin/adapters/active_record.rb
  17. +2 −2 lib/rails_admin/adapters/active_record/abstract_object.rb
  18. +100 −106 lib/rails_admin/adapters/mongoid.rb
  19. +1 −1  lib/rails_admin/adapters/mongoid/abstract_object.rb
  20. +5 −5 lib/rails_admin/adapters/mongoid/extension.rb
  21. +7 −8 lib/rails_admin/bootstrap-sass.rb
  22. +2 −1  lib/rails_admin/bootstrap-sass/compass_functions.rb
  23. +23 −23 lib/rails_admin/config.rb
  24. +12 −15 lib/rails_admin/config/actions.rb
  25. +8 −8 lib/rails_admin/config/actions/base.rb
  26. +3 −3 lib/rails_admin/config/actions/bulk_delete.rb
  27. +5 −5 lib/rails_admin/config/actions/dashboard.rb
  28. +4 −4 lib/rails_admin/config/actions/delete.rb
  29. +3 −3 lib/rails_admin/config/actions/edit.rb
  30. +1 −1  lib/rails_admin/config/actions/export.rb
  31. +1 −1  lib/rails_admin/config/actions/history_index.rb
  32. +1 −1  lib/rails_admin/config/actions/history_show.rb
  33. +11 −12 lib/rails_admin/config/actions/index.rb
  34. +3 −3 lib/rails_admin/config/actions/new.rb
  35. +2 −2 lib/rails_admin/config/actions/show.rb
  36. +1 −1  lib/rails_admin/config/actions/show_in_app.rb
  37. +26 −26 lib/rails_admin/config/configurable.rb
  38. +7 −7 lib/rails_admin/config/fields.rb
  39. +5 −6 lib/rails_admin/config/fields/association.rb
  40. +32 −30 lib/rails_admin/config/fields/base.rb
  41. +9 −10 lib/rails_admin/config/fields/factories/association.rb
  42. +3 −9 lib/rails_admin/config/fields/factories/carrierwave.rb
  43. +2 −4 lib/rails_admin/config/fields/factories/devise.rb
  44. +3 −5 lib/rails_admin/config/fields/factories/dragonfly.rb
  45. +1 −1  lib/rails_admin/config/fields/factories/enum.rb
  46. +3 −3 lib/rails_admin/config/fields/factories/paperclip.rb
  47. +6 −8 lib/rails_admin/config/fields/group.rb
  48. +2 −2 lib/rails_admin/config/fields/types.rb
  49. +4 −4 lib/rails_admin/config/fields/types/belongs_to_association.rb
  50. +2 −2 lib/rails_admin/config/fields/types/boolean.rb
  51. +7 −12 lib/rails_admin/config/fields/types/bson_object_id.rb
  52. +1 −1  lib/rails_admin/config/fields/types/carrierwave.rb
  53. +3 −3 lib/rails_admin/config/fields/types/ck_editor.rb
  54. +9 −9 lib/rails_admin/config/fields/types/code_mirror.rb
  55. +2 −2 lib/rails_admin/config/fields/types/color.rb
  56. +2 −2 lib/rails_admin/config/fields/types/date.rb
  57. +52 −54 lib/rails_admin/config/fields/types/datetime.rb
  58. +1 −1  lib/rails_admin/config/fields/types/decimal.rb
  59. +2 −2 lib/rails_admin/config/fields/types/dragonfly.rb
  60. +3 −3 lib/rails_admin/config/fields/types/enum.rb
  61. +5 −5 lib/rails_admin/config/fields/types/file_upload.rb
  62. +1 −1  lib/rails_admin/config/fields/types/float.rb
  63. +1 −1  lib/rails_admin/config/fields/types/has_and_belongs_to_many_association.rb
  64. +1 −1  lib/rails_admin/config/fields/types/has_many_association.rb
  65. +3 −4 lib/rails_admin/config/fields/types/has_one_association.rb
  66. +1 −1  lib/rails_admin/config/fields/types/hidden.rb
  67. +1 −1  lib/rails_admin/config/fields/types/integer.rb
  68. +2 −2 lib/rails_admin/config/fields/types/paperclip.rb
  69. +4 −4 lib/rails_admin/config/fields/types/password.rb
  70. +8 −11 lib/rails_admin/config/fields/types/polymorphic_association.rb
  71. +1 −1  lib/rails_admin/config/fields/types/serialized.rb
  72. +5 −6 lib/rails_admin/config/fields/types/string.rb
  73. +6 −6 lib/rails_admin/config/fields/types/text.rb
  74. +4 −4 lib/rails_admin/config/fields/types/time.rb
  75. +1 −1  lib/rails_admin/config/fields/types/timestamp.rb
  76. +1 −2  lib/rails_admin/config/fields/types/wysihtml5.rb
  77. +24 −24 lib/rails_admin/config/has_fields.rb
  78. +3 −3 lib/rails_admin/config/has_groups.rb
  79. +2 −2 lib/rails_admin/config/hideable.rb
  80. +1 −1  lib/rails_admin/config/lazy_model.rb
  81. +6 −7 lib/rails_admin/config/model.rb
  82. +4 −6 lib/rails_admin/config/proxyable/proxy.rb
  83. +1 −3 lib/rails_admin/config/sections.rb
  84. +1 −1  lib/rails_admin/config/sections/base.rb
  85. +3 −3 lib/rails_admin/engine.rb
  86. +3 −3 lib/rails_admin/extension.rb
  87. +3 −3 lib/rails_admin/extensions/cancan.rb
  88. +1 −1  lib/rails_admin/extensions/cancan/authorization_adapter.rb
  89. +3 −3 lib/rails_admin/extensions/history.rb
  90. +1 −1  lib/rails_admin/extensions/history/auditing_adapter.rb
  91. +12 −11 lib/rails_admin/extensions/history/history.rb
  92. +3 −3 lib/rails_admin/extensions/paper_trail.rb
  93. +21 −20 lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
  94. +11 −15 lib/rails_admin/i18n_support.rb
  95. +4 −5 lib/rails_admin/support/core_extensions.rb
  96. +21 −23 lib/rails_admin/support/csv_converter.rb
  97. +0 −3  lib/rails_admin/version.rb
  98. +3 −3 rails_admin.gemspec
  99. +12 −12 spec/controllers/rails_admin/application_controller_spec.rb
  100. +127 −130 spec/controllers/rails_admin/main_controller_spec.rb
  101. +4 −4 spec/dummy_app/Gemfile
  102. +0 −2  spec/dummy_app/app/active_record/abstract.rb
  103. +1 −1  spec/dummy_app/app/active_record/another_field_test.rb
  104. +2 −2 spec/dummy_app/app/active_record/ball.rb
  105. +1 −3 spec/dummy_app/app/active_record/carrierwave_uploader.rb
  106. +1 −1  spec/dummy_app/app/active_record/category.rb
  107. +1 −1  spec/dummy_app/app/active_record/cms/basic_page.rb
  108. +1 −1  spec/dummy_app/app/active_record/comment.rb
  109. +1 −1  spec/dummy_app/app/active_record/comment/confirmed.rb
  110. +2 −2 spec/dummy_app/app/active_record/division.rb
  111. +5 −5 spec/dummy_app/app/active_record/draft.rb
  112. +6 −6 spec/dummy_app/app/active_record/field_test.rb
  113. +1 −1  spec/dummy_app/app/active_record/image.rb
  114. +3 −3 spec/dummy_app/app/active_record/league.rb
  115. +4 −4 spec/dummy_app/app/active_record/nested_field_test.rb
  116. +7 −7 spec/dummy_app/app/active_record/player.rb
  117. +9 −10 spec/dummy_app/app/active_record/team.rb
  118. +2 −2 spec/dummy_app/app/active_record/user.rb
  119. +1 −1  spec/dummy_app/app/mongoid/another_field_test.rb
  120. +3 −3 spec/dummy_app/app/mongoid/ball.rb
  121. +1 −3 spec/dummy_app/app/mongoid/carrierwave_uploader.rb
  122. +1 −1  spec/dummy_app/app/mongoid/category.rb
  123. +3 −3 spec/dummy_app/app/mongoid/cms/basic_page.rb
  124. +2 −2 spec/dummy_app/app/mongoid/comment.rb
  125. +1 −1  spec/dummy_app/app/mongoid/comment/confirmed.rb
  126. +2 −2 spec/dummy_app/app/mongoid/division.rb
  127. +11 −11 spec/dummy_app/app/mongoid/draft.rb
  128. +1 −1  spec/dummy_app/app/mongoid/embed.rb
  129. +1 −1  spec/dummy_app/app/mongoid/fan.rb
  130. +35 −35 spec/dummy_app/app/mongoid/field_test.rb
  131. +1 −1  spec/dummy_app/app/mongoid/image.rb
  132. +3 −3 spec/dummy_app/app/mongoid/league.rb
  133. +5 −5 spec/dummy_app/app/mongoid/nested_field_test.rb
  134. +17 −17 spec/dummy_app/app/mongoid/player.rb
  135. +25 −25 spec/dummy_app/app/mongoid/team.rb
  136. +13 −13 spec/dummy_app/app/mongoid/user.rb
  137. +4 −4 spec/dummy_app/config/application.rb
  138. +1 −3 spec/dummy_app/config/boot.rb
  139. +1 −1  spec/dummy_app/config/environments/test.rb
  140. +2 −2 spec/dummy_app/config/initializers/devise.rb
  141. +1 −2  spec/dummy_app/config/initializers/session_patch.rb
  142. +1 −1  spec/dummy_app/config/initializers/session_store.rb
  143. +1 −1  spec/dummy_app/config/initializers/wrap_parameters.rb
  144. +2 −2 spec/dummy_app/config/routes.rb
  145. +1 −1  spec/dummy_app/db/migrate/00000000000001_create_divisions_migration.rb
  146. +1 −1  spec/dummy_app/db/migrate/00000000000002_create_drafts_migration.rb
  147. +1 −1  spec/dummy_app/db/migrate/00000000000003_create_leagues_migration.rb
  148. +5 −5 spec/dummy_app/db/migrate/00000000000004_create_players_migration.rb
  149. +5 −5 spec/dummy_app/db/migrate/00000000000005_create_teams_migration.rb
  150. +5 −5 spec/dummy_app/db/migrate/00000000000006_devise_create_users.rb
  151. +7 −7 spec/dummy_app/db/migrate/00000000000007_create_histories_table.rb
  152. +1 −1  spec/dummy_app/db/migrate/00000000000008_create_fans_migration.rb
  153. +1 −1  spec/dummy_app/db/migrate/00000000000009_create_fans_teams_migration.rb
  154. +1 −1  spec/dummy_app/db/migrate/00000000000010_add_revenue_to_team_migration.rb
  155. +1 −1  spec/dummy_app/db/migrate/00000000000011_add_suspended_to_player_migration.rb
  156. +0 −1  spec/dummy_app/db/migrate/00000000000012_add_avatar_columns_to_user.rb
  157. +1 −1  spec/dummy_app/db/migrate/20101223222233_create_rel_tests.rb
  158. +1 −1  spec/dummy_app/db/migrate/20110714095433_create_balls.rb
  159. +3 −3 spec/dummy_app/db/migrate/20110901131551_change_division_primary_key.rb
  160. +4 −5 spec/dummy_app/db/migrate/20110901150912_set_primary_key_not_null_for_divisions.rb
  161. +1 −1  spec/dummy_app/db/migrate/20120319041705_drop_rel_tests.rb
  162. +9 −9 spec/dummy_app/db/seeds.rb
  163. +2 −3 spec/factories.rb
  164. +86 −86 spec/helpers/rails_admin/application_helper_spec.rb
  165. +6 −6 spec/helpers/rails_admin/form_builder_spec.rb
  166. +167 −174 spec/integration/authorization/cancan_spec.rb
  167. +11 −11 spec/integration/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb
  168. +16 −16 spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb
  169. +69 −69 spec/integration/basic/create/rails_admin_basic_create_spec.rb
  170. +8 −8 spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb
  171. +21 −21 spec/integration/basic/delete/rails_admin_basic_delete_spec.rb
  172. +32 −32 spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb
  173. +39 −39 spec/integration/basic/edit/rails_admin_basic_edit_spec.rb
  174. +36 −36 spec/integration/basic/export/rails_admin_basic_export_spec.rb
  175. +144 −146 spec/integration/basic/list/rails_admin_basic_list_spec.rb
  176. +30 −30 spec/integration/basic/new/rails_admin_basic_new_spec.rb
  177. +12 −12 spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb
  178. +34 −34 spec/integration/basic/show/rails_admin_basic_show_spec.rb
  179. +90 −90 spec/integration/basic/update/rails_admin_basic_update_spec.rb
  180. +351 −352 spec/integration/config/edit/rails_admin_config_edit_spec.rb
  181. +132 −133 spec/integration/config/list/rails_admin_config_list_spec.rb
  182. +82 −83 spec/integration/config/show/rails_admin_config_show_spec.rb
  183. +15 −15 spec/integration/history/rails_admin_history_spec.rb
  184. +43 −43 spec/integration/rails_admin_spec.rb
  185. +12 −12 spec/integration/relation_spec.rb
  186. +7 −4 spec/orm/active_record.rb
  187. +1 −7 spec/orm/mongoid.rb
  188. +28 −28 spec/rails_admin/abstract_model_spec.rb
  189. +3 −3 spec/rails_admin/active_record_extension_spec.rb
  190. +29 −29 spec/rails_admin/adapters/active_record/abstract_object_spec.rb
  191. +210 −215 spec/rails_admin/adapters/active_record_spec.rb
  192. +19 −19 spec/rails_admin/adapters/mongoid/abstract_object_spec.rb
  193. +429 −435 spec/rails_admin/adapters/mongoid_spec.rb
  194. +9 −9 spec/rails_admin/config/actions/base_spec.rb
  195. +42 −42 spec/rails_admin/config/actions_spec.rb
  196. +135 −136 spec/rails_admin/config/fields/base_spec.rb
  197. +17 −17 spec/rails_admin/config/fields/date_spec.rb
  198. +12 −13 spec/rails_admin/config/fields/datetime_spec.rb
  199. +4 −5 spec/rails_admin/config/fields/file_upload_spec.rb
  200. +12 −13 spec/rails_admin/config/fields/time_spec.rb
  201. +5 −5 spec/rails_admin/config/fields/timestamp_spec.rb
  202. +1 −1  spec/rails_admin/config/fields/types/ck_editor_spec.rb
  203. +2 −2 spec/rails_admin/config/fields/types/datetime_spec.rb
  204. +4 −4 spec/rails_admin/config/fields_spec.rb
  205. +4 −4 spec/rails_admin/config/has_fields_spec.rb
  206. +5 −5 spec/rails_admin/config/lazy_model_spec.rb
  207. +50 −50 spec/rails_admin/config/model_spec.rb
  208. +7 −10 spec/rails_admin/config/proxyable/proxy_spec.rb
  209. +22 −22 spec/rails_admin/config/sections_spec.rb
  210. +79 −80 spec/rails_admin/config_spec.rb
  211. +3 −3 spec/rails_admin/support/csv_converter_spec.rb
  212. +6 −6 spec/spec_helper.rb
View
1  .travis.yml
@@ -39,4 +39,3 @@ before_script:
- cd ../../
services:
- mongodb
-script: bundle exec rake default
View
16 Gemfile
@@ -28,10 +28,10 @@ group :active_record do
end
group :mongoid do
- gem 'mongoid', :github => 'mongoid/mongoid'
- gem 'mongoid-paperclip', '>= 0.0.8', :require => 'mongoid_paperclip'
- gem 'mongoid-grid_fs', :github => 'ahoward/mongoid-grid_fs'
- gem 'carrierwave-mongoid', '>= 0.6.3', :require => 'carrierwave/mongoid'
+ gem 'mongoid', github: 'mongoid/mongoid'
+ gem 'mongoid-paperclip', '>= 0.0.8', require: 'mongoid_paperclip'
+ gem 'mongoid-grid_fs', github: 'ahoward/mongoid-grid_fs'
+ gem 'carrierwave-mongoid', '>= 0.6.3', require: 'carrierwave/mongoid'
end
group :development, :test do
@@ -47,7 +47,7 @@ group :test do
gem 'cancan', '>= 1.6'
gem 'capybara', '>= 2.1'
gem 'carrierwave', '>= 0.8'
- gem 'coveralls', :require => false
+ gem 'coveralls', require: false
gem 'database_cleaner', '>= 1.2'
gem 'devise', '>= 3.2'
gem 'dragonfly', '~> 0.9.0'
@@ -56,11 +56,11 @@ group :test do
gem 'launchy', '>= 2.2'
gem 'mini_magick', '>= 3.4'
gem 'paperclip', '>= 3.4'
- gem 'poltergeist', :github => 'jonleighton/poltergeist'
- gem 'rack-cache', :require => 'rack/cache'
+ gem 'poltergeist', github: 'jonleighton/poltergeist'
+ gem 'rack-cache', require: 'rack/cache'
gem 'rspec-rails', '>= 2.14'
gem 'rubocop', '>= 0.15'
- gem 'simplecov', :require => false
+ gem 'simplecov', require: false
gem 'timecop', '>= 0.5'
end
View
4 Rakefile
@@ -9,7 +9,7 @@ Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
-task :test => :spec
+task test: :spec
begin
require 'rubocop/rake_task'
@@ -21,4 +21,4 @@ rescue LoadError
end
end
-task :default => [:spec, :rubocop]
+task default: [:spec, :rubocop]
View
24 app/controllers/rails_admin/application_controller.rb
@@ -20,57 +20,57 @@ class ApplicationController < ::ApplicationController
def get_model
@model_name = to_model_name(params[:model_name])
- raise RailsAdmin::ModelNotFound unless (@abstract_model = RailsAdmin::AbstractModel.new(@model_name))
- raise RailsAdmin::ModelNotFound if (@model_config = @abstract_model.config).excluded?
+ fail(RailsAdmin::ModelNotFound) unless (@abstract_model = RailsAdmin::AbstractModel.new(@model_name))
+ fail(RailsAdmin::ModelNotFound) if (@model_config = @abstract_model.config).excluded?
@properties = @abstract_model.properties
end
def get_object
- raise RailsAdmin::ObjectNotFound unless (@object = @abstract_model.get(params[:id]))
+ fail(RailsAdmin::ObjectNotFound) unless (@object = @abstract_model.get(params[:id]))
end
def to_model_name(param)
- model_name = param.split("~").map(&:camelize).join("::")
+ param.split('~').collect(&:camelize).join('::')
end
- private
+ private
def _get_plugin_name
@plugin_name_array ||= [RailsAdmin.config.main_app_name.is_a?(Proc) ? instance_eval(&RailsAdmin.config.main_app_name) : RailsAdmin.config.main_app_name].flatten
end
def _authenticate!
- instance_eval &RailsAdmin::Config.authenticate_with
+ instance_eval(&RailsAdmin::Config.authenticate_with)
end
def _authorize!
- instance_eval &RailsAdmin::Config.authorize_with
+ instance_eval(&RailsAdmin::Config.authorize_with)
end
def _audit!
- instance_eval &RailsAdmin::Config.audit_with
+ instance_eval(&RailsAdmin::Config.audit_with)
end
def _current_user
- instance_eval &RailsAdmin::Config.current_user_method
+ instance_eval(&RailsAdmin::Config.current_user_method)
end
alias_method :user_for_paper_trail, :_current_user
rescue_from RailsAdmin::ObjectNotFound do
- flash[:error] = I18n.t('admin.flash.object_not_found', :model => @model_name, :id => params[:id])
+ flash[:error] = I18n.t('admin.flash.object_not_found', model: @model_name, id: params[:id])
params[:action] = 'index'
index
end
rescue_from RailsAdmin::ModelNotFound do
- flash[:error] = I18n.t('admin.flash.model_not_found', :model => @model_name)
+ flash[:error] = I18n.t('admin.flash.model_not_found', model: @model_name)
params[:action] = 'dashboard'
dashboard
end
def not_found
- render :file => Rails.root.join('public', '404.html'), :layout => false, :status => :not_found
+ render file: Rails.root.join('public', '404.html'), layout: false, status: :not_found
end
def rails_admin_controller?
View
65 app/controllers/rails_admin/main_controller.rb
@@ -1,15 +1,13 @@
module RailsAdmin
-
class MainController < RailsAdmin::ApplicationController
-
include ActionView::Helpers::TextHelper
include RailsAdmin::MainHelper
include RailsAdmin::ApplicationHelper
layout :get_layout
- before_filter :get_model, :except => RailsAdmin::Config::Actions.all(:root).map(&:action_name)
- before_filter :get_object, :only => RailsAdmin::Config::Actions.all(:member).map(&:action_name)
+ before_filter :get_model, except: RailsAdmin::Config::Actions.all(:root).collect(&:action_name)
+ before_filter :get_object, only: RailsAdmin::Config::Actions.all(:member).collect(&:action_name)
before_filter :check_for_cancel
RailsAdmin::Config::Actions.all.each do |action|
@@ -26,7 +24,7 @@ def #{action.action_name}
end
def bulk_action
- self.send(params[:bulk_action]) if params[:bulk_action].in?(RailsAdmin::Config::Actions.all(:controller => self, :abstract_model => @abstract_model).select(&:bulkable?).map(&:route_fragment))
+ send(params[:bulk_action]) if params[:bulk_action].in?(RailsAdmin::Config::Actions.all(controller: self, abstract_model: @abstract_model).select(&:bulkable?).collect(&:route_fragment))
end
def list_entries(model_config = @model_config, auth_scope_key = :index, additional_scope = get_association_scope_from_params, pagination = !(params[:associated_collection] || params[:all] || params[:bulk_ids]))
@@ -39,7 +37,7 @@ def list_entries(model_config = @model_config, auth_scope_key = :index, addition
get_collection(model_config, scope, pagination)
end
- private
+ private
def get_layout
"rails_admin/#{request.headers['X-PJAX'] ? 'pjax' : 'application'}"
@@ -51,12 +49,12 @@ def back_or_index
def get_sort_hash(model_config)
abstract_model = model_config.abstract_model
- params[:sort] = params[:sort_reverse] = nil unless model_config.list.fields.map {|f| f.name.to_s}.include? params[:sort]
+ params[:sort] = params[:sort_reverse] = nil unless model_config.list.fields.collect { |f| f.name.to_s }.include? params[:sort]
params[:sort] ||= model_config.list.sort_by.to_s
params[:sort_reverse] ||= 'false'
- field = model_config.list.fields.find{ |f| f.name.to_s == params[:sort] }
+ field = model_config.list.fields.detect { |f| f.name.to_s == params[:sort] }
column = if field.nil? || field.sortable == true # use params[:sort] on the base table
"#{abstract_model.table_name}.#{params[:sort]}"
@@ -73,33 +71,33 @@ def get_sort_hash(model_config)
end
reversed_sort = (field ? field.sort_reverse? : model_config.list.sort_reverse?)
- {:sort => column, :sort_reverse => (params[:sort_reverse] == reversed_sort.to_s)}
+ {sort: column, sort_reverse: (params[:sort_reverse] == reversed_sort.to_s)}
end
def redirect_to_on_success
- notice = t("admin.flash.successful", :name => @model_config.label, :action => t("admin.actions.#{@action.key}.done"))
+ notice = t('admin.flash.successful', name: @model_config.label, action: t("admin.actions.#{@action.key}.done"))
if params[:_add_another]
- redirect_to new_path(:return_to => params[:return_to]), :flash => { :success => notice }
+ redirect_to new_path(return_to: params[:return_to]), flash: {success: notice}
elsif params[:_add_edit]
- redirect_to edit_path(:id => @object.id, :return_to => params[:return_to]), :flash => { :success => notice }
+ redirect_to edit_path(id: @object.id, return_to: params[:return_to]), flash: {success: notice}
else
- redirect_to back_or_index, :flash => { :success => notice }
+ redirect_to back_or_index, flash: {success: notice}
end
end
def satisfy_strong_params!
- if @abstract_model.model.ancestors.map(&:to_s).include?('ActiveModel::ForbiddenAttributesProtection')
+ if @abstract_model.model.ancestors.collect(&:to_s).include?('ActiveModel::ForbiddenAttributesProtection')
params[@abstract_model.param_key].try :permit!
end
end
def sanitize_params_for!(action, model_config = @model_config, _params = params[@abstract_model.param_key])
return unless _params.present?
- fields = model_config.send(action).with(:controller => self, :view => self.view_context, :object => @object).visible_fields
- allowed_methods = fields.map{|f|
+ fields = model_config.send(action).with(controller: self, view: view_context, object: @object).visible_fields
+ allowed_methods = fields.collect do|f|
f.allowed_methods
- }.flatten.uniq.map(&:to_s) << "id" << "_destroy"
- fields.each {|f| f.parse_input(_params) }
+ end.flatten.uniq.collect(&:to_s) << 'id' << '_destroy'
+ fields.each { |f| f.parse_input(_params) }
_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
@@ -109,35 +107,32 @@ def sanitize_params_for!(action, model_config = @model_config, _params = params[
end
end
- def handle_save_error whereto = :new
- action = params[:action]
-
- flash.now[:error] = t("admin.flash.error", :name => @model_config.label, :action => t("admin.actions.#{@action.key}.done"))
+ def handle_save_error(whereto = :new)
+ flash.now[:error] = t('admin.flash.error', name: @model_config.label, action: t("admin.actions.#{@action.key}.done"))
flash.now[:error] += ". #{@object.errors[:base].to_sentence}" unless @object.errors[:base].blank?
respond_to do |format|
- format.html { render whereto, :status => :not_acceptable }
- format.js { render whereto, :layout => false, :status => :not_acceptable }
+ format.html { render whereto, status: :not_acceptable }
+ format.js { render whereto, layout: false, status: :not_acceptable }
end
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") })
+ redirect_to(back_or_index, flash: {info: t('admin.flash.noaction')})
end
end
def get_collection(model_config, scope, pagination)
- associations = model_config.list.fields.select {|f| f.type == :belongs_to_association && !f.polymorphic? }.map {|f| f.association[:name] }
+ associations = model_config.list.fields.select { |f| f.type == :belongs_to_association && !f.polymorphic? }.collect { |f| f.association[:name] }
options = {}
- options = options.merge(:page => (params[Kaminari.config.param_name] || 1).to_i, :per => (params[:per] || model_config.list.items_per_page)) if pagination
- options = options.merge(:include => associations) unless associations.blank?
+ options = options.merge(page: (params[Kaminari.config.param_name] || 1).to_i, per: (params[:per] || model_config.list.items_per_page)) if pagination
+ options = options.merge(include: associations) unless associations.blank?
options = options.merge(get_sort_hash(model_config))
- options = options.merge(:query => params[:query]) if params[:query].present?
- options = options.merge(:filters => params[:f]) if params[:f].present?
- options = options.merge(:bulk_ids => params[:bulk_ids]) if params[:bulk_ids]
-
- objects = model_config.abstract_model.all(options, scope)
+ options = options.merge(query: params[:query]) if params[:query].present?
+ options = options.merge(filters: params[:f]) if params[:f].present?
+ options = options.merge(bulk_ids: params[:bulk_ids]) if params[:bulk_ids]
+ model_config.abstract_model.all(options, scope)
end
def get_association_scope_from_params
@@ -145,8 +140,8 @@ def get_association_scope_from_params
source_abstract_model = RailsAdmin::AbstractModel.new(to_model_name(params[:source_abstract_model]))
source_model_config = source_abstract_model.config
source_object = source_abstract_model.get(params[:source_object_id])
- action = params[:current_action].in?(['create', 'update']) ? params[:current_action] : 'edit'
- @association = source_model_config.send(action).fields.find{|f| f.name == params[:associated_collection].to_sym }.with(:controller => self, :object => source_object)
+ action = params[:current_action].in?(%w(create update)) ? params[:current_action] : 'edit'
+ @association = source_model_config.send(action).fields.detect { |f| f.name == params[:associated_collection].to_sym }.with(controller: self, object: source_object)
@association.associated_collection_scope
end
end
View
75 app/helpers/rails_admin/application_helper.rb
@@ -2,7 +2,6 @@
module RailsAdmin
module ApplicationHelper
-
include RailsAdmin::I18nSupport
def authorized?(action, abstract_model = nil, object = nil)
@@ -17,18 +16,18 @@ def current_action?(action, abstract_model = @abstract_model, object = @object)
end
def action(key, abstract_model = nil, object = nil)
- RailsAdmin::Config::Actions.find(key, { :controller => self.controller, :abstract_model => abstract_model, :object => object })
+ RailsAdmin::Config::Actions.find(key, controller: controller, abstract_model: abstract_model, object: object)
end
def actions(scope = :all, abstract_model = nil, object = nil)
- RailsAdmin::Config::Actions.all(scope, { :controller => self.controller, :abstract_model => abstract_model, :object => object })
+ RailsAdmin::Config::Actions.all(scope, controller: controller, abstract_model: abstract_model, object: object)
end
def edit_user_link
return nil unless authorized?(:edit, _current_user.class, _current_user) && _current_user.respond_to?(:email)
return nil unless abstract_model = RailsAdmin.config(_current_user.class).abstract_model
- return nil unless edit_action = RailsAdmin::Config::Actions.find(:edit, {:controller => self.controller, :abstract_model => abstract_model, :object => _current_user })
- link_to _current_user.email, url_for(:action => edit_action.action_name, :model_name => abstract_model.to_param, :id => _current_user.id, :controller => 'rails_admin/main')
+ return nil unless edit_action = RailsAdmin::Config::Actions.find(:edit, controller: controller, abstract_model: abstract_model, object: _current_user)
+ link_to _current_user.email, url_for(action: edit_action.action_name, model_name: abstract_model.to_param, id: _current_user.id, controller: 'rails_admin/main')
end
def logout_path
@@ -41,22 +40,22 @@ def logout_path
def wording_for(label, action = @action, abstract_model = @abstract_model, object = @object)
model_config = abstract_model.try(:config)
object = abstract_model && object.is_a?(abstract_model.model) ? object : nil
- action = RailsAdmin::Config::Actions.find(action.to_sym) if (action.is_a?(Symbol) || action.is_a?(String))
+ action = RailsAdmin::Config::Actions.find(action.to_sym) if action.is_a?(Symbol) || action.is_a?(String)
I18n.t("admin.actions.#{action.i18n_key}.#{label}",
- :model_label => model_config && model_config.label,
- :model_label_plural => model_config && model_config.label_plural,
- :object_label => model_config && object.try(model_config.object_label_method)
+ model_label: model_config && model_config.label,
+ model_label_plural: model_config && model_config.label_plural,
+ object_label: model_config && object.try(model_config.object_label_method)
)
end
def main_navigation
- nodes_stack = RailsAdmin::Config.visible_models(:controller => self.controller)
- node_model_names = nodes_stack.map{ |c| c.abstract_model.model_name }
+ nodes_stack = RailsAdmin::Config.visible_models(controller: controller)
+ node_model_names = nodes_stack.collect { |c| c.abstract_model.model_name }
- nodes_stack.group_by(&:navigation_label).map do |navigation_label, nodes|
+ nodes_stack.group_by(&:navigation_label).collect do |navigation_label, nodes|
- nodes = nodes.select{ |n| n.parent.nil? || !n.parent.to_s.in?(node_model_names) }
+ nodes = nodes.select { |n| n.parent.nil? || !n.parent.to_s.in?(node_model_names) }
li_stack = navigation nodes_stack, nodes
label = navigation_label || t('admin.misc.navigation')
@@ -65,8 +64,8 @@ def main_navigation
end
def static_navigation
- li_stack = RailsAdmin::Config.navigation_static_links.map do |title, url|
- content_tag(:li, link_to(title.to_s, url, :target => '_blank'))
+ li_stack = RailsAdmin::Config.navigation_static_links.collect do |title, url|
+ content_tag(:li, link_to(title.to_s, url, target: '_blank'))
end.join
label = RailsAdmin::Config.navigation_static_label || t('admin.misc.navigation_static_label')
@@ -74,52 +73,52 @@ def static_navigation
li_stack
end
- def navigation nodes_stack, nodes, level=0
- nodes.map do |node|
+ def navigation(nodes_stack, nodes, level = 0)
+ nodes.collect do |node|
model_param = node.abstract_model.to_param
- url = url_for(:action => :index, :controller => 'rails_admin/main', :model_name => model_param)
+ url = url_for(action: :index, controller: 'rails_admin/main', model_name: model_param)
level_class = " nav-level-#{level}" if level > 0
nav_icon = node.navigation_icon ? %{<i class="#{node.navigation_icon}"></i>}.html_safe : ''
- li = content_tag :li, "data-model"=>model_param do
- link_to nav_icon + node.label_plural, url, :class => "pjax#{level_class}"
+ li = content_tag :li, 'data-model' => model_param do
+ link_to nav_icon + node.label_plural, url, class: "pjax#{level_class}"
end
- li + navigation(nodes_stack, nodes_stack.select{ |n| n.parent.to_s == node.abstract_model.model_name}, level+1)
+ li + navigation(nodes_stack, nodes_stack.select { |n| n.parent.to_s == node.abstract_model.model_name }, level + 1)
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))
- content_tag(:ul, :class => "breadcrumb") do
- parent_actions.map do |a|
+ content_tag(:ul, class: 'breadcrumb') do
+ parent_actions.collect do |a|
am = a.send(:eval, 'bindings[:abstract_model]')
o = a.send(:eval, 'bindings[:object]')
- content_tag(:li, :class => current_action?(a, am, o) && "active") do
+ content_tag(:li, class: current_action?(a, am, o) && 'active') do
crumb = if a.http_methods.include?(:get)
- 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
+ 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
wording_for(:breadcrumb, a, am, o)
end
else
content_tag(:span, wording_for(:breadcrumb, a, am, o))
end
- crumb+= content_tag(:span, '/', :class => 'divider') unless current_action?(a, am, o)
+ crumb += content_tag(:span, '/', class: 'divider') unless current_action?(a, am, o)
crumb
end
- end.reverse.join().html_safe
+ end.reverse.join.html_safe
end
end
# parent => :root, :collection, :member
def menu_for(parent, abstract_model = nil, object = nil, only_icon = false) # perf matters here (no action view trickery)
- actions = actions(parent, abstract_model, object).select{ |a| a.http_methods.include?(:get) }
- actions.map do |action|
+ actions = actions(parent, abstract_model, object).select { |a| a.http_methods.include?(:get) }
+ actions.collect do |action|
wording = wording_for(:menu, action)
%{
<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) })}">
+ <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>
</a>
@@ -128,21 +127,19 @@ def menu_for(parent, abstract_model = nil, object = nil, only_icon = false) # pe
end.join.html_safe
end
- def bulk_menu abstract_model = @abstract_model
+ def bulk_menu(abstract_model = @abstract_model)
actions = actions(:bulkable, abstract_model)
return '' if actions.empty?
- content_tag :li, { :class => 'dropdown', :style => 'float:right' } do
- content_tag(:a, { :class => 'dropdown-toggle', :'data-toggle' => "dropdown", :href => '#' }) { t('admin.misc.bulk_menu_title').html_safe + '<b class="caret"></b>'.html_safe } +
- content_tag(:ul, :class => 'dropdown-menu', :style => 'left:auto; right:0;') do
- actions.map do |action|
+ content_tag :li, class: 'dropdown', style: 'float:right' do
+ content_tag(:a, :class => 'dropdown-toggle', :'data-toggle' => 'dropdown', :href => '#') { t('admin.misc.bulk_menu_title').html_safe + '<b class="caret"></b>'.html_safe } +
+ content_tag(:ul, class: 'dropdown-menu', style: 'left:auto; right:0;') do
+ actions.collect do |action|
content_tag :li do
- link_to wording_for(:bulk_link, action), '#', :onclick => "jQuery('#bulk_action').val('#{action.action_name}'); jQuery('#bulk_form').submit(); return false;"
+ link_to wording_for(:bulk_link, action), '#', onclick: "jQuery('#bulk_action').val('#{action.action_name}'); jQuery('#bulk_form').submit(); return false;"
end
end.join.html_safe
end
end.html_safe
end
-
end
end
-
View
51 app/helpers/rails_admin/form_builder.rb
@@ -4,27 +4,27 @@ class FormBuilder < ::ActionView::Helpers::FormBuilder
def generate(options = {})
without_field_error_proc_added_div do
- options.reverse_merge!({
- :action => @template.controller.params[:action],
- :model_config => @template.instance_variable_get(:@model_config),
- :nested_in => false
- })
+ options.reverse_merge!(
+ action: @template.controller.params[:action],
+ model_config: @template.instance_variable_get(:@model_config),
+ nested_in: false
+ )
object_infos +
- visible_groups(options[:model_config], generator_action(options[:action], options[:nested_in])).map do |fieldset|
+ visible_groups(options[:model_config], generator_action(options[:action], options[:nested_in])).collect do |fieldset|
fieldset_for fieldset, options[:nested_in]
end.join.html_safe +
- (options[:nested_in] ? '' : @template.render(:partial => 'rails_admin/main/submit_buttons'))
+ (options[:nested_in] ? '' : @template.render(partial: 'rails_admin/main/submit_buttons'))
end
end
def fieldset_for(fieldset, nested_in)
- if (fields = fieldset.with(:form => self, :object => @object, :view => @template, :controller => @template.controller).visible_fields).length > 0
+ 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(: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.map{ |field| field_wrapper_for(field, nested_in) }.join
+ contents << fields.collect { |field| field_wrapper_for(field, nested_in) }.join
contents.join.html_safe
end
end
@@ -35,8 +35,8 @@ def field_wrapper_for(field, nested_in)
# do not show nested field if the target is the origin
unless field.inverse_of.presence && field.inverse_of == nested_in &&
@template.instance_variable_get(:@model_config).abstract_model == field.associated_model_config.abstract_model
- @template.content_tag(:div, :class => "control-group #{field.type_css_class} #{field.css_class} #{'error' if field.errors.present?}", :id => "#{dom_id(field)}_field") do
- label(field.method_name, field.label, :class => 'control-label') +
+ @template.content_tag(:div, class: "control-group #{field.type_css_class} #{field.css_class} #{'error' if field.errors.present?}", id: "#{dom_id(field)}_field") do
+ label(field.method_name, field.label, class: 'control-label') +
(field.nested_form ? field_for(field) : input_for(field))
end
end
@@ -46,7 +46,7 @@ def field_wrapper_for(field, nested_in)
end
def input_for(field)
- @template.content_tag(:div, :class => 'controls') do
+ @template.content_tag(:div, class: 'controls') do
field_for(field) +
errors_for(field) +
help_for(field)
@@ -54,11 +54,11 @@ def input_for(field)
end
def errors_for(field)
- field.errors.present? ? @template.content_tag(:span, "#{field.label} #{field.errors.to_sentence}", :class => 'help-inline') : ''.html_safe
+ field.errors.present? ? @template.content_tag(:span, "#{field.label} #{field.errors.to_sentence}", class: 'help-inline') : ''.html_safe
end
def help_for(field)
- field.help.present? ? @template.content_tag(:p, field.help, :class => 'help-block') : ''.html_safe
+ field.help.present? ? @template.content_tag(:p, field.help, class: 'help-block') : ''.html_safe
end
def field_for(field)
@@ -73,21 +73,21 @@ def object_infos
model_config = RailsAdmin.config(object)
model_label = model_config.label
object_label = if object.new_record?
- I18n.t('admin.form.new_model', :name => model_label)
+ I18n.t('admin.form.new_model', name: model_label)
else
object.send(model_config.object_label_method).presence || "#{model_config.label} ##{object.id}"
end
- %{<span style="display:none" class="object-infos" data-model-label="#{model_label}" data-object-label="#{CGI::escapeHTML(object_label)}"></span>}.html_safe
+ %{<span style="display:none" class="object-infos" data-model-label="#{model_label}" data-object-label="#{CGI.escapeHTML(object_label)}"></span>}.html_safe
end
- def jquery_namespace field
+ def jquery_namespace(field)
%{#{'#modal ' if @template.controller.params[:modal]}##{dom_id(field)}_field}
end
def dom_id(field)
(@dom_id ||= {})[field.name] ||=
[
- @object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, ""),
+ @object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, '_').sub(/_$/, ''),
options[:index],
field.method_name
].reject(&:blank?).join('_')
@@ -97,7 +97,8 @@ def dom_name(field)
(@dom_name ||= {})[field.name] ||= %{#{@object_name}#{options[:index] && "[#{options[:index]}]"}[#{field.method_name}]#{field.is_a?(Config::Fields::Association) && field.multiple? ? '[]' : ''}}
end
- protected
+ protected
+
def generator_action(action, nested)
if nested
action = :nested
@@ -110,17 +111,17 @@ def generator_action(action, nested)
def visible_groups(model_config, action)
model_config.send(action).with(
- :form => self,
- :object => @object,
- :view => @template,
- :controller => @template.controller
+ form: self,
+ object: @object,
+ view: @template,
+ controller: @template.controller
).visible_groups
end
def without_field_error_proc_added_div
default_field_error_proc = ::ActionView::Base.field_error_proc
begin
- ::ActionView::Base.field_error_proc = Proc.new { |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
View
19 app/helpers/rails_admin/main_helper.rb
@@ -3,16 +3,16 @@
module RailsAdmin
module MainHelper
def rails_admin_form_for(*args, &block)
- options = args.extract_options!.reverse_merge(:builder => RailsAdmin::FormBuilder)
+ options = args.extract_options!.reverse_merge(builder: RailsAdmin::FormBuilder)
form_for(*(args << options), &block) << after_nested_form_callbacks
end
def get_indicator(percent)
- return "" if percent < 0 # none
- return "info" if percent < 34 # < 1/100 of max
- return "success" if percent < 67 # < 1/10 of max
- return "warning" if percent < 84 # < 1/3 of max
- return "danger" # > 1/3 of max
+ return '' if percent < 0 # none
+ return 'info' if percent < 34 # < 1/100 of max
+ return 'success' if percent < 67 # < 1/10 of max
+ return 'warning' if percent < 84 # < 1/3 of max
+ 'danger' # > 1/3 of max
end
def get_column_sets(properties)
@@ -20,14 +20,15 @@ def get_column_sets(properties)
property_index = 0
set_index = 0
- while (property_index < properties.length)
+ while property_index < properties.length
current_set_width = 0
- begin
+ loop do
sets[set_index] ||= []
sets[set_index] << properties[property_index]
current_set_width += (properties[property_index].column_width || 120)
property_index += 1
- end while (current_set_width < RailsAdmin::Config.total_columns_width) && (property_index < properties.length)
+ break if current_set_width >= RailsAdmin::Config.total_columns_width || property_index >= properties.length
+ end
set_index += 1
end
sets
View
6 config/initializers/active_record_extensions.rb
@@ -5,14 +5,14 @@ def self.rails_admin(&block)
end
def rails_admin_default_object_label_method
- self.new_record? ? "new #{self.class.to_s}" : "#{self.class.to_s} ##{self.id}"
+ self.new_record? ? "new #{self.class.to_s}" : "#{self.class.to_s} ##{id}"
end
def safe_send(value)
if self.has_attribute?(value)
- self.read_attribute(value)
+ read_attribute(value)
else
- self.send(value)
+ send(value)
end
end
end
View
2  config/initializers/haml.rb
@@ -1,2 +1,2 @@
-require "haml"
+require 'haml'
Haml::Template.options[:ugly] = true
View
14 config/routes.rb
@@ -1,11 +1,11 @@
RailsAdmin::Engine.routes.draw do
- controller "main" do
- RailsAdmin::Config::Actions.all(:root).each { |action| match "/#{action.route_fragment}", :to => action.action_name, :as => action.action_name, :via => action.http_methods }
- scope ":model_name" do
- RailsAdmin::Config::Actions.all(:collection).each { |action| match "/#{action.route_fragment}", :to => action.action_name, :as => action.action_name, :via => action.http_methods }
- post "/bulk_action", :to => :bulk_action, :as => "bulk_action"
- scope ":id" do
- RailsAdmin::Config::Actions.all(:member).each { |action| match "/#{action.route_fragment}", :to => action.action_name, :as => action.action_name, :via => action.http_methods }
+ controller 'main' do
+ RailsAdmin::Config::Actions.all(:root).each { |action| match "/#{action.route_fragment}", to: action.action_name, as: action.action_name, via: action.http_methods }
+ scope ':model_name' do
+ RailsAdmin::Config::Actions.all(:collection).each { |action| match "/#{action.route_fragment}", to: action.action_name, as: action.action_name, via: action.http_methods }
+ post '/bulk_action', to: :bulk_action, as: 'bulk_action'
+ scope ':id' do
+ RailsAdmin::Config::Actions.all(:member).each { |action| match "/#{action.route_fragment}", to: action.action_name, as: action.action_name, via: action.http_methods }
end
end
end
View
10 lib/generators/rails_admin/install_generator.rb
@@ -3,16 +3,16 @@
module RailsAdmin
class InstallGenerator < Rails::Generators::Base
- source_root File.expand_path("../templates", __FILE__)
+ source_root File.expand_path('../templates', __FILE__)
include Generators::Utils::InstanceMethods
- argument :_namespace, :type => :string, :required => false, :desc => "RailsAdmin url namespace"
- desc "RailsAdmin installation generator"
+ argument :_namespace, type: :string, required: false, desc: 'RailsAdmin url namespace'
+ desc 'RailsAdmin installation generator'
def install
- namespace = ask_for("Where do you want to mount rails_admin?", "admin", _namespace)
+ namespace = ask_for('Where do you want to mount rails_admin?', 'admin', _namespace)
route("mount RailsAdmin::Engine => '/#{namespace}', :as => 'rails_admin'")
- template "initializer.erb", "config/initializers/rails_admin.rb"
+ template 'initializer.erb', 'config/initializers/rails_admin.rb'
end
end
end
View
2  lib/generators/rails_admin/templates/initializer.erb
@@ -6,7 +6,7 @@ RailsAdmin.config do |config|
# config.authenticate_with do
# warden.authenticate! scope: :user
# end
- # config.current_user_method &:current_user
+ # config.current_user_method(&:current_user)
## == Cancan ==
# config.authorize_with :cancan
View
7 lib/generators/rails_admin/utils.rb
@@ -7,12 +7,13 @@ def display(output, color = :green)
end
def ask_for(wording, default_value = nil, override_if_present_value = nil)
- override_if_present_value.present? ?
- display("Using [#{override_if_present_value}] for question '#{wording}'") && override_if_present_value :
+ if override_if_present_value.present?
+ display("Using [#{override_if_present_value}] for question '#{wording}'") && override_if_present_value
+ else
ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value
+ end
end
end
end
end
end
-
View
56 lib/rails_admin/abstract_model.rb
@@ -9,8 +9,8 @@ def reset
end
def all(adapter = nil)
- @@all ||= Config.models_pool.map{ |m| new(m) }.compact
- adapter ? @@all.select{|m| m.adapter == adapter} : @@all
+ @@all ||= Config.models_pool.collect { |m| new(m) }.compact
+ adapter ? @@all.select { |m| m.adapter == adapter } : @@all
end
alias_method :old_new, :new
@@ -18,7 +18,7 @@ def new(m)
m = m.constantize unless m.is_a?(Class)
(am = old_new(m)).model && am.adapter ? am : nil
rescue LoadError, NameError
- puts "[RailsAdmin] Could not load model #{m}, assuming model is non existing. (#{$!})" unless Rails.env.test?
+ puts "[RailsAdmin] Could not load model #{m}, assuming model is non existing. (#{$ERROR_INFO})" unless Rails.env.test?
nil
end
@@ -27,7 +27,7 @@ def new(m)
def polymorphic_parents(adapter, model_name, name)
@@polymorphic_parents[adapter.to_sym] ||= {}.tap do |hash|
all(adapter).each do |am|
- am.associations.select{|r| r[:as] }.each do |association|
+ am.associations.select { |r| r[:as] }.each do |association|
(hash[[association[:model_proc].call.to_s.underscore, association[:as]].join('_').to_sym] ||= []) << am.model
end
end
@@ -43,7 +43,7 @@ def reset_polymorphic_parents
def initialize(model_or_model_name)
@model_name = model_or_model_name.to_s
- ancestors = model.ancestors.map(&:to_s)
+ ancestors = model.ancestors.collect(&:to_s)
if ancestors.include?('ActiveRecord::Base') && !model.abstract_class?
initialize_active_record
elsif ancestors.include?('Mongoid::Document')
@@ -65,11 +65,11 @@ def config
end
def to_param
- @model_name.split("::").map(&:underscore).join("~")
+ @model_name.split('::').collect(&:underscore).join('~')
end
def param_key
- @model_name.split("::").map(&:underscore).join("_")
+ @model_name.split('::').collect(&:underscore).join('_')
end
def pretty_name
@@ -95,7 +95,7 @@ def each_associated_children(object)
end
end
- private
+ private
def initialize_active_record
@adapter = :active_record
@@ -124,7 +124,7 @@ def to_statement
build_statement_for_type_generic
end
- protected
+ protected
def get_filtering_duration
FilteringDuration.new(@operator, @value).get_duration
@@ -132,20 +132,22 @@ def get_filtering_duration
def build_statement_for_type_generic
build_statement_for_type || case @type
- when :date then build_statement_for_date
- when :datetime, :timestamp then build_statement_for_datetime_or_timestamp
- end
+ when :date
+ build_statement_for_date
+ when :datetime, :timestamp
+ build_statement_for_datetime_or_timestamp
+ end
end
def build_statement_for_type
- raise "You must override build_statement_for_type in your StatementBuilder"
+ fail('You must override build_statement_for_type in your StatementBuilder')
end
def build_statement_for_integer_decimal_or_float
case @value
when Array then
- val, range_begin, range_end = *@value.map do |v|
- if (v.to_i.to_s == v || v.to_f.to_s == v)
+ 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
end
@@ -174,11 +176,11 @@ def build_statement_for_datetime_or_timestamp
end
def unary_operators
- raise "You must override unary_operators in your StatementBuilder"
+ fail('You must override unary_operators in your StatementBuilder')
end
def range_filter(min, max)
- raise "You must override range_filter in your StatementBuilder"
+ fail('You must override range_filter in your StatementBuilder')
end
class FilteringDuration
@@ -189,12 +191,12 @@ def initialize(operator, value)
def get_duration
case @operator
- when 'between' then between
- when 'today' then today
- when 'yesterday' then yesterday
- when 'this_week' then this_week
- when 'last_week' then last_week
- else default
+ when 'between' then between
+ when 'today' then today
+ when 'yesterday' then yesterday
+ when 'this_week' then this_week
+ when 'last_week' then last_week
+ else default
end
end
@@ -212,7 +214,7 @@ def this_week
def last_week
[1.week.ago.to_date.beginning_of_week,
- 1.week.ago.to_date.end_of_week]
+ 1.week.ago.to_date.end_of_week]
end
def between
@@ -223,11 +225,11 @@ def default
[default_date, default_date]
end
- private
+ private
def date_format
- I18n.t("admin.misc.filter_date_format",
- :default => I18n.t("admin.misc.filter_date_format", :locale => :en)).gsub('dd', '%d').gsub('mm', '%m').gsub('yy', '%Y')
+ I18n.t('admin.misc.filter_date_format',
+ default: I18n.t('admin.misc.filter_date_format', locale: :en)).gsub('dd', '%d').gsub('mm', '%m').gsub('yy', '%Y')
end
def convert_to_date(value)
View
72 lib/rails_admin/adapters/active_record.rb
@@ -26,7 +26,7 @@ def first(options = {}, scope = nil)
end
def all(options = {}, scope = nil)
- scope ||= self.scoped
+ scope ||= scoped
scope = scope.includes(options[:include]) if options[:include]
scope = scope.limit(options[:limit]) if options[:limit]
scope = scope.where(primary_key => options[:bulk_ids]) if options[:bulk_ids]
@@ -40,15 +40,15 @@ def all(options = {}, scope = nil)
end
def count(options = {}, scope = nil)
- all(options.merge({:limit => false, :page => false}), scope).count
+ all(options.merge(limit: false, page: false), scope).count
end
def destroy(objects)
- Array.wrap(objects).each &:destroy
+ Array.wrap(objects).each(&:destroy)
end
def associations
- model.reflect_on_all_associations.map do |association|
+ model.reflect_on_all_associations.collect do |association|
Association.new(association, model).to_options_hash
end
end
@@ -57,9 +57,9 @@ def properties
columns = model.columns.reject do |c|
c.type.blank? ||
DISABLED_COLUMN_TYPES.include?(c.type.to_sym) ||
- DISABLED_COLUMN_MATCHERS.any? {|matcher| matcher.match(c.type.to_s)}
+ DISABLED_COLUMN_MATCHERS.any? { |matcher| matcher.match(c.type.to_s) }
end
- columns.map do |property|
+ columns.collect do |property|
{
:name => property.name.to_sym,
:pretty_name => property.name.to_s.tr('_', ' ').capitalize,
@@ -70,7 +70,7 @@ def properties
end
end
- delegate :primary_key, :table_name, :to => :model, :prefix => false
+ delegate :primary_key, :table_name, to: :model, prefix: false
def encoding
Rails.configuration.database_configuration[Rails.env]['encoding']
@@ -88,10 +88,9 @@ def adapter_supports_joins?
true
end
- private
+ private
class WhereBuilder
-
def initialize(scope)
@statements = []
@values = []
@@ -130,7 +129,7 @@ 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|
wb = WhereBuilder.new(scope)
- wb.add(fields.find{|f| f.name.to_s == field_name}, filter_dump[:v], (filter_dump[:o] || 'default'))
+ wb.add(fields.detect { |f| f.name.to_s == field_name }, filter_dump[:v], (filter_dump[:o] || 'default'))
# AND current filter statements to other filter statements
scope = wb.build
end
@@ -144,9 +143,9 @@ def build_statement(column, type, value, operator)
def type_lookup(property)
if model.serialized_attributes[property.name.to_s]
- {:type => :serialized}
+ {type: :serialized}
else
- {:type => property.type}
+ {type: property.type}
end
end
@@ -160,22 +159,23 @@ def initialize(association, model)
def to_options_hash
{
- :name => name.to_sym,
- :pretty_name => display_name,
- :type => macro,
- :model_proc => Proc.new { model_lookup },
- :primary_key_proc => Proc.new { primary_key_lookup },
- :foreign_key => foreign_key.to_sym,
- :foreign_type => foreign_type_lookup,
- :as => as_lookup,
- :polymorphic => polymorphic_lookup,
- :inverse_of => inverse_of_lookup,
- :read_only => read_only_lookup,
- :nested_form => nested_attributes_options_lookup
+ name: name.to_sym,
+ pretty_name: display_name,
+ type: macro,
+ model_proc: proc { model_lookup },
+ primary_key_proc: proc { primary_key_lookup },
+ foreign_key: foreign_key.to_sym,
+ foreign_type: foreign_type_lookup,
+ as: as_lookup,
+ polymorphic: polymorphic_lookup,
+ inverse_of: inverse_of_lookup,
+ read_only: read_only_lookup,
+ nested_form: nested_attributes_options_lookup
}
end
- private
+ private
+
def model_lookup
if options[:polymorphic]
polymorphic_parents(:active_record, model_name.to_s, name) || []
@@ -217,13 +217,13 @@ def display_name
end
delegate :klass, :macro, :name, :options, :scope, :foreign_key,
- :to => :association, :prefix => false
- delegate :name, :to => :model, :prefix => true
- delegate :polymorphic_parents, :to => RailsAdmin::AbstractModel
+ to: :association, prefix: false
+ delegate :name, to: :model, prefix: true
+ delegate :polymorphic_parents, to: RailsAdmin::AbstractModel
end
class StatementBuilder < RailsAdmin::AbstractModel::StatementBuilder
- protected
+ protected
def unary_operators
{
@@ -236,7 +236,7 @@ def unary_operators
}
end
- private
+ private
def range_filter(min, max)
if min && max
@@ -250,11 +250,11 @@ def range_filter(min, max)
def build_statement_for_type
case @type
- when :boolean then build_statement_for_boolean
- when :integer, :decimal, :float then build_statement_for_integer_decimal_or_float
- when :string, :text then build_statement_for_string_or_text
- when :enum then build_statement_for_enum
- when :belongs_to_association then build_statement_for_belongs_to_association
+ when :boolean then build_statement_for_boolean
+ when :integer, :decimal, :float then build_statement_for_integer_decimal_or_float
+ when :string, :text then build_statement_for_string_or_text
+ when :enum then build_statement_for_enum
+ when :belongs_to_association then build_statement_for_belongs_to_association
end
end
@@ -299,7 +299,7 @@ def ar_adapter
end
def like_operator
- ar_adapter == "postgresql" ? 'ILIKE' : 'LIKE'
+ ar_adapter == 'postgresql' ? 'ILIKE' : 'LIKE'
end
end
end
View
4 lib/rails_admin/adapters/active_record/abstract_object.rb
@@ -19,12 +19,12 @@ def set_attributes(attributes)
object.assign_attributes(attributes)
end
- def save(options = { :validate => true })
+ def save(options = {validate: true})
object.save(options)
end
def method_missing(name, *args, &block)
- self.object.send(name, *args, &block)
+ object.send(name, *args, &block)
end
end
end
View
206 lib/rails_admin/adapters/mongoid.rb
@@ -6,40 +6,37 @@ module RailsAdmin
module Adapters
module Mongoid
STRING_TYPE_COLUMN_NAMES = [:name, :title, :subject]
- DISABLED_COLUMN_TYPES = ['Range', 'Moped::BSON::Binary', "BSON::Binary", "Mongoid::Geospatial::Point"]
+ DISABLED_COLUMN_TYPES = ['Range', 'Moped::BSON::Binary', 'BSON::Binary', 'Mongoid::Geospatial::Point']
ObjectId = defined?(Moped::BSON) ? Moped::BSON::ObjectId : BSON::ObjectId
-
def new(params = {})
AbstractObject.new(model.new)
end
def get(id)
- begin
- AbstractObject.new(model.find(id))
- rescue => e
- raise e if %w[
- BSON::InvalidObjectId
- Mongoid::Errors::DocumentNotFound
- Mongoid::Errors::InvalidFind
- Moped::Errors::InvalidObjectId
- ].exclude?(e.class.to_s)
- end
+ AbstractObject.new(model.find(id))
+ rescue => e
+ raise e if %w[
+ BSON::InvalidObjectId
+ Mongoid::Errors::DocumentNotFound
+ Mongoid::Errors::InvalidFind
+ Moped::Errors::InvalidObjectId
+ ].exclude?(e.class.to_s)
end
def scoped
model.scoped
end
- def first(options = {},scope=nil)
+ def first(options = {}, scope = nil)
all(options, scope).first
end
- def all(options = {},scope=nil)
- scope ||= self.scoped
+ def all(options = {}, scope = nil)
+ scope ||= scoped
scope = scope.includes(*options[:include]) if options[:include]
scope = scope.limit(options[:limit]) if options[:limit]
- scope = scope.any_in(:_id => options[:bulk_ids]) if options[:bulk_ids]
+ scope = scope.any_in(_id: options[:bulk_ids]) if options[:bulk_ids]
scope = scope.where(query_conditions(options[:query])) if options[:query]
scope = scope.where(filter_conditions(options[:filters])) if options[:filters]
if options[:page] && options[:per]
@@ -49,12 +46,12 @@ def all(options = {},scope=nil)
scope
end
- def count(options = {},scope=nil)
- all(options.merge({:limit => false, :page => false}), scope).count
+ def count(options = {}, scope = nil)
+ all(options.merge(limit: false, page: false), scope).count
end
def destroy(objects)
- Array.wrap(objects).each &:destroy
+ Array.wrap(objects).each(&:destroy)
end
def primary_key
@@ -62,14 +59,14 @@ def primary_key
end
def associations
- model.relations.values.map do |association|
+ model.relations.values.collect do |association|
Association.new(association, model).to_options_hash
end
end
def properties
- fields = model.fields.reject{|name, field| DISABLED_COLUMN_TYPES.include?(field.type.to_s) }
- fields.map do |name,field|
+ fields = model.fields.reject { |name, field| DISABLED_COLUMN_TYPES.include?(field.type.to_s) }
+ fields.collect do |name, field|
{
:name => field.name.to_sym,
:length => nil,
@@ -89,7 +86,7 @@ def encoding
end
def embedded?
- @embedded ||= !!model.relations.values.find{|a| a.macro.to_sym == :embedded_in }
+ @embedded ||= !!model.relations.values.detect { |a| a.macro.to_sym == :embedded_in }
end
def cyclic?
@@ -100,7 +97,7 @@ def adapter_supports_joins?
false
end
- private
+ private
def build_statement(column, type, value, operator)
StatementBuilder.new(column, type, value, operator).to_statement
@@ -128,7 +125,7 @@ def query_conditions(query, fields = config.list.fields.select(&:queryable?))
end
if statements.any?
- { '$or' => statements }
+ {'$or' => statements}
else
{}
end
@@ -141,12 +138,12 @@ def filter_conditions(filters, fields = config.list.fields.select(&:filterable?)
filters.each_pair do |field_name, filters_dump|
filters_dump.each do |_, filter_dump|
- field = fields.find{|f| f.name.to_s == field_name}
+ field = fields.detect { |f| f.name.to_s == field_name }
next unless field
conditions_per_collection = make_field_conditions(field, filter_dump[:v], (filter_dump[:o] || 'default'))
field_statements = make_condition_for_current_collection(field, conditions_per_collection)
if field_statements.many?
- statements << { '$or' => field_statements }
+ statements << {'$or' => field_statements}
elsif field_statements.any?
statements << field_statements.first
end
@@ -154,7 +151,7 @@ def filter_conditions(filters, fields = config.list.fields.select(&:filterable?)
end
if statements.any?
- { '$and' => statements }
+ {'$and' => statements}
else
{}
end
@@ -162,47 +159,44 @@ def filter_conditions(filters, fields = config.list.fields.select(&:filterable?)
def type_lookup(name, field)
{
- "Array" => { :type => :serialized },
- "BigDecimal" => { :type => :decimal },
- "Mongoid::Boolean" => { :type => :boolean },
- "Boolean" => { :type => :boolean },
- "BSON::ObjectId" => { :type => :bson_object_id, :serial? => (name == primary_key) },
- "Moped::BSON::ObjectId" => { :type => :bson_object_id, :serial? => (name == primary_key) },
- "Date" => { :type => :date },
- "DateTime" => { :type => :datetime },
- "ActiveSupport::TimeWithZone" => { :type => :datetime },
- "Float" => { :type => :float },
- "Hash" => { :type => :serialized },
- "Money" => { :type => :serialized },
- "Integer" => { :type => :integer },
- "Object" => (
- if associations.find{|a| a[:type] == :belongs_to && a[:foreign_key] == name.to_sym}
- { :type => :bson_object_id }
+ 'Array' => {type: :serialized},
+ 'BigDecimal' => {type: :decimal},
+ 'Mongoid::Boolean' => {type: :boolean},
+ 'Boolean' => {type: :boolean},
+ 'BSON::ObjectId' => {:type => :bson_object_id, :serial? => (name == primary_key)},
+ 'Moped::BSON::ObjectId' => {:type => :bson_object_id, :serial? => (name == primary_key)},
+ 'Date' => {type: :date},
+ 'DateTime' => {type: :datetime},
+ 'ActiveSupport::TimeWithZone' => {type: :datetime},
+ 'Float' => {type: :float},
+ 'Hash' => {type: :serialized},
+ 'Money' => {type: :serialized},
+ 'Integer' => {type: :integer},
+ 'Object' => (
+ if associations.detect { |a| a[:type] == :belongs_to && a[:foreign_key] == name.to_sym }
+ {type: :bson_object_id}
else
- { :type => :string, :length => 255 }
+ {type: :string, length: 255}
end
),
- "String" => (
+ 'String' => (
if (length = length_validation_lookup(name)) && length < 256
- { :type => :string, :length => length }
+ {type: :string, length: length}
elsif STRING_TYPE_COLUMN_NAMES.include?(name.to_sym)
- { :type => :string, :length => 255 }
+ {type: :string, length: 255}
else
- { :type => :text }
+ {type: :text}
end
),
- "Symbol" => { :type => :string, :length => 255 },
- "Time" => { :type => :datetime },
- }[field.type.to_s] or raise "Type #{field.type.to_s} for field :#{name} in #{model.inspect} not supported"
+ 'Symbol' => {type: :string, length: 255},
+ 'Time' => {type: :datetime},
+ }[field.type.to_s] || fail("Type #{field.type.to_s} for field :#{name} in #{model.inspect} not supported")
end
def length_validation_lookup(name)
- shortest = model.validators.select do |validator|
- validator.respond_to?(:attributes) &&
- validator.attributes.include?(name.to_sym) &&
- validator.kind == :length &&
- validator.options[:maximum]
- end.min{|a, b| a.options[:maximum] <=> b.options[:maximum] }
+ shortest = model.validators.select { |validator| validator.respond_to?(:attributes) && validator.attributes.include?(name.to_sym) && validator.kind == :length && validator.options[:maximum] }.min do |a, b|
+ a.options[:maximum] <=> b.options[:maximum]
+ end
shortest && shortest.options[:maximum]
end
@@ -217,7 +211,7 @@ def parse_collection_name(column)
end
def make_condition_for_current_collection(target_field, conditions_per_collection)
- result =[]
+ result = []
conditions_per_collection.each do |collection_name, conditions|
if collection_name == table_name
# conditions referring current model column are passed directly
@@ -231,14 +225,14 @@ def make_condition_for_current_collection(target_field, conditions_per_collectio
end
def perform_search_on_associated_collection(field_name, conditions)
- target_association = associations.find{|a| a[:name] == field_name }
+ target_association = associations.detect { |a| a[:name] == field_name }
return [] unless target_association
model = target_association[:model_proc].call
case target_association[:type]
when :belongs_to, :has_and_belongs_to_many
- [{ target_association[:foreign_key].to_s => { '$in' => model.where('$or' => conditions).all.map{|r| r.send(target_association[:primary_key_proc].call)} }}]
+ [{target_association[:foreign_key].to_s => {'$in' => model.where('$or' => conditions).all.collect { |r| r.send(target_association[:primary_key_proc].call) }}}]
when :has_many
- [{ target_association[:primary_key_proc].call.to_s => { '$in' => model.where('$or' => conditions).all.map{|r| r.send(target_association[:foreign_key])} }}]
+ [{target_association[:primary_key_proc].call.to_s => {'$in' => model.where('$or' => conditions).all.collect { |r| r.send(target_association[:foreign_key]) }}}]
end
end
@@ -249,7 +243,7 @@ def sort_by(options, scope)
when String
field_name, collection_name = options[:sort].split('.').reverse
if collection_name && collection_name != table_name
- raise "sorting by associated model column is not supported in Non-Relational databases"
+ fail('sorting by associated model column is not supported in Non-Relational databases')
end
when Symbol
field_name = options[:sort].to_s
@@ -261,7 +255,8 @@ def sort_by(options, scope)
end
end
- private
+ private
+
class Association
attr_reader :association, :model
def initialize(association, model)
@@ -272,23 +267,23 @@ def initialize(association, model)
def to_options_hash
{
- :name => name.to_sym,
- :pretty_name => display_name,
- :type => type_lookup,
- :model_proc => Proc.new { model_proc_lookup },
- :primary_key_proc => Proc.new { primary_key_lookup },
- :foreign_key => foreign_key_lookup,
- :foreign_type => foreign_type_lookup,
- :foreign_inverse_of => foreign_inverse_of_lookup,
- :as => as_lookup,
- :polymorphic => polymorphic_lookup,
- :inverse_of => inverse_of_lookup,
- :read_only => nil,
- :nested_form => nested_attributes_options_lookup
+ name: name.to_sym,
+ pretty_name: display_name,
+ type: type_lookup,
+ model_proc: proc { model_proc_lookup },
+ primary_key_proc: proc { primary_key_lookup },
+ foreign_key: foreign_key_lookup,
+ foreign_type: foreign_type_lookup,
+ foreign_inverse_of: foreign_inverse_of_lookup,
+ as: as_lookup,
+ polymorphic: polymorphic_lookup,
+ inverse_of: inverse_of_lookup,
+ read_only: nil,
+ nested_form: nested_attributes_options_lookup
}
end
- private
+ private
def display_name
name.to_s.tr('_', ' ').capitalize
@@ -317,7 +312,7 @@ def foreign_inverse_of_lookup
def nested_attributes_options_lookup
nested = model_nested_attributes_options.try { |o| o[name.to_sym] }
if !nested && [:embeds_one, :embeds_many].include?(macro.to_sym) && !association.cyclic
- raise <<-MSG.gsub(/^\s+/, '')
+ fail <<-MSG.gsub(/^\s+/, '')
Embbeded association without accepts_nested_attributes_for can't be handled by RailsAdmin,
because embedded model doesn't have top-level access.
Please add `accepts_nested_attributes_for :#{association.name}' line to `#{model.to_s}' model.
@@ -363,50 +358,50 @@ def type_lookup
when :has_and_belongs_to_many, :references_and_referenced_in_many
:has_and_belongs_to_many
else
- raise "Unknown association type: #{macro.inspect}"
+ fail("Unknown association type: #{macro.inspect}")
end
end
delegate :foreign_key, :macro, :name, :options, :scope, :polymorphic?,
:klass, :inverse_of, :inverse_type, :as,
- :to => :association, :prefix => false
- delegate :name, :nested_attributes_options, :to => :model, :prefix => true
- delegate :polymorphic_parents, :to => RailsAdmin::AbstractModel
+ to: :association, prefix: false
+ delegate :name, :nested_attributes_options, to: :model, prefix: true
+ delegate :polymorphic_parents, to: RailsAdmin::AbstractModel
end
class StatementBuilder < RailsAdmin::AbstractModel::StatementBuilder
- protected
+ protected
def unary_operators
{
- '_blank' => { @column => {'$in' => [nil, '']} },
- '_present' => { @column => {'$nin' => [nil, '']} },
- '_null' => { @column => nil },
- '_not_null' => { @column => {'$ne' => nil} },
- '_empty' => { @column => '' },
- '_not_empty' => { @column => {'$ne' => ''} }
+ '_blank' => {@column => {'$in' => [nil, '']}},
+ '_present' => {@column => {'$nin' => [nil, '']}},
+ '_null' => {@column => nil},
+ '_not_null' => {@column => {'$ne' => nil}},
+ '_empty' => {@column => ''},
+ '_not_empty' => {@column => {'$ne' => ''}}
}
end
- private
+ private
def build_statement_for_type
case @type
- when :boolean then build_statement_for_boolean
- when :integer, :decimal, :float then build_statement_for_integer_decimal_or_float
- when :string, :text then build_statement_for_string_or_text
- when :enum then build_statement_for_enum
- when :belongs_to_association, :bson_object_id then build_statement_for_belongs_to_association_or_bson_object_id
+ when :boolean then build_statement_for_boolean
+ when :integer, :decimal, :float then build_statement_for_integer_decimal_or_float
+ when :string, :text then build_statement_for_string_or_text
+ when :enum then build_statement_for_enum
+ when :belongs_to_association, :bson_object_id then build_statement_for_belongs_to_association_or_bson_object_id
end
end
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)
+ return {@column => false} if %w[false f 0].include?(@value)
+ return {@column => true} if %w[true t 1].include?(@value)
end
def column_for_value(value)
- { @column => value }
+ {@column => value}
end
def build_statement_for_string_or_text
@@ -423,33 +418,32 @@ def build_statement_for_string_or_text
else
return
end
- { @column => @value }
+ {@column => @value}
end
def build_statement_for_enum
return if @value.blank?
- { @column => { "$in" => Array.wrap(@value) } }
+ {@column => {'$in' => Array.wrap(@value)}}
end
def build_statement_for_belongs_to_association_or_bson_object_id
object_id = (object_id_from_string(@value) rescue nil)
- { @column => object_id } if object_id
+ {@column => object_id} if object_id
end
def range_filter(min, max)
if min && max
- { @column => { '$gte' => min, '$lte' => max } }
+ {@column => {'$gte' => min, '$lte' => max}}
elsif min
- { @column => { '$gte' => min } }
+ {@column => {'$gte' => min}}
elsif max
- { @column => { '$lte' => max } }
+ {@column => {'$lte' => max}}
end
end
def object_id_from_string(str)
ObjectId.from_string(str)
end
-
end
end
end
View
2  lib/rails_admin/adapters/mongoid/abstract_object.rb
@@ -19,7 +19,7 @@ def #{name.to_s.singularize}_ids=(item_ids)
item.update_attribute('#{association.foreign_key}', id)
end
end
- super __items__.map &:id
+ super __items__.map(&:id)
end
RUBY
elsif [:has_one, :references_one].include? association.macro
View
10 lib/rails_admin/adapters/mongoid/extension.rb
@@ -16,14 +16,14 @@ def rails_admin(&block)
end