Class: ActiveAdmin::Application
- Inherits:
-
Object
- Object
- ActiveAdmin::Application
- Includes:
- AssetRegistration, Settings, Settings::Inheritance
- 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.
Instance Method Summary collapse
-
#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.
-
#namespace(name) {|namespace| ... } ⇒ Object
Creates a namespace for the given name.
-
#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.
- #router ⇒ Object
-
#routes(rails_router) ⇒ Object
One-liner called by user’s config/routes.rb file.
-
#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
Methods included from Settings
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
19 20 21 |
# File 'lib/active_admin/application.rb', line 19 def initialize @namespaces = {} end |
Instance Attribute Details
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
18 19 20 |
# File 'lib/active_admin/application.rb', line 18 def namespaces @namespaces end |
Instance Method Details
#files ⇒ Object
Returns ALL the files to be loaded
185 186 187 |
# File 'lib/active_admin/application.rb', line 185 def files load_paths.flatten.compact.uniq.map{ |path| Dir["#{path}/**/*.rb"] }.flatten end |
#load(file) ⇒ Object
178 179 180 181 182 |
# File 'lib/active_admin/application.rb', line 178 def load(file) super rescue ActiveRecord::StatementInvalid => exception raise DatabaseHitDuringLoad.new exception end |
#load! ⇒ Object
Loads all ruby files that are within the load_paths setting. To reload everything simply call ‘ActiveAdmin.unload!`
168 169 170 171 172 173 174 175 176 |
# File 'lib/active_admin/application.rb', line 168 def load! unless loaded? ActiveAdmin::Event.dispatch BeforeLoadEvent, self # before_load hook files.each{ |file| load file } # load files namespace(default_namespace) # init AA resources ActiveAdmin::Event.dispatch AfterLoadEvent, self # after_load hook @@loaded = true end end |
#loaded? ⇒ Boolean
Whether all configuration files have been loaded
155 156 157 |
# File 'lib/active_admin/application.rb', line 155 def loaded? @@loaded ||= false end |
#namespace(name) {|namespace| ... } ⇒ Object
Creates a namespace for the given name
Yields the namespace if a block is given
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/active_admin/application.rb', line 128 def namespace(name) name ||= :root if namespaces[name] namespace = namespaces[name] else namespace = namespaces[name] = Namespace.new(self, name) ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace end yield(namespace) if block_given? namespace end |
#prepare! ⇒ Object
Runs after the app’s AA initializer
112 113 114 115 |
# File 'lib/active_admin/application.rb', line 112 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.
118 119 120 121 |
# File 'lib/active_admin/application.rb', line 118 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.
149 150 151 152 |
# File 'lib/active_admin/application.rb', line 149 def register_page(name, = {}, &block) ns = .fetch(:namespace){ default_namespace } namespace(ns).register_page name, , &block end |
#router ⇒ Object
189 190 191 |
# File 'lib/active_admin/application.rb', line 189 def router @router ||= Router.new(self) end |
#routes(rails_router) ⇒ Object
One-liner called by user’s config/routes.rb file
194 195 196 197 |
# File 'lib/active_admin/application.rb', line 194 def routes(rails_router) load! router.apply(rails_router) end |
#setup! ⇒ Object
Runs before the app’s AA initializer
107 108 109 |
# File 'lib/active_admin/application.rb', line 107 def setup! register_default_assets end |
#unload! ⇒ Object
Removes all defined controllers from memory. Useful in development, where they are reloaded on each request.
161 162 163 164 |
# File 'lib/active_admin/application.rb', line 161 def unload! namespaces.values.each &:unload! @@loaded = false end |