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
-
#dashboard_section(name, options = {}, &block) ⇒ Object
Helper method to add a dashboard section.
-
#files ⇒ Object
Returns ALL the files to be loaded.
-
#initialize ⇒ Application
constructor
A new instance of Application.
-
#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
-
#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
-
#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
#dashboard_section(name, options = {}, &block) ⇒ Object
Helper method to add a dashboard section
203 204 205 |
# File 'lib/active_admin/application.rb', line 203 def dashboard_section(name, = {}, &block) ActiveAdmin::Dashboards.add_section(name, , &block) end |
#files ⇒ Object
Returns ALL the files to be loaded
175 176 177 |
# File 'lib/active_admin/application.rb', line 175 def files load_paths.flatten.compact.uniq.map{ |path| Dir["#{path}/**/*.rb"] }.flatten end |
#load! ⇒ Object
Loads all ruby files that are within the load_paths setting. To reload everything simply call ‘ActiveAdmin.unload!`
164 165 166 167 168 169 170 171 172 |
# File 'lib/active_admin/application.rb', line 164 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
151 152 153 |
# File 'lib/active_admin/application.rb', line 151 def loaded? @@loaded ||= false end |
#namespace(name) {|namespace| ... } ⇒ Object
Creates a namespace for the given name
Yields the namespace if a block is given
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/active_admin/application.rb', line 124 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
107 108 109 110 111 |
# File 'lib/active_admin/application.rb', line 107 def prepare! remove_active_admin_load_paths_from_rails_autoload_and_eager_load attach_reloader generate_stylesheets end |
#register(resource, options = {}, &block) ⇒ Object
Registers a brand new configuration for the given resource.
114 115 116 117 |
# File 'lib/active_admin/application.rb', line 114 def register(resource, = {}, &block) ns_name = namespace_name() namespace(ns_name).register resource, , &block end |
#register_page(name, options = {}, &block) ⇒ Object
Register a page
@&block The registration block.
145 146 147 148 |
# File 'lib/active_admin/application.rb', line 145 def register_page(name, = {}, &block) ns_name = namespace_name() namespace(ns_name).register_page name, , &block end |
#router ⇒ Object
179 180 181 |
# File 'lib/active_admin/application.rb', line 179 def router @router ||= Router.new(self) end |
#routes(rails_router) ⇒ Object
One-liner called by user’s config/routes.rb file
184 185 186 187 |
# File 'lib/active_admin/application.rb', line 184 def routes(rails_router) load! router.apply(rails_router) end |
#setup! ⇒ Object
103 104 105 |
# File 'lib/active_admin/application.rb', line 103 def setup! register_default_assets end |
#unload! ⇒ Object
Removes all defined controllers from memory. Useful in development, where they are reloaded on each request.
157 158 159 160 |
# File 'lib/active_admin/application.rb', line 157 def unload! namespaces.values.each{ |namespace| namespace.unload! } @@loaded = false end |