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
-
#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.
-
#namespace(name) {|namespace| ... } ⇒ Namespace
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.
20 21 22 |
# File 'lib/active_admin/application.rb', line 20 def initialize @namespaces = Namespace::Store.new end |
Instance Attribute Details
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
19 20 21 |
# File 'lib/active_admin/application.rb', line 19 def namespaces @namespaces end |
Instance Method Details
#allow_comments= ⇒ Object
Deprecated Settings
134 135 136 |
# File 'lib/active_admin/application.rb', line 134 def allow_comments=(*) raise "`config.allow_comments` is no longer provided in ActiveAdmin 1.x. Use `config.comments` instead." end |
#controllers_for_filters ⇒ Object
247 248 249 250 251 |
# File 'lib/active_admin/application.rb', line 247 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
220 221 222 |
# File 'lib/active_admin/application.rb', line 220 def files load_paths.flatten.compact.uniq.flat_map{ |path| Dir["#{path}/**/*.rb"] } end |
#load(file) ⇒ Object
215 216 217 |
# File 'lib/active_admin/application.rb', line 215 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!`
205 206 207 208 209 210 211 212 213 |
# File 'lib/active_admin/application.rb', line 205 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
192 193 194 |
# File 'lib/active_admin/application.rb', line 192 def loaded? @@loaded ||= false end |
#namespace(name) {|namespace| ... } ⇒ Namespace
Creates a namespace for the given name
Yields the namespace if a block is given
166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/active_admin/application.rb', line 166 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 |
#prepare! ⇒ Object
Runs after the app’s AA initializer
150 151 152 153 |
# File 'lib/active_admin/application.rb', line 150 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.
156 157 158 159 |
# File 'lib/active_admin/application.rb', line 156 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.
186 187 188 189 |
# File 'lib/active_admin/application.rb', line 186 def register_page(name, = {}, &block) ns = .fetch(:namespace){ default_namespace } namespace(ns).register_page name, , &block end |
#router ⇒ Object
224 225 226 |
# File 'lib/active_admin/application.rb', line 224 def router @router ||= Router.new(self) end |
#routes(rails_router) ⇒ Object
One-liner called by user’s config/routes.rb file
229 230 231 232 |
# File 'lib/active_admin/application.rb', line 229 def routes(rails_router) load! router.apply(rails_router) end |
#setup! ⇒ Object
Runs before the app’s AA initializer
145 146 147 |
# File 'lib/active_admin/application.rb', line 145 def setup! register_default_assets end |
#unload! ⇒ Object
Removes all defined controllers from memory. Useful in development, where they are reloaded on each request.
198 199 200 201 |
# File 'lib/active_admin/application.rb', line 198 def unload! namespaces.each &:unload! @@loaded = false end |