Class: ActiveAdmin::Application
- Inherits:
-
Object
- Object
- ActiveAdmin::Application
- Includes:
- AssetRegistration
- Defined in:
- lib/active_admin/application.rb
Constant Summary collapse
- BeforeLoadEvent =
Event that gets triggered on load of Active Admin
'active_admin.application.before_load'.freeze
- AfterLoadEvent =
'active_admin.application.after_load'.freeze
Instance Attribute Summary collapse
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
Class Method Summary collapse
Instance Method Summary collapse
-
#allow_comments= ⇒ Object
Deprecated Settings.
- #controllers_for_filters ⇒ Object
-
#files ⇒ Object
Returns ALL the files to be loaded.
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #load(file) ⇒ Object
-
#load! ⇒ Object
Loads all ruby files that are within the load_paths setting.
-
#loaded? ⇒ Boolean
Whether all configuration files have been loaded.
- #method_missing(method, *args) ⇒ Object
-
#namespace(name) {|namespace| ... } ⇒ Namespace
Creates a namespace for the given name.
- #namespace_settings ⇒ Object
-
#prepare! ⇒ Object
Runs after the app's AA initializer.
-
#register(resource, options = {}, &block) ⇒ Object
Registers a brand new configuration for the given resource.
-
#register_page(name, options = {}, &block) ⇒ Object
Register a page.
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
-
#routes(rails_router) ⇒ Object
Creates all the necessary routes for the ActiveAdmin configurations.
- #settings ⇒ Object
-
#setup! ⇒ Object
Runs before the app's AA initializer.
-
#unload! ⇒ Object
Removes all defined controllers from memory.
Methods included from AssetRegistration
#clear_javascripts!, #clear_stylesheets!, #javascripts, #register_javascript, #register_stylesheet, #stylesheets
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
41 42 43 |
# File 'lib/active_admin/application.rb', line 41 def initialize @namespaces = Namespace::Store.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/active_admin/application.rb', line 30 def method_missing(method, *args) if settings.respond_to?(method) settings.send(method, *args) elsif namespace_settings.respond_to?(method) namespace_settings.send(method, *args) else super end end |
Instance Attribute Details
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
40 41 42 |
# File 'lib/active_admin/application.rb', line 40 def namespaces @namespaces end |
Class Method Details
.inheritable_setting(name, default) ⇒ Object
13 14 15 |
# File 'lib/active_admin/application.rb', line 13 def inheritable_setting(name, default) NamespaceSettings.register name, default end |
.setting(name, default) ⇒ Object
9 10 11 |
# File 'lib/active_admin/application.rb', line 9 def setting(name, default) ApplicationSettings.register name, default end |
Instance Method Details
#allow_comments= ⇒ Object
Deprecated Settings
47 48 49 |
# File 'lib/active_admin/application.rb', line 47 def allow_comments=(*) raise "`config.allow_comments` is no longer provided in ActiveAdmin 1.x. Use `config.comments` instead." end |
#controllers_for_filters ⇒ Object
164 165 166 167 168 |
# File 'lib/active_admin/application.rb', line 164 def controllers_for_filters controllers = [BaseController] controllers.push *Devise.controllers_for_filters if Dependency.devise? controllers end |
#files ⇒ Object
Returns ALL the files to be loaded
133 134 135 |
# File 'lib/active_admin/application.rb', line 133 def files load_paths.flatten.compact.uniq.flat_map{ |path| Dir["#{path}/**/*.rb"] } end |
#load(file) ⇒ Object
128 129 130 |
# File 'lib/active_admin/application.rb', line 128 def load(file) DatabaseHitDuringLoad.capture{ super } end |
#load! ⇒ Object
Loads all ruby files that are within the load_paths setting. To reload everything simply call `ActiveAdmin.unload!`
118 119 120 121 122 123 124 125 126 |
# File 'lib/active_admin/application.rb', line 118 def load! unless loaded? ActiveSupport::Notifications.publish BeforeLoadEvent, self # before_load hook files.each{ |file| load file } # load files namespace(default_namespace) # init AA resources ActiveSupport::Notifications.publish AfterLoadEvent, self # after_load hook @@loaded = true end end |
#loaded? ⇒ Boolean
Whether all configuration files have been loaded
105 106 107 |
# File 'lib/active_admin/application.rb', line 105 def loaded? @@loaded ||= false end |
#namespace(name) {|namespace| ... } ⇒ Namespace
Creates a namespace for the given name
Yields the namespace if a block is given
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/active_admin/application.rb', line 79 def namespace(name) name ||= :root namespace = namespaces[name] ||= begin namespace = Namespace.new(self, name) ActiveSupport::Notifications.publish ActiveAdmin::Namespace::RegisterEvent, namespace namespace end yield(namespace) if block_given? namespace end |
#namespace_settings ⇒ Object
22 23 24 |
# File 'lib/active_admin/application.rb', line 22 def namespace_settings @namespace_settings ||= SettingsNode.build(NamespaceSettings) end |
#prepare! ⇒ Object
Runs after the app's AA initializer
63 64 65 66 |
# File 'lib/active_admin/application.rb', line 63 def prepare! remove_active_admin_load_paths_from_rails_autoload_and_eager_load attach_reloader end |
#register(resource, options = {}, &block) ⇒ Object
Registers a brand new configuration for the given resource.
69 70 71 72 |
# File 'lib/active_admin/application.rb', line 69 def register(resource, = {}, &block) ns = .fetch(:namespace){ default_namespace } namespace(ns).register resource, , &block end |
#register_page(name, options = {}, &block) ⇒ Object
Register a page
@&block The registration block.
99 100 101 102 |
# File 'lib/active_admin/application.rb', line 99 def register_page(name, = {}, &block) ns = .fetch(:namespace){ default_namespace } namespace(ns).register_page name, , &block end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
26 27 28 |
# File 'lib/active_admin/application.rb', line 26 def respond_to_missing?(method, include_private = false) [settings, namespace_settings].any? { |sets| sets.respond_to?(method) } || super end |
#routes(rails_router) ⇒ Object
Creates all the necessary routes for the ActiveAdmin configurations
Use this within the routes.rb file:
Application.routes.draw do |map|
ActiveAdmin.routes(self)
end
146 147 148 149 |
# File 'lib/active_admin/application.rb', line 146 def routes(rails_router) load! Router.new(router: rails_router, namespaces: namespaces).apply end |
#settings ⇒ Object
18 19 20 |
# File 'lib/active_admin/application.rb', line 18 def settings @settings ||= SettingsNode.build(ApplicationSettings) end |
#setup! ⇒ Object
Runs before the app's AA initializer
58 59 60 |
# File 'lib/active_admin/application.rb', line 58 def setup! register_default_assets end |
#unload! ⇒ Object
Removes all defined controllers from memory. Useful in development, where they are reloaded on each request.
111 112 113 114 |
# File 'lib/active_admin/application.rb', line 111 def unload! namespaces.each &:unload! @@loaded = false end |