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
-
#create_another ⇒ Boolean
Display create another checkbox on a new page.
-
#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
149 150 151 |
# File 'lib/active_admin/application.rb', line 149 def allow_comments=(*) raise "`config.allow_comments` is no longer provided in ActiveAdmin 1.x. Use `config.comments` instead." end |
#controllers_for_filters ⇒ Object
262 263 264 265 266 |
# File 'lib/active_admin/application.rb', line 262 def controllers_for_filters controllers = [BaseController] controllers.push *Devise.controllers_for_filters if Dependency.devise? controllers end |
#create_another ⇒ Boolean
Display create another checkbox on a new page
94 |
# File 'lib/active_admin/application.rb', line 94 inheritable_setting :create_another, false |
#files ⇒ Object
Returns ALL the files to be loaded
235 236 237 |
# File 'lib/active_admin/application.rb', line 235 def files load_paths.flatten.compact.uniq.flat_map{ |path| Dir["#{path}/**/*.rb"] } end |
#load(file) ⇒ Object
230 231 232 |
# File 'lib/active_admin/application.rb', line 230 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!
220 221 222 223 224 225 226 227 228 |
# File 'lib/active_admin/application.rb', line 220 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
207 208 209 |
# File 'lib/active_admin/application.rb', line 207 def loaded? @@loaded ||= false end |
#namespace(name) {|namespace| ... } ⇒ Namespace
Creates a namespace for the given name
Yields the namespace if a block is given
181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/active_admin/application.rb', line 181 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
165 166 167 168 |
# File 'lib/active_admin/application.rb', line 165 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.
171 172 173 174 |
# File 'lib/active_admin/application.rb', line 171 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.
201 202 203 204 |
# File 'lib/active_admin/application.rb', line 201 def register_page(name, = {}, &block) ns = .fetch(:namespace){ default_namespace } namespace(ns).register_page name, , &block end |
#router ⇒ Object
239 240 241 |
# File 'lib/active_admin/application.rb', line 239 def router @router ||= Router.new(self) end |
#routes(rails_router) ⇒ Object
One-liner called by user’s config/routes.rb file
244 245 246 247 |
# File 'lib/active_admin/application.rb', line 244 def routes(rails_router) load! router.apply(rails_router) end |
#setup! ⇒ Object
Runs before the app’s AA initializer
160 161 162 |
# File 'lib/active_admin/application.rb', line 160 def setup! register_default_assets end |
#unload! ⇒ Object
Removes all defined controllers from memory. Useful in development, where they are reloaded on each request.
213 214 215 216 |
# File 'lib/active_admin/application.rb', line 213 def unload! namespaces.each &:unload! @@loaded = false end |