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
152 153 154 |
# File 'lib/active_admin/application.rb', line 152 def allow_comments=(*) raise "`config.allow_comments` is no longer provided in ActiveAdmin 1.x. Use `config.comments` instead." end |
#controllers_for_filters ⇒ Object
265 266 267 268 269 |
# File 'lib/active_admin/application.rb', line 265 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
238 239 240 |
# File 'lib/active_admin/application.rb', line 238 def files load_paths.flatten.compact.uniq.flat_map{ |path| Dir["#{path}/**/*.rb"] } end |
#load(file) ⇒ Object
233 234 235 |
# File 'lib/active_admin/application.rb', line 233 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!`
223 224 225 226 227 228 229 230 231 |
# File 'lib/active_admin/application.rb', line 223 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
210 211 212 |
# File 'lib/active_admin/application.rb', line 210 def loaded? @@loaded ||= false end |
#namespace(name) {|namespace| ... } ⇒ Namespace
Creates a namespace for the given name
Yields the namespace if a block is given
184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/active_admin/application.rb', line 184 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
168 169 170 171 |
# File 'lib/active_admin/application.rb', line 168 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.
174 175 176 177 |
# File 'lib/active_admin/application.rb', line 174 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.
204 205 206 207 |
# File 'lib/active_admin/application.rb', line 204 def register_page(name, = {}, &block) ns = .fetch(:namespace){ default_namespace } namespace(ns).register_page name, , &block end |
#router ⇒ Object
242 243 244 |
# File 'lib/active_admin/application.rb', line 242 def router @router ||= Router.new(self) end |
#routes(rails_router) ⇒ Object
One-liner called by user’s config/routes.rb file
247 248 249 250 |
# File 'lib/active_admin/application.rb', line 247 def routes(rails_router) load! router.apply(rails_router) end |
#setup! ⇒ Object
Runs before the app’s AA initializer
163 164 165 |
# File 'lib/active_admin/application.rb', line 163 def setup! register_default_assets end |
#unload! ⇒ Object
Removes all defined controllers from memory. Useful in development, where they are reloaded on each request.
216 217 218 219 |
# File 'lib/active_admin/application.rb', line 216 def unload! namespaces.each &:unload! @@loaded = false end |