obitum-rails_admin 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +57 -0
- data/LICENSE.md +20 -0
- data/README.md +206 -0
- data/Rakefile +14 -0
- data/app/assets/images/rails_admin/aristo/images/bg_fallback.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/icon_sprite.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/progress_bar.gif +0 -0
- data/app/assets/images/rails_admin/aristo/images/slider_handles.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/images/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
- data/app/assets/images/rails_admin/bullet_black.png +0 -0
- data/app/assets/images/rails_admin/bullet_white.png +0 -0
- data/app/assets/images/rails_admin/calendar.png +0 -0
- data/app/assets/images/rails_admin/clock.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_background.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hex.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_h.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_s.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_indic.gif +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_overlay.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_g.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_r.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_select.gif +0 -0
- data/app/assets/images/rails_admin/colorpicker/colorpicker_submit.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_background.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hex.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hsb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hsb_h.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_hsb_s.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_indic.gif +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_rgb_b.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_rgb_g.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_rgb_r.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/custom_submit.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/select.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/select2.png +0 -0
- data/app/assets/images/rails_admin/colorpicker/slider.png +0 -0
- data/app/assets/images/rails_admin/logo.png +0 -0
- data/app/assets/images/rails_admin/magnifier.png +0 -0
- data/app/assets/images/rails_admin/multiselect/icon_sprite.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-dark.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-light.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-dark.png +0 -0
- data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-light.png +0 -0
- data/app/assets/javascripts/rails_admin/custom/ui.js +12 -0
- data/app/assets/javascripts/rails_admin/jquery-ui-1.8.16.custom.js +5271 -0
- data/app/assets/javascripts/rails_admin/jquery.colorpicker.js +484 -0
- data/app/assets/javascripts/rails_admin/jquery.pjax.js +266 -0
- data/app/assets/javascripts/rails_admin/jquery.ui.timepicker.js +1219 -0
- data/app/assets/javascripts/rails_admin/jquery_nested_form.js +58 -0
- data/app/assets/javascripts/rails_admin/ra.datetimepicker.js +67 -0
- data/app/assets/javascripts/rails_admin/ra.filter-box.js +120 -0
- data/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js +280 -0
- data/app/assets/javascripts/rails_admin/ra.filtering-select.js +181 -0
- data/app/assets/javascripts/rails_admin/ra.remote-form.js +148 -0
- data/app/assets/javascripts/rails_admin/rails_admin.js.erb +19 -0
- data/app/assets/javascripts/rails_admin/themes/default/ui.js +12 -0
- data/app/assets/javascripts/rails_admin/ui.js.coffee +33 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/bg_fallback.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/icon_sprite.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/progress_bar.gif +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/slider_handles.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
- data/app/assets/stylesheets/rails_admin/aristo/jquery-ui-1.8.7.custom.css.scss +733 -0
- data/app/assets/stylesheets/rails_admin/base/README +2 -0
- data/app/assets/stylesheets/rails_admin/base/mixins.css.scss +1 -0
- data/app/assets/stylesheets/rails_admin/base/theming.css.scss +145 -0
- data/app/assets/stylesheets/rails_admin/base/variables.css.scss +1 -0
- data/app/assets/stylesheets/rails_admin/custom/mixins.css.scss +12 -0
- data/app/assets/stylesheets/rails_admin/custom/theming.css.scss +13 -0
- data/app/assets/stylesheets/rails_admin/custom/variables.css.scss +15 -0
- data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +41 -0
- data/app/assets/stylesheets/rails_admin/jquery.colorpicker.css.scss +180 -0
- data/app/assets/stylesheets/rails_admin/jquery.ui.timepicker.css.scss +53 -0
- data/app/assets/stylesheets/rails_admin/ra.calendar-additions.css.scss +25 -0
- data/app/assets/stylesheets/rails_admin/ra.filtering-multiselect.css.scss +85 -0
- data/app/assets/stylesheets/rails_admin/rails_admin.css +4 -0
- data/app/assets/stylesheets/rails_admin/themes/default/mixins.css.scss +8 -0
- data/app/assets/stylesheets/rails_admin/themes/default/theming.css.scss +11 -0
- data/app/assets/stylesheets/rails_admin/themes/default/variables.css.scss +12 -0
- data/app/controllers/rails_admin/application_controller.rb +87 -0
- data/app/controllers/rails_admin/main_controller.rb +148 -0
- data/app/helpers/rails_admin/application_helper.rb +97 -0
- data/app/helpers/rails_admin/form_builder.rb +106 -0
- data/app/helpers/rails_admin/main_helper.rb +36 -0
- data/app/views/kaminari/twitter-bootstrap/_gap.html.haml +2 -0
- data/app/views/kaminari/twitter-bootstrap/_next_page.html.haml +4 -0
- data/app/views/kaminari/twitter-bootstrap/_page.html.haml +4 -0
- data/app/views/kaminari/twitter-bootstrap/_paginator.html.haml +10 -0
- data/app/views/kaminari/twitter-bootstrap/_prev_page.html.haml +4 -0
- data/app/views/layouts/rails_admin/_navigation.html.haml +17 -0
- data/app/views/layouts/rails_admin/_secondary_navigation.html.haml +11 -0
- data/app/views/layouts/rails_admin/application.html.haml +39 -0
- data/app/views/rails_admin/main/_dashboard_history.html.haml +10 -0
- data/app/views/rails_admin/main/_delete_notice.html.haml +19 -0
- data/app/views/rails_admin/main/_form_colorpicker.html.haml +23 -0
- data/app/views/rails_admin/main/_form_datetime.html.haml +4 -0
- data/app/views/rails_admin/main/_form_enumeration.html.haml +4 -0
- data/app/views/rails_admin/main/_form_field.html.haml +1 -0
- data/app/views/rails_admin/main/_form_file_upload.html.haml +17 -0
- data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +57 -0
- data/app/views/rails_admin/main/_form_filtering_select.html.haml +46 -0
- data/app/views/rails_admin/main/_form_nested_many.html.haml +6 -0
- data/app/views/rails_admin/main/_form_nested_one.html.haml +6 -0
- data/app/views/rails_admin/main/_form_polymorphic_association.html.haml +34 -0
- data/app/views/rails_admin/main/_form_text.html.haml +9 -0
- data/app/views/rails_admin/main/_submit_buttons.html.haml +13 -0
- data/app/views/rails_admin/main/bulk_delete.html.haml +7 -0
- data/app/views/rails_admin/main/dashboard.html.haml +31 -0
- data/app/views/rails_admin/main/delete.html.haml +14 -0
- data/app/views/rails_admin/main/edit.html.haml +2 -0
- data/app/views/rails_admin/main/export.html.haml +71 -0
- data/app/views/rails_admin/main/history.html.haml +42 -0
- data/app/views/rails_admin/main/index.html.haml +123 -0
- data/app/views/rails_admin/main/new.html.haml +2 -0
- data/app/views/rails_admin/main/show.html.haml +14 -0
- data/config/initializers/active_record_extensions.rb +19 -0
- data/config/initializers/devise_patch.rb +9 -0
- data/config/initializers/haml.rb +3 -0
- data/config/locales/rails_admin.en.yml +129 -0
- data/config/routes.rb +12 -0
- data/lib/generators/rails_admin/install_generator.rb +84 -0
- data/lib/generators/rails_admin/templates/drop.rb +18 -0
- data/lib/generators/rails_admin/templates/initializer.erb +101 -0
- data/lib/generators/rails_admin/templates/migration.rb +18 -0
- data/lib/generators/rails_admin/uninstall_generator.rb +22 -0
- data/lib/generators/rails_admin/utils.rb +30 -0
- data/lib/rails_admin.rb +39 -0
- data/lib/rails_admin/abstract_model.rb +73 -0
- data/lib/rails_admin/abstract_object.rb +28 -0
- data/lib/rails_admin/adapters/active_record.rb +347 -0
- data/lib/rails_admin/config.rb +293 -0
- data/lib/rails_admin/config/actions.rb +121 -0
- data/lib/rails_admin/config/actions/base.rb +105 -0
- data/lib/rails_admin/config/actions/bulk_delete.rb +56 -0
- data/lib/rails_admin/config/actions/dashboard.rb +40 -0
- data/lib/rails_admin/config/actions/delete.rb +50 -0
- data/lib/rails_admin/config/actions/edit.rb +52 -0
- data/lib/rails_admin/config/actions/export.rb +37 -0
- data/lib/rails_admin/config/actions/history_index.rb +34 -0
- data/lib/rails_admin/config/actions/history_show.rb +34 -0
- data/lib/rails_admin/config/actions/index.rb +73 -0
- data/lib/rails_admin/config/actions/new.rb +60 -0
- data/lib/rails_admin/config/actions/show.rb +27 -0
- data/lib/rails_admin/config/actions/show_in_app.rb +23 -0
- data/lib/rails_admin/config/base.rb +111 -0
- data/lib/rails_admin/config/fields.rb +97 -0
- data/lib/rails_admin/config/fields/association.rb +115 -0
- data/lib/rails_admin/config/fields/base.rb +274 -0
- data/lib/rails_admin/config/fields/factories/carrierwave.rb +12 -0
- data/lib/rails_admin/config/fields/factories/devise.rb +30 -0
- data/lib/rails_admin/config/fields/factories/dragonfly.rb +21 -0
- data/lib/rails_admin/config/fields/factories/enum.rb +11 -0
- data/lib/rails_admin/config/fields/factories/paperclip.rb +27 -0
- data/lib/rails_admin/config/fields/factories/password.rb +17 -0
- data/lib/rails_admin/config/fields/group.rb +65 -0
- data/lib/rails_admin/config/fields/groupable.rb +25 -0
- data/lib/rails_admin/config/fields/types.rb +26 -0
- data/lib/rails_admin/config/fields/types/all.rb +23 -0
- data/lib/rails_admin/config/fields/types/belongs_to_association.rb +43 -0
- data/lib/rails_admin/config/fields/types/boolean.rb +29 -0
- data/lib/rails_admin/config/fields/types/carrierwave.rb +40 -0
- data/lib/rails_admin/config/fields/types/color.rb +37 -0
- data/lib/rails_admin/config/fields/types/date.rb +24 -0
- data/lib/rails_admin/config/fields/types/datetime.rb +165 -0
- data/lib/rails_admin/config/fields/types/decimal.rb +14 -0
- data/lib/rails_admin/config/fields/types/dragonfly.rb +59 -0
- data/lib/rails_admin/config/fields/types/enum.rb +35 -0
- data/lib/rails_admin/config/fields/types/file_upload.rb +65 -0
- data/lib/rails_admin/config/fields/types/float.rb +14 -0
- data/lib/rails_admin/config/fields/types/has_and_belongs_to_many_association.rb +14 -0
- data/lib/rails_admin/config/fields/types/has_many_association.rb +37 -0
- data/lib/rails_admin/config/fields/types/has_one_association.rb +35 -0
- data/lib/rails_admin/config/fields/types/hidden.rb +19 -0
- data/lib/rails_admin/config/fields/types/integer.rb +20 -0
- data/lib/rails_admin/config/fields/types/paperclip.rb +46 -0
- data/lib/rails_admin/config/fields/types/password.rb +42 -0
- data/lib/rails_admin/config/fields/types/polymorphic_association.rb +76 -0
- data/lib/rails_admin/config/fields/types/string.rb +43 -0
- data/lib/rails_admin/config/fields/types/text.rb +38 -0
- data/lib/rails_admin/config/fields/types/time.rb +36 -0
- data/lib/rails_admin/config/fields/types/timestamp.rb +18 -0
- data/lib/rails_admin/config/has_fields.rb +135 -0
- data/lib/rails_admin/config/has_groups.rb +23 -0
- data/lib/rails_admin/config/hideable.rb +28 -0
- data/lib/rails_admin/config/model.rb +82 -0
- data/lib/rails_admin/config/proxy.rb +40 -0
- data/lib/rails_admin/config/sections.rb +38 -0
- data/lib/rails_admin/config/sections/base.rb +19 -0
- data/lib/rails_admin/config/sections/create.rb +11 -0
- data/lib/rails_admin/config/sections/edit.rb +11 -0
- data/lib/rails_admin/config/sections/export.rb +11 -0
- data/lib/rails_admin/config/sections/list.rb +27 -0
- data/lib/rails_admin/config/sections/nested.rb +10 -0
- data/lib/rails_admin/config/sections/show.rb +10 -0
- data/lib/rails_admin/config/sections/update.rb +10 -0
- data/lib/rails_admin/engine.rb +21 -0
- data/lib/rails_admin/extension.rb +29 -0
- data/lib/rails_admin/extensions/cancan.rb +5 -0
- data/lib/rails_admin/extensions/cancan/authorization_adapter.rb +59 -0
- data/lib/rails_admin/extensions/history.rb +5 -0
- data/lib/rails_admin/extensions/history/auditing_adapter.rb +37 -0
- data/lib/rails_admin/extensions/history/history.rb +68 -0
- data/lib/rails_admin/extensions/paper_trail.rb +5 -0
- data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +92 -0
- data/lib/rails_admin/generic_support.rb +18 -0
- data/lib/rails_admin/i18n_support.rb +43 -0
- data/lib/rails_admin/support/core_extensions.rb +44 -0
- data/lib/rails_admin/support/csv_converter.rb +109 -0
- data/lib/rails_admin/version.rb +6 -0
- data/lib/tasks/prepare_ci_env.rake +27 -0
- data/lib/tasks/rails_admin.rake +18 -0
- data/spec/ci.sh +2 -0
- data/spec/controllers/application_controller_spec.rb +30 -0
- data/spec/controllers/main_controller_spec.rb +114 -0
- data/spec/database_helpers.rb +15 -0
- data/spec/dummy_app/Gemfile +53 -0
- data/spec/dummy_app/Rakefile +7 -0
- data/spec/dummy_app/app/controllers/application_controller.rb +3 -0
- data/spec/dummy_app/app/controllers/players_controller.rb +5 -0
- data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_app/app/locales/models.en.yml +16 -0
- data/spec/dummy_app/app/models/abstract.rb +5 -0
- data/spec/dummy_app/app/models/ball.rb +8 -0
- data/spec/dummy_app/app/models/category.rb +3 -0
- data/spec/dummy_app/app/models/cms.rb +5 -0
- data/spec/dummy_app/app/models/cms/basic_page.rb +7 -0
- data/spec/dummy_app/app/models/cms/unscoped_page.rb +3 -0
- data/spec/dummy_app/app/models/comment.rb +3 -0
- data/spec/dummy_app/app/models/division.rb +8 -0
- data/spec/dummy_app/app/models/draft.rb +11 -0
- data/spec/dummy_app/app/models/fan.rb +5 -0
- data/spec/dummy_app/app/models/field_test.rb +20 -0
- data/spec/dummy_app/app/models/hardball.rb +2 -0
- data/spec/dummy_app/app/models/league.rb +10 -0
- data/spec/dummy_app/app/models/nested_field_test.rb +3 -0
- data/spec/dummy_app/app/models/player.rb +23 -0
- data/spec/dummy_app/app/models/rel_test.rb +6 -0
- data/spec/dummy_app/app/models/team.rb +25 -0
- data/spec/dummy_app/app/models/user.rb +21 -0
- data/spec/dummy_app/app/uploaders/carrierwave_uploader.rb +53 -0
- data/spec/dummy_app/app/views/layouts/application.html.erb +13 -0
- data/spec/dummy_app/app/views/players/show.html.haml +1 -0
- data/spec/dummy_app/config.ru +4 -0
- data/spec/dummy_app/config/application.rb +47 -0
- data/spec/dummy_app/config/boot.rb +6 -0
- data/spec/dummy_app/config/database.yml +22 -0
- data/spec/dummy_app/config/environment.rb +5 -0
- data/spec/dummy_app/config/environments/development.rb +27 -0
- data/spec/dummy_app/config/environments/production.rb +51 -0
- data/spec/dummy_app/config/environments/test.rb +39 -0
- data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_app/config/initializers/devise.rb +142 -0
- data/spec/dummy_app/config/initializers/inflections.rb +10 -0
- data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
- data/spec/dummy_app/config/initializers/quiet_assets.rb +10 -0
- data/spec/dummy_app/config/initializers/rails_admin.rb +11 -0
- data/spec/dummy_app/config/initializers/secret_token.rb +7 -0
- data/spec/dummy_app/config/initializers/session_store.rb +8 -0
- data/spec/dummy_app/config/routes.rb +10 -0
- data/spec/dummy_app/db/migrate/00000000000001_create_divisions_migration.rb +13 -0
- data/spec/dummy_app/db/migrate/00000000000002_create_drafts_migration.rb +19 -0
- data/spec/dummy_app/db/migrate/00000000000003_create_leagues_migration.rb +12 -0
- data/spec/dummy_app/db/migrate/00000000000004_create_players_migration.rb +20 -0
- data/spec/dummy_app/db/migrate/00000000000005_create_teams_migration.rb +22 -0
- data/spec/dummy_app/db/migrate/00000000000006_devise_create_users.rb +19 -0
- data/spec/dummy_app/db/migrate/00000000000007_create_histories_table.rb +16 -0
- data/spec/dummy_app/db/migrate/00000000000008_create_fans_migration.rb +12 -0
- data/spec/dummy_app/db/migrate/00000000000009_create_fans_teams_migration.rb +11 -0
- data/spec/dummy_app/db/migrate/00000000000010_add_revenue_to_team_migration.rb +9 -0
- data/spec/dummy_app/db/migrate/00000000000011_add_suspended_to_player_migration.rb +9 -0
- data/spec/dummy_app/db/migrate/00000000000012_add_avatar_columns_to_user.rb +16 -0
- data/spec/dummy_app/db/migrate/00000000000013_add_roles_to_user.rb +9 -0
- data/spec/dummy_app/db/migrate/00000000000014_add_color_to_team_migration.rb +9 -0
- data/spec/dummy_app/db/migrate/20101223222233_create_rel_tests.rb +15 -0
- data/spec/dummy_app/db/migrate/20110103205808_create_comments.rb +15 -0
- data/spec/dummy_app/db/migrate/20110123042530_rename_histories_to_rails_admin_histories.rb +9 -0
- data/spec/dummy_app/db/migrate/20110224184303_create_field_tests.rb +22 -0
- data/spec/dummy_app/db/migrate/20110328193014_create_cms_basic_pages.rb +14 -0
- data/spec/dummy_app/db/migrate/20110329183136_remove_league_id_from_teams.rb +9 -0
- data/spec/dummy_app/db/migrate/20110607152842_add_format_to_field_test.rb +9 -0
- data/spec/dummy_app/db/migrate/20110714095433_create_balls.rb +12 -0
- data/spec/dummy_app/db/migrate/20110831090841_add_protected_field_and_restricted_field_to_field_tests.rb +6 -0
- data/spec/dummy_app/db/migrate/20110901131551_change_division_primary_key.rb +19 -0
- data/spec/dummy_app/db/migrate/20110901142530_rename_league_id_foreign_key_on_divisions.rb +5 -0
- data/spec/dummy_app/db/migrate/20110901150912_set_primary_key_not_null_for_divisions.rb +21 -0
- data/spec/dummy_app/db/migrate/20110901154834_change_length_for_rails_admin_histories.rb +9 -0
- data/spec/dummy_app/db/migrate/20111103174459_create_unscoped_pages.rb +9 -0
- data/spec/dummy_app/db/migrate/20111108143642_add_dragonfly_and_carrierwave_to_field_tests.rb +7 -0
- data/spec/dummy_app/db/migrate/20111115041025_add_type_to_balls.rb +5 -0
- data/spec/dummy_app/db/migrate/20111123092549_create_nested_field_tests.rb +10 -0
- data/spec/dummy_app/db/migrate/20111130075338_add_dragonfly_asset_name_to_field_tests.rb +5 -0
- data/spec/dummy_app/db/migrate/20111215083258_create_foo_bars.rb +8 -0
- data/spec/dummy_app/db/migrate/20120117151733_add_custom_field_to_teams.rb +5 -0
- data/spec/dummy_app/db/migrate/20120118122004_add_categories.rb +7 -0
- data/spec/dummy_app/db/seeds.rb +18 -0
- data/spec/dummy_app/foo/Gemfile +17 -0
- data/spec/dummy_app/foo/MIT-LICENSE +20 -0
- data/spec/dummy_app/foo/README.rdoc +3 -0
- data/spec/dummy_app/foo/Rakefile +39 -0
- data/spec/dummy_app/foo/app/assets/javascripts/foo/application.js +9 -0
- data/spec/dummy_app/foo/app/assets/stylesheets/foo/application.css +7 -0
- data/spec/dummy_app/foo/app/controllers/foo/application_controller.rb +4 -0
- data/spec/dummy_app/foo/app/helpers/foo/application_helper.rb +4 -0
- data/spec/dummy_app/foo/app/models/foo/bar.rb +4 -0
- data/spec/dummy_app/foo/app/views/layouts/foo/application.html.erb +14 -0
- data/spec/dummy_app/foo/config/routes.rb +2 -0
- data/spec/dummy_app/foo/foo.gemspec +23 -0
- data/spec/dummy_app/foo/lib/foo.rb +4 -0
- data/spec/dummy_app/foo/lib/foo/engine.rb +5 -0
- data/spec/dummy_app/foo/lib/foo/version.rb +3 -0
- data/spec/dummy_app/foo/lib/tasks/foo_tasks.rake +4 -0
- data/spec/dummy_app/foo/script/rails +6 -0
- data/spec/dummy_app/foo/test/dummy/Rakefile +7 -0
- data/spec/dummy_app/foo/test/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy_app/foo/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy_app/foo/test/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy_app/foo/test/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_app/foo/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy_app/foo/test/dummy/config.ru +4 -0
- data/spec/dummy_app/foo/test/dummy/config/application.rb +45 -0
- data/spec/dummy_app/foo/test/dummy/config/boot.rb +10 -0
- data/spec/dummy_app/foo/test/dummy/config/database.yml +25 -0
- data/spec/dummy_app/foo/test/dummy/config/environment.rb +5 -0
- data/spec/dummy_app/foo/test/dummy/config/environments/development.rb +30 -0
- data/spec/dummy_app/foo/test/dummy/config/environments/production.rb +60 -0
- data/spec/dummy_app/foo/test/dummy/config/environments/test.rb +39 -0
- data/spec/dummy_app/foo/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_app/foo/test/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy_app/foo/test/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy_app/foo/test/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy_app/foo/test/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy_app/foo/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy_app/foo/test/dummy/config/locales/en.yml +5 -0
- data/spec/dummy_app/foo/test/dummy/config/routes.rb +4 -0
- data/spec/dummy_app/foo/test/dummy/db/schema.rb +21 -0
- data/spec/dummy_app/foo/test/dummy/public/404.html +26 -0
- data/spec/dummy_app/foo/test/dummy/public/422.html +26 -0
- data/spec/dummy_app/foo/test/dummy/public/500.html +26 -0
- data/spec/dummy_app/foo/test/dummy/public/favicon.ico +0 -0
- data/spec/dummy_app/foo/test/dummy/script/rails +6 -0
- data/spec/dummy_app/foo/test/fixtures/foo/bars.yml +11 -0
- data/spec/dummy_app/foo/test/foo_test.rb +7 -0
- data/spec/dummy_app/foo/test/integration/navigation_test.rb +10 -0
- data/spec/dummy_app/foo/test/test_helper.rb +10 -0
- data/spec/dummy_app/foo/test/unit/foo/bar_test.rb +9 -0
- data/spec/dummy_app/public/404.html +0 -0
- data/spec/dummy_app/public/favicon.ico +0 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/24/10_36_27_888_Pensive_Parakeet.jpg +0 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/24/10_36_27_888_Pensive_Parakeet.jpg.meta +1 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/30/08_54_39_906_Costa_Rican_Frog.jpg +0 -0
- data/spec/dummy_app/public/system/dragonfly/development/2011/11/30/08_54_39_906_Costa_Rican_Frog.jpg.meta +1 -0
- data/spec/dummy_app/public/system/paperclip_assets/1/original/Boston City Flow.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/1/thumb/Boston City Flow.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/3/original/Costa Rican Frog.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/3/thumb/Costa Rican Frog.jpg +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/6/original/liste-electorale.pdf +0 -0
- data/spec/dummy_app/public/system/paperclip_assets/6/thumb/liste-electorale.pdf +148 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/3/Boston_City_Flow.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/3/thumb_Boston_City_Flow.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/4/Costa_Rican_Frog.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/4/thumb_Costa_Rican_Frog.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/6/Pensive_Parakeet.jpg +0 -0
- data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/6/thumb_Pensive_Parakeet.jpg +0 -0
- data/spec/dummy_app/script/rails +6 -0
- data/spec/factories.rb +66 -0
- data/spec/generator_helpers.rb +30 -0
- data/spec/generators/install_generator_spec.rb +85 -0
- data/spec/generators/uninstall_generator_spec.rb +35 -0
- data/spec/helpers/application_helper_spec.rb +212 -0
- data/spec/lib/abstract_object_spec.rb +119 -0
- data/spec/lib/custom_field.rb +7 -0
- data/spec/lib/rails_admin_spec.rb +301 -0
- data/spec/requests/actions.rb +161 -0
- data/spec/requests/authorization/cancan_spec.rb +350 -0
- data/spec/requests/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +25 -0
- data/spec/requests/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +57 -0
- data/spec/requests/basic/create/rails_admin_basic_create_spec.rb +143 -0
- data/spec/requests/basic/create/rails_admin_namespaced_model_create_spec.rb +39 -0
- data/spec/requests/basic/delete/rails_admin_basic_delete_spec.rb +27 -0
- data/spec/requests/basic/destroy/rails_admin_basic_destroy_spec.rb +56 -0
- data/spec/requests/basic/edit/rails_admin_basic_edit_spec.rb +109 -0
- data/spec/requests/basic/export/rails_admin_basic_export_spec.rb +87 -0
- data/spec/requests/basic/list/rails_admin_basic_list_spec.rb +417 -0
- data/spec/requests/basic/new/rails_admin_basic_new_spec.rb +74 -0
- data/spec/requests/basic/new/rails_admin_namespaced_model_new_spec.rb +31 -0
- data/spec/requests/basic/show/rails_admin_basic_show_spec.rb +92 -0
- data/spec/requests/basic/update/rails_admin_basic_update_spec.rb +191 -0
- data/spec/requests/config/edit/rails_admin_config_edit_spec.rb +913 -0
- data/spec/requests/config/list/rails_admin_config_list_spec.rb +509 -0
- data/spec/requests/config/navigation/rails_admin_config_navigation_spec.rb +107 -0
- data/spec/requests/config/rails_admin_config_spec.rb +227 -0
- data/spec/requests/config/show/rails_admin_config_show_spec.rb +282 -0
- data/spec/requests/history/rails_admin_history_spec.rb +66 -0
- data/spec/requests/rails_admin_spec.rb +146 -0
- data/spec/requests/relation_spec.rb +26 -0
- data/spec/spec_helper.rb +91 -0
- metadata +967 -0
data/config/routes.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
RailsAdmin::Engine.routes.draw do
|
|
2
|
+
controller "main" do
|
|
3
|
+
RailsAdmin::Config::Actions.all(:root).each { |action| match "/#{action.route_fragment}", :to => action.action_name, :as => action.action_name, :via => action.http_methods }
|
|
4
|
+
scope ":model_name" do
|
|
5
|
+
RailsAdmin::Config::Actions.all(:collection).each { |action| match "/#{action.route_fragment}", :to => action.action_name, :as => action.action_name, :via => action.http_methods }
|
|
6
|
+
post "/bulk_action", :to => :bulk_action, :as => "bulk_action"
|
|
7
|
+
scope ":id" do
|
|
8
|
+
RailsAdmin::Config::Actions.all(:member).each { |action| match "/#{action.route_fragment}", :to => action.action_name, :as => action.action_name, :via => action.http_methods }
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require 'rails/generators'
|
|
2
|
+
require File.expand_path('../utils', __FILE__)
|
|
3
|
+
|
|
4
|
+
# http://guides.rubyonrails.org/generators.html
|
|
5
|
+
# http://rdoc.info/github/wycats/thor/master/Thor/Actions.html
|
|
6
|
+
# keep generator idempotent, thanks
|
|
7
|
+
|
|
8
|
+
module RailsAdmin
|
|
9
|
+
class InstallGenerator < Rails::Generators::Base
|
|
10
|
+
source_root File.expand_path("../templates", __FILE__)
|
|
11
|
+
include Rails::Generators::Migration
|
|
12
|
+
include Generators::Utils::InstanceMethods
|
|
13
|
+
extend Generators::Utils::ClassMethods
|
|
14
|
+
|
|
15
|
+
argument :_model_name, :type => :string, :required => false, :desc => "Devise user model name"
|
|
16
|
+
argument :_namespace, :type => :string, :required => false, :desc => "RailsAdmin url namespace"
|
|
17
|
+
desc "RailsAdmin installation generator"
|
|
18
|
+
|
|
19
|
+
def install
|
|
20
|
+
routes = File.open(Rails.root.join("config/routes.rb")).try :read
|
|
21
|
+
initializer = (File.open(Rails.root.join("config/initializers/rails_admin.rb")) rescue nil).try :read
|
|
22
|
+
|
|
23
|
+
display "Hello, RailsAdmin installer will help you sets things up!", :blue
|
|
24
|
+
display "I need to work with Devise, let's look at a few things first:"
|
|
25
|
+
display "Checking for a current installation of devise..."
|
|
26
|
+
unless defined?(Devise)
|
|
27
|
+
display "Adding devise gem to your Gemfile:"
|
|
28
|
+
append_file "Gemfile", "\n", :force => true
|
|
29
|
+
gem 'devise'
|
|
30
|
+
else
|
|
31
|
+
display "Found it!"
|
|
32
|
+
end
|
|
33
|
+
unless File.exists?(Rails.root.join("config/initializers/devise.rb"))
|
|
34
|
+
display "Looks like you don't have devise installed! We'll install it for you:"
|
|
35
|
+
generate "devise:install"
|
|
36
|
+
else
|
|
37
|
+
display "Looks like you've already installed it, good!"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
unless routes.index("devise_for")
|
|
41
|
+
model_name = ask_for("What would you like the user model to be called?", "user", _model_name)
|
|
42
|
+
display "Now setting up devise with user model name '#{model_name}':"
|
|
43
|
+
generate "devise", model_name
|
|
44
|
+
else
|
|
45
|
+
display "And you already set it up, good! We just need to know about your user model name..."
|
|
46
|
+
guess = routes.match(/devise_for :(\w+)/)[1].try(:singularize)
|
|
47
|
+
display("We found '#{guess}' (should be one of 'user', 'admin', etc.)")
|
|
48
|
+
model_name = ask_for("Correct Devise model name if needed.", guess, _model_name)
|
|
49
|
+
unless guess == model_name
|
|
50
|
+
display "Now setting up devise with user model name '#{model_name}':"
|
|
51
|
+
generate "devise", model_name
|
|
52
|
+
else
|
|
53
|
+
display "Ok, Devise looks already set up with user model name '#{model_name}':"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
display "Now you'll need an initializer..."
|
|
57
|
+
@model_name = model_name
|
|
58
|
+
unless initializer
|
|
59
|
+
template "initializer.erb", "config/initializers/rails_admin.rb"
|
|
60
|
+
else
|
|
61
|
+
display "You already have a config file. You're updating, heh? I'm generating a new 'rails_admin.rb.example' that you can review."
|
|
62
|
+
template "initializer.erb", "config/initializers/rails_admin.rb.example"
|
|
63
|
+
config_tag = initializer.match(/RailsAdmin\.config.+\|(.+)\|/)[1] rescue nil
|
|
64
|
+
if config_tag
|
|
65
|
+
if initializer.index(::Regexp.new("#{config_tag}\.current_user_method.?\{.+?\}"))
|
|
66
|
+
display "current_user_method found and updated with 'current_#{model_name}'", :green
|
|
67
|
+
gsub_file Rails.root.join("config/initializers/rails_admin.rb"), ::Regexp.new("#{config_tag}\.current_user_method.?\{.+?\}"), "#{config_tag}.current_user_method { current_#{model_name} }"
|
|
68
|
+
else
|
|
69
|
+
display "current_user_method not found. Added one with 'current_#{model_name}'!", :yellow
|
|
70
|
+
insert_into_file Rails.root.join("config/initializers/rails_admin.rb"), "\n\n #{config_tag}.current_user_method { current_#{model_name} } #auto-generated", :after => /^RailsAdmin\.config.+$/
|
|
71
|
+
end
|
|
72
|
+
else
|
|
73
|
+
display "Couldn't parse your config file: current_user_method couldn't be updated", :red
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
display "Adding a migration..."
|
|
77
|
+
migration_template 'migration.rb', 'db/migrate/create_rails_admin_histories_table.rb' rescue display $!.message
|
|
78
|
+
namespace = ask_for("Where do you want to mount rails_admin?", "admin", _namespace)
|
|
79
|
+
gsub_file "config/routes.rb", /mount RailsAdmin::Engine => \'\/.+\', :as => \'rails_admin\'/, ''
|
|
80
|
+
route("mount RailsAdmin::Engine => '/#{namespace}', :as => 'rails_admin'")
|
|
81
|
+
display "Job's done: migrate, start your server and visit '/#{namespace}'!", :blue
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class DropRailsAdminHistoriesTable < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
drop_table :rails_admin_histories
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def self.down
|
|
7
|
+
create_table :rails_admin_histories do |t|
|
|
8
|
+
t.text :message # title, name, or object_id
|
|
9
|
+
t.string :username
|
|
10
|
+
t.integer :item
|
|
11
|
+
t.string :table
|
|
12
|
+
t.integer :month, :limit => 2
|
|
13
|
+
t.integer :year, :limit => 5
|
|
14
|
+
t.timestamps
|
|
15
|
+
end
|
|
16
|
+
add_index(:rails_admin_histories, [:item, :table, :month, :year], :name => 'index_rails_admin_histories' )
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# RailsAdmin config file. Generated on <%= DateTime.now.to_s(:long) %>
|
|
2
|
+
# See github.com/sferik/rails_admin for more informations
|
|
3
|
+
|
|
4
|
+
RailsAdmin.config do |config|
|
|
5
|
+
|
|
6
|
+
# If your default_local is different from :en, uncomment the following 2 lines and set your default locale here:
|
|
7
|
+
# require 'i18n'
|
|
8
|
+
# I18n.default_locale = :de
|
|
9
|
+
|
|
10
|
+
config.current_user_method { current_<%= @model_name.underscore %> } # auto-generated
|
|
11
|
+
|
|
12
|
+
# If you want to track changes on your models:
|
|
13
|
+
# config.audit_with :history, <%= @model_name.classify %>
|
|
14
|
+
|
|
15
|
+
# Or with a PaperTrail: (you need to install it first)
|
|
16
|
+
# config.audit_with :paper_trail, <%= @model_name.classify %>
|
|
17
|
+
|
|
18
|
+
# Set the admin name here (optional second array element will appear in a beautiful RailsAdmin red ©)
|
|
19
|
+
config.main_app_name = ['<%= Rails.application.engine_name.titleize.chomp(' Application') %>', 'Admin']
|
|
20
|
+
# or for a dynamic name:
|
|
21
|
+
# config.main_app_name = Proc.new { |controller| [Rails.application.engine_name.titleize, controller.params['action'].titleize] }
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# ==> Global show view settings
|
|
25
|
+
# Display empty fields in show views
|
|
26
|
+
# config.compact_show_view = false
|
|
27
|
+
|
|
28
|
+
# ==> Global list view settings
|
|
29
|
+
# Number of default rows per-page:
|
|
30
|
+
# config.default_items_per_page = 20
|
|
31
|
+
|
|
32
|
+
# ==> Included models
|
|
33
|
+
# Add all excluded models here:
|
|
34
|
+
# config.excluded_models = [<%= RailsAdmin::AbstractModel.all_models.map(&:name).join(', ') %>]
|
|
35
|
+
|
|
36
|
+
# Add models here if you want to go 'whitelist mode':
|
|
37
|
+
# config.included_models = [<%= RailsAdmin::AbstractModel.all_models.map(&:name).join(', ') %>]
|
|
38
|
+
|
|
39
|
+
# Application wide tried label methods for models' instances
|
|
40
|
+
# config.label_methods << :description # Default is [:name, :title]
|
|
41
|
+
|
|
42
|
+
# ==> Global models configuration
|
|
43
|
+
# config.models do
|
|
44
|
+
# # Configuration here will affect all included models in all scopes, handle with care!
|
|
45
|
+
#
|
|
46
|
+
# list do
|
|
47
|
+
# # Configuration here will affect all included models in list sections (same for show, export, edit, update, create)
|
|
48
|
+
#
|
|
49
|
+
# fields_of_type :date do
|
|
50
|
+
# # Configuration here will affect all date fields, in the list section, for all included models. See README for a comprehensive type list.
|
|
51
|
+
# end
|
|
52
|
+
# end
|
|
53
|
+
# end
|
|
54
|
+
#
|
|
55
|
+
# ==> Model specific configuration
|
|
56
|
+
# Keep in mind that *all* configuration blocks are optional.
|
|
57
|
+
# RailsAdmin will try his best to provide the best defaults for each section, for each field.
|
|
58
|
+
# Try to override as few things as possible, in the most generic way. Try to avoid setting labels for models and attributes, use ActiveRecord I18n API instead.
|
|
59
|
+
# Less code is better code!
|
|
60
|
+
# config.model MyModel do
|
|
61
|
+
# # Cross-section field configuration
|
|
62
|
+
# object_label_method :name # Name of the method called for pretty printing an *instance* of ModelName
|
|
63
|
+
# label 'My model' # Name of ModelName (smartly defaults to ActiveRecord's I18n API)
|
|
64
|
+
# label_plural 'My models' # Same, plural
|
|
65
|
+
# weight -1 # Navigation priority. Bigger is higher.
|
|
66
|
+
# parent OtherModel # Set parent model for navigation. MyModel will be nested below. OtherModel will be on first position of the dropdown
|
|
67
|
+
# navigation_label # Sets dropdown entry's name in navigation. Only for parents!
|
|
68
|
+
# # Section specific configuration:
|
|
69
|
+
# list do
|
|
70
|
+
# filters [:id, :name] # Array of field names which filters should be shown by default in the table header
|
|
71
|
+
# items_per_page 100 # Override default_items_per_page
|
|
72
|
+
# sort_by :id # Sort column (default is primary key)
|
|
73
|
+
# sort_reverse true # Sort direction (default is true for primary key, last created first)
|
|
74
|
+
# # Here goes the fields configuration for the list view
|
|
75
|
+
# end
|
|
76
|
+
# end
|
|
77
|
+
|
|
78
|
+
# Your model's configuration, to help you get started:
|
|
79
|
+
|
|
80
|
+
# All fields marked as 'hidden' won't be shown anywhere in the rails_admin unless you mark them as visible. (visible(true))
|
|
81
|
+
|
|
82
|
+
<% RailsAdmin::AbstractModel.all.map do |abstract_model| -%>
|
|
83
|
+
# config.model <%= abstract_model.model.model_name %> do
|
|
84
|
+
# # Found associations:
|
|
85
|
+
<%= RailsAdmin.config(abstract_model).export.fields.select{|f| f.association?}.map do |field|
|
|
86
|
+
%{ # configure #{field.name.inspect}, #{field.type.inspect}#{" # Hidden" unless field.visible?} }
|
|
87
|
+
end.join("\n") -%>
|
|
88
|
+
# # Found columns:
|
|
89
|
+
<%= RailsAdmin.config(abstract_model).export.fields.select{|f| !f.association?}.map do |field|
|
|
90
|
+
%{ # configure #{field.name.inspect}, #{field.type.inspect}#{" # Hidden" unless field.visible?} }
|
|
91
|
+
end.join("\n") -%>
|
|
92
|
+
# # Sections:
|
|
93
|
+
# list do; end
|
|
94
|
+
# export do; end
|
|
95
|
+
# show do; end
|
|
96
|
+
# edit do; end
|
|
97
|
+
# create do; end
|
|
98
|
+
# update do; end
|
|
99
|
+
# end
|
|
100
|
+
<%- end -%>
|
|
101
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class CreateRailsAdminHistoriesTable < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
create_table :rails_admin_histories do |t|
|
|
4
|
+
t.text :message # title, name, or object_id
|
|
5
|
+
t.string :username
|
|
6
|
+
t.integer :item
|
|
7
|
+
t.string :table
|
|
8
|
+
t.integer :month, :limit => 2
|
|
9
|
+
t.integer :year, :limit => 5
|
|
10
|
+
t.timestamps
|
|
11
|
+
end
|
|
12
|
+
add_index(:rails_admin_histories, [:item, :table, :month, :year], :name => 'index_rails_admin_histories' )
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.down
|
|
16
|
+
drop_table :rails_admin_histories
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'rails/generators'
|
|
2
|
+
require File.expand_path('../utils', __FILE__)
|
|
3
|
+
|
|
4
|
+
module RailsAdmin
|
|
5
|
+
class UninstallGenerator < Rails::Generators::Base
|
|
6
|
+
include Rails::Generators::Migration
|
|
7
|
+
include Generators::Utils::InstanceMethods
|
|
8
|
+
extend Generators::Utils::ClassMethods
|
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
10
|
+
|
|
11
|
+
desc "RailsAdmin uninstall"
|
|
12
|
+
|
|
13
|
+
def uninstall
|
|
14
|
+
display "Why you leaving so soon? :("
|
|
15
|
+
migration_template 'drop.rb', 'db/migrate/drop_rails_admin_histories_table.rb'
|
|
16
|
+
remove_file 'config/initializers/rails_admin.rb'
|
|
17
|
+
remove_file 'config/initializers/rails_admin.rb.example'
|
|
18
|
+
gsub_file "config/routes.rb", /mount RailsAdmin::Engine => \'\/.+\', :as => \'rails_admin\'/, ''
|
|
19
|
+
display "Done! Devise has been left untouched."
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module RailsAdmin
|
|
2
|
+
module Generators
|
|
3
|
+
module Utils
|
|
4
|
+
module InstanceMethods
|
|
5
|
+
def display(output, color = :green)
|
|
6
|
+
say(" - #{output}", color)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def ask_for(wording, default_value = nil, override_if_present_value = nil)
|
|
10
|
+
override_if_present_value.present? ?
|
|
11
|
+
display("Using [#{override_if_present_value}] for question '#{wording}'") && override_if_present_value :
|
|
12
|
+
ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
module ClassMethods
|
|
17
|
+
def next_migration_number(dirname)
|
|
18
|
+
if ActiveRecord::Base.timestamped_migrations
|
|
19
|
+
migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
|
20
|
+
migration_number += 1
|
|
21
|
+
migration_number.to_s
|
|
22
|
+
else
|
|
23
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
data/lib/rails_admin.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'rails_admin/engine'
|
|
2
|
+
require 'rails_admin/abstract_model'
|
|
3
|
+
require 'rails_admin/config'
|
|
4
|
+
require 'rails_admin/extension'
|
|
5
|
+
require 'rails_admin/extensions/cancan'
|
|
6
|
+
require 'rails_admin/extensions/paper_trail'
|
|
7
|
+
require 'rails_admin/extensions/history'
|
|
8
|
+
require 'rails_admin/support/csv_converter'
|
|
9
|
+
require 'rails_admin/support/core_extensions'
|
|
10
|
+
|
|
11
|
+
module RailsAdmin
|
|
12
|
+
# Setup RailsAdmin
|
|
13
|
+
#
|
|
14
|
+
# Given the first argument is a model class, a model class name
|
|
15
|
+
# or an abstract model object proxies to model configuration method.
|
|
16
|
+
#
|
|
17
|
+
# If only a block is passed it is stored to initializer stack to be evaluated
|
|
18
|
+
# on first request in production mode and on each request in development. If
|
|
19
|
+
# initialization has already occured (in other words RailsAdmin.setup has
|
|
20
|
+
# been called) the block will be added to stack and evaluated at once.
|
|
21
|
+
#
|
|
22
|
+
# Otherwise returns RailsAdmin::Config class.
|
|
23
|
+
#
|
|
24
|
+
# @see RailsAdmin::Config
|
|
25
|
+
def self.config(entity = nil, &block)
|
|
26
|
+
if entity
|
|
27
|
+
RailsAdmin::Config.model(entity, &block)
|
|
28
|
+
elsif block_given? && ENV['SKIP_RAILS_ADMIN_INITIALIZER'] != "true"
|
|
29
|
+
block.call(RailsAdmin::Config)
|
|
30
|
+
else
|
|
31
|
+
RailsAdmin::Config
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Reset RailsAdmin configuration to defaults
|
|
36
|
+
def self.reset
|
|
37
|
+
RailsAdmin::Config.reset
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
|
2
|
+
require 'rails_admin/generic_support'
|
|
3
|
+
|
|
4
|
+
module RailsAdmin
|
|
5
|
+
class AbstractModel
|
|
6
|
+
cattr_accessor :all_models, :all_abstract_models
|
|
7
|
+
@@all_models = nil
|
|
8
|
+
@@all_abstract_models = nil
|
|
9
|
+
# Returns all models for a given Rails app
|
|
10
|
+
|
|
11
|
+
# self.all_abstract_models
|
|
12
|
+
def self.all
|
|
13
|
+
@@all_abstract_models ||= all_models.map{ |model| new(model) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.all_models
|
|
17
|
+
@@all_models ||= (
|
|
18
|
+
possible_models = RailsAdmin::Config.included_models.map(&:to_s).presence || ([Rails.application] + Rails::Application::Railties.engines).map do |app|
|
|
19
|
+
(app.paths['app/models'] + app.config.autoload_paths).map do |load_path|
|
|
20
|
+
Dir.glob(app.root.join(load_path)).map do |load_dir|
|
|
21
|
+
Dir.glob(load_dir + "/**/*.rb").map do |filename|
|
|
22
|
+
lchomp(filename, "#{app.root.join(load_dir)}/").chomp('.rb').camelize # app/models/module/class.rb => module/class.rb => module/class => Module::Class
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end.flatten
|
|
27
|
+
excluded_models = (RailsAdmin::Config.excluded_models.map(&:to_s) + ['RailsAdmin::History'])
|
|
28
|
+
(possible_models - excluded_models).uniq.sort{|x, y| x.to_s <=> y.to_s}.map{|model| lookup(model) }.compact
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Given a string +model_name+, finds the corresponding model class
|
|
33
|
+
def self.lookup(model_name)
|
|
34
|
+
model = model_name.constantize rescue nil
|
|
35
|
+
if model && model.is_a?(Class) && superclasses(model).include?(ActiveRecord::Base) && !model.abstract_class?
|
|
36
|
+
model
|
|
37
|
+
else
|
|
38
|
+
nil
|
|
39
|
+
end
|
|
40
|
+
rescue LoadError
|
|
41
|
+
Rails.logger.error "Error while loading '#{model_name}': #{$!}"
|
|
42
|
+
nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def initialize(model)
|
|
46
|
+
model = self.class.lookup(model.to_s.camelize) unless model.is_a?(Class)
|
|
47
|
+
@model_name = model.name
|
|
48
|
+
self.extend(GenericSupport)
|
|
49
|
+
### TODO more ORMs support
|
|
50
|
+
require 'rails_admin/adapters/active_record'
|
|
51
|
+
self.extend(RailsAdmin::Adapters::ActiveRecord)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def model
|
|
55
|
+
@model_name.constantize
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def self.superclasses(klass)
|
|
61
|
+
superclasses = []
|
|
62
|
+
while klass
|
|
63
|
+
superclasses << klass.superclass if klass && klass.superclass
|
|
64
|
+
klass = klass.superclass
|
|
65
|
+
end
|
|
66
|
+
superclasses
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def self.lchomp(base, arg) # yeah.. delete was probably safe, but never know.
|
|
70
|
+
base.to_s.reverse.chomp(arg.to_s.reverse).reverse
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module RailsAdmin
|
|
2
|
+
class AbstractObject
|
|
3
|
+
# undef almost all of this class's methods so it will pass almost
|
|
4
|
+
# everything through to its delegate using method_missing (below).
|
|
5
|
+
instance_methods.each { |m| undef_method m unless m.to_s =~ /(^__|^send$|^object_id$)/ }
|
|
6
|
+
# ^^^^^
|
|
7
|
+
# the unnecessary "to_s" above is a workaround for meta_where, see
|
|
8
|
+
# https://github.com/sferik/rails_admin/issues/374
|
|
9
|
+
|
|
10
|
+
attr_accessor :object
|
|
11
|
+
|
|
12
|
+
def initialize(object)
|
|
13
|
+
self.object = object
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def set_attributes(attributes, role = nil)
|
|
17
|
+
object.assign_attributes(attributes, :as => role)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def method_missing(name, *args, &block)
|
|
21
|
+
self.object.send(name, *args, &block)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def save(options = { :validate => true })
|
|
25
|
+
object.save(options)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
require 'active_record'
|
|
2
|
+
require 'rails_admin/config/sections/list'
|
|
3
|
+
require 'rails_admin/abstract_object'
|
|
4
|
+
|
|
5
|
+
module RailsAdmin
|
|
6
|
+
module Adapters
|
|
7
|
+
module ActiveRecord
|
|
8
|
+
DISABLED_COLUMN_TYPES = [:tsvector, :blob, :binary]
|
|
9
|
+
@@polymorphic_parents = nil
|
|
10
|
+
|
|
11
|
+
def self.polymorphic_parents(name)
|
|
12
|
+
@@polymorphic_parents ||= {}.tap do |hash|
|
|
13
|
+
RailsAdmin::AbstractModel.all_models.each do |klass|
|
|
14
|
+
klass.reflect_on_all_associations.select{|r| r.options[:as] }.each do |reflection|
|
|
15
|
+
(hash[reflection.options[:as].to_sym] ||= []) << klass
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
@@polymorphic_parents[name.to_sym]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def get(id)
|
|
23
|
+
if object = model.where(model.primary_key => id).first
|
|
24
|
+
RailsAdmin::AbstractObject.new object
|
|
25
|
+
else
|
|
26
|
+
nil
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def count(options = {}, scope = nil)
|
|
31
|
+
all(options.merge({:limit => false, :page => false}), scope).count
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def first(options = {}, scope = nil)
|
|
35
|
+
all(options, scope).first
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def all(options = {}, scope = nil)
|
|
39
|
+
scope ||= self.scoped
|
|
40
|
+
scope = scope.includes(options[:include]) if options[:include]
|
|
41
|
+
scope = scope.limit(options[:limit]) if options[:limit]
|
|
42
|
+
scope = scope.where(model.primary_key => options[:bulk_ids]) if options[:bulk_ids]
|
|
43
|
+
scope = scope.where(options[:conditions]) if options[:conditions]
|
|
44
|
+
scope = scope.page(options[:page]).per(options[:per]) if options[:page] && options[:per]
|
|
45
|
+
scope = scope.reorder("#{options[:sort]} #{options[:sort_reverse] ? 'asc' : 'desc'}") if options[:sort]
|
|
46
|
+
scope
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def scoped
|
|
50
|
+
model.scoped
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def create(params = {})
|
|
54
|
+
model.create(params)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def new(params = {})
|
|
58
|
+
RailsAdmin::AbstractObject.new(model.new(params))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def destroy(objects)
|
|
62
|
+
[objects].flatten.map &:destroy
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def destroy_all!
|
|
66
|
+
model.all.each do |object|
|
|
67
|
+
object.destroy
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def has_and_belongs_to_many_associations
|
|
72
|
+
associations.select do |association|
|
|
73
|
+
association[:type] == :has_and_belongs_to_many
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def has_many_associations
|
|
78
|
+
associations.select do |association|
|
|
79
|
+
association[:type] == :has_many
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def has_one_associations
|
|
84
|
+
associations.select do |association|
|
|
85
|
+
association[:type] == :has_one
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def belongs_to_associations
|
|
90
|
+
associations.select do |association|
|
|
91
|
+
association[:type] == :belongs_to
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def associations
|
|
96
|
+
model.reflect_on_all_associations.map do |association|
|
|
97
|
+
{
|
|
98
|
+
:name => association.name.to_sym,
|
|
99
|
+
:pretty_name => association.name.to_s.tr('_', ' ').capitalize,
|
|
100
|
+
:type => association.macro,
|
|
101
|
+
:parent_model => association_parent_model_lookup(association),
|
|
102
|
+
:parent_key => association_parent_key_lookup(association),
|
|
103
|
+
:child_model => association_child_model_lookup(association),
|
|
104
|
+
:child_key => association_child_key_lookup(association),
|
|
105
|
+
:foreign_type => association_foreign_type_lookup(association),
|
|
106
|
+
:as => association_as_lookup(association),
|
|
107
|
+
:polymorphic => association_polymorphic_lookup(association),
|
|
108
|
+
:inverse_of => association_inverse_of_lookup(association),
|
|
109
|
+
:read_only => association_read_only_lookup(association),
|
|
110
|
+
:nested_form => association_nested_attributes_options_lookup(association)
|
|
111
|
+
}
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def polymorphic_associations
|
|
116
|
+
(has_many_associations + has_one_associations).select do |association|
|
|
117
|
+
association[:options][:as]
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def properties
|
|
122
|
+
columns = model.columns.reject {|c| c.type.blank? || DISABLED_COLUMN_TYPES.include?(c.type.to_sym) }
|
|
123
|
+
columns.map do |property|
|
|
124
|
+
{
|
|
125
|
+
:name => property.name.to_sym,
|
|
126
|
+
:pretty_name => property.name.to_s.tr('_', ' ').capitalize,
|
|
127
|
+
:type => property.type,
|
|
128
|
+
:length => property.limit,
|
|
129
|
+
:nullable? => property.null,
|
|
130
|
+
:serial? => property.primary,
|
|
131
|
+
}
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def model_store_exists?
|
|
136
|
+
model.table_exists?
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def get_conditions_hash(model_config, query, filters)
|
|
140
|
+
@like_operator = "ILIKE" if ::ActiveRecord::Base.configurations[Rails.env]['adapter'] == "postgresql"
|
|
141
|
+
@like_operator ||= "LIKE"
|
|
142
|
+
|
|
143
|
+
query_statements = []
|
|
144
|
+
filters_statements = []
|
|
145
|
+
values = []
|
|
146
|
+
conditions = [""]
|
|
147
|
+
|
|
148
|
+
if query.present?
|
|
149
|
+
queryable_fields = model_config.list.fields.select(&:queryable?)
|
|
150
|
+
queryable_fields.each do |field|
|
|
151
|
+
searchable_columns = field.searchable_columns.flatten
|
|
152
|
+
searchable_columns.each do |field_infos|
|
|
153
|
+
statement, value1, value2 = build_statement(field_infos[:column], field_infos[:type], query, field.search_operator)
|
|
154
|
+
if statement
|
|
155
|
+
query_statements << statement
|
|
156
|
+
values << value1 unless value1.nil?
|
|
157
|
+
values << value2 unless value2.nil?
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
unless query_statements.empty?
|
|
164
|
+
conditions[0] += " AND " unless conditions == [""]
|
|
165
|
+
conditions[0] += "(#{query_statements.join(" OR ")})"
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
if filters.present?
|
|
169
|
+
@filterable_fields = model_config.list.fields.select(&:filterable?).inject({}){ |memo, field| memo[field.name.to_sym] = field.searchable_columns; memo }
|
|
170
|
+
filters.each_pair do |field_name, filters_dump|
|
|
171
|
+
filters_dump.each do |filter_index, filter_dump|
|
|
172
|
+
field_statements = []
|
|
173
|
+
@filterable_fields[field_name.to_sym].each do |field_infos|
|
|
174
|
+
statement, value1, value2 = build_statement(field_infos[:column], field_infos[:type], filter_dump[:v], (filter_dump[:o] || 'default'))
|
|
175
|
+
if statement
|
|
176
|
+
field_statements << statement
|
|
177
|
+
values << value1 unless value1.nil?
|
|
178
|
+
values << value2 unless value2.nil?
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
filters_statements << "(#{field_statements.join(' OR ')})" unless field_statements.empty?
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
unless filters_statements.empty?
|
|
187
|
+
conditions[0] += " AND " unless conditions == [""]
|
|
188
|
+
conditions[0] += "#{filters_statements.join(" AND ")}" # filters should all be true
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
conditions += values
|
|
192
|
+
conditions != [""] ? { :conditions => conditions } : {}
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def build_statement(column, type, value, operator)
|
|
196
|
+
|
|
197
|
+
# this operator/value has been discarded (but kept in the dom to override the one stored in the various links of the page)
|
|
198
|
+
return if operator == '_discard' || value == '_discard'
|
|
199
|
+
|
|
200
|
+
# filtering data with unary operator, not type dependent
|
|
201
|
+
if operator == '_blank' || value == '_blank'
|
|
202
|
+
return ["(#{column} IS NULL OR #{column} = '')"]
|
|
203
|
+
elsif operator == '_present' || value == '_present'
|
|
204
|
+
return ["(#{column} IS NOT NULL AND #{column} != '')"]
|
|
205
|
+
elsif operator == '_null' || value == '_null'
|
|
206
|
+
return ["(#{column} IS NULL)"]
|
|
207
|
+
elsif operator == '_not_null' || value == '_not_null'
|
|
208
|
+
return ["(#{column} IS NOT NULL)"]
|
|
209
|
+
elsif operator == '_empty' || value == '_empty'
|
|
210
|
+
return ["(#{column} = '')"]
|
|
211
|
+
elsif operator == '_not_empty' || value == '_not_empty'
|
|
212
|
+
return ["(#{column} != '')"]
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
# now we go type specific
|
|
216
|
+
case type
|
|
217
|
+
when :boolean
|
|
218
|
+
return ["(#{column} IS NULL OR #{column} = ?)", false] if ['false', 'f', '0'].include?(value)
|
|
219
|
+
return ["(#{column} = ?)", true] if ['true', 't', '1'].include?(value)
|
|
220
|
+
when :integer, :belongs_to_association
|
|
221
|
+
return if value.blank?
|
|
222
|
+
["(#{column} = ?)", value.to_i] if value.to_i.to_s == value
|
|
223
|
+
when :string, :text
|
|
224
|
+
return if value.blank?
|
|
225
|
+
value = case operator
|
|
226
|
+
when 'default', 'like'
|
|
227
|
+
"%#{value}%"
|
|
228
|
+
when 'starts_with'
|
|
229
|
+
"#{value}%"
|
|
230
|
+
when 'ends_with'
|
|
231
|
+
"%#{value}"
|
|
232
|
+
when 'is', '='
|
|
233
|
+
"#{value}"
|
|
234
|
+
end
|
|
235
|
+
["(#{column} #{@like_operator} ?)", value]
|
|
236
|
+
when :datetime, :timestamp, :date
|
|
237
|
+
return unless operator != 'default'
|
|
238
|
+
values = case operator
|
|
239
|
+
when 'today'
|
|
240
|
+
[Date.today.beginning_of_day, Date.today.end_of_day]
|
|
241
|
+
when 'yesterday'
|
|
242
|
+
[Date.yesterday.beginning_of_day, Date.yesterday.end_of_day]
|
|
243
|
+
when 'this_week'
|
|
244
|
+
[Date.today.beginning_of_week.beginning_of_day, Date.today.end_of_week.end_of_day]
|
|
245
|
+
when 'last_week'
|
|
246
|
+
[1.week.ago.to_date.beginning_of_week.beginning_of_day, 1.week.ago.to_date.end_of_week.end_of_day]
|
|
247
|
+
when 'less_than'
|
|
248
|
+
return if value.blank?
|
|
249
|
+
[value.to_i.days.ago, DateTime.now]
|
|
250
|
+
when 'more_than'
|
|
251
|
+
return if value.blank?
|
|
252
|
+
[2000.years.ago, value.to_i.days.ago]
|
|
253
|
+
when 'mmddyyyy'
|
|
254
|
+
return if (value.blank? || value.match(/([0-9]{8})/).nil?)
|
|
255
|
+
[Date.strptime(value.match(/([0-9]{8})/)[1], '%m%d%Y').beginning_of_day, Date.strptime(value.match(/([0-9]{8})/)[1], '%m%d%Y').end_of_day]
|
|
256
|
+
end
|
|
257
|
+
["(#{column} BETWEEN ? AND ?)", *values]
|
|
258
|
+
when :enum
|
|
259
|
+
return if value.blank?
|
|
260
|
+
["(#{column} IN (?))", [value].flatten]
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def association_options(association)
|
|
265
|
+
if association.options[:polymorphic]
|
|
266
|
+
{
|
|
267
|
+
:polymorphic => true,
|
|
268
|
+
:foreign_type => association.options[:foreign_type] || "#{association.name}_type"
|
|
269
|
+
}
|
|
270
|
+
elsif association.options[:as]
|
|
271
|
+
{
|
|
272
|
+
:as => association.options[:as]
|
|
273
|
+
}
|
|
274
|
+
else
|
|
275
|
+
{}
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def association_parent_model_lookup(association)
|
|
280
|
+
case association.macro
|
|
281
|
+
when :belongs_to
|
|
282
|
+
if association.options[:polymorphic]
|
|
283
|
+
RailsAdmin::Adapters::ActiveRecord.polymorphic_parents(association.name) || []
|
|
284
|
+
else
|
|
285
|
+
association.klass
|
|
286
|
+
end
|
|
287
|
+
when :has_one, :has_many, :has_and_belongs_to_many
|
|
288
|
+
association.active_record
|
|
289
|
+
else
|
|
290
|
+
raise "Unknown association type: #{association.macro.inspect}"
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
def association_foreign_type_lookup(association)
|
|
295
|
+
if association.options[:polymorphic]
|
|
296
|
+
association.options[:foreign_type].try(:to_sym) || :"#{association.name}_type"
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def association_nested_attributes_options_lookup(association)
|
|
301
|
+
model.nested_attributes_options.try { |o| o[association.name.to_sym] }
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
def association_as_lookup(association)
|
|
305
|
+
association.options[:as].try :to_sym
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
def association_polymorphic_lookup(association)
|
|
309
|
+
association.options[:polymorphic]
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def association_parent_key_lookup(association)
|
|
313
|
+
[:id]
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
def association_inverse_of_lookup(association)
|
|
317
|
+
association.options[:inverse_of].try :to_sym
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
def association_read_only_lookup(association)
|
|
321
|
+
association.options[:readonly]
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def association_child_model_lookup(association)
|
|
325
|
+
case association.macro
|
|
326
|
+
when :belongs_to
|
|
327
|
+
association.active_record
|
|
328
|
+
when :has_one, :has_many, :has_and_belongs_to_many
|
|
329
|
+
association.klass
|
|
330
|
+
else
|
|
331
|
+
raise "Unknown association type: #{association.macro.inspect}"
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def association_child_key_lookup(association)
|
|
336
|
+
case association.macro
|
|
337
|
+
when :belongs_to
|
|
338
|
+
association.options[:foreign_key].try(:to_sym) || "#{association.name}_id".to_sym
|
|
339
|
+
when :has_one, :has_many, :has_and_belongs_to_many
|
|
340
|
+
association.foreign_key.to_sym
|
|
341
|
+
else
|
|
342
|
+
raise "Unknown association type: #{association.macro.inspect}"
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
end
|