Class: ActiveAdmin::Application
- Inherits:
-
Object
- Object
- ActiveAdmin::Application
- Includes:
- AssetRegistration, Settings
- 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
- @@loaded =
Stores if everything has been loaded or we need to reload
false
Instance Attribute Summary collapse
-
#admin_notes ⇒ Object
DEPRECATED: This option is deprecated and will be removed.
Class Method Summary collapse
- .deprecated_inheritable_setting(name, default) ⇒ Object
-
.inheritable_setting(name, default) ⇒ Object
Adds settings to both the Application and the Namespace instance so that they can be configured independantly.
Instance Method Summary collapse
- #after_filter(*args, &block) ⇒ Object
- #around_filter(*args, &block) ⇒ Object
-
#before_filter(*args, &block) ⇒ Object
Add before, around and after filters to each registered resource and pages.
-
#dashboard_section(name, options = {}, &block) ⇒ Object
Helper method to add a dashboard section.
-
#files_in_load_path ⇒ Object
Returns ALL the files to load from all the load paths.
-
#find_or_create_namespace(name) {|namespace| ... } ⇒ Object
(also: #namespace)
Creates a namespace for the given name.
-
#load! ⇒ Object
Loads all of the ruby files that are within the load path of ActiveAdmin.load_paths.
- #load_default_namespace ⇒ Object
-
#loaded? ⇒ Boolean
Returns true if all the configuration files have been loaded.
- #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
- #setup! ⇒ Object
- #skip_before_filter(*args, &block) ⇒ Object
-
#unload! ⇒ Object
Removes all the controllers that were defined by registering resources for administration.
Methods included from AssetRegistration
#clear_javascripts!, #clear_stylesheets!, #javascripts, #register_javascript, #register_stylesheet, #stylesheets
Methods included from Settings
Instance Attribute Details
#admin_notes ⇒ Object
DEPRECATED: This option is deprecated and will be removed. Use the #allow_comments_in option instead
98 99 100 |
# File 'lib/active_admin/application.rb', line 98 def admin_notes @admin_notes end |
Class Method Details
.deprecated_inheritable_setting(name, default) ⇒ Object
15 16 17 18 |
# File 'lib/active_admin/application.rb', line 15 def self.deprecated_inheritable_setting(name, default) Namespace.deprecated_setting name, nil deprecated_setting name, default end |
.inheritable_setting(name, default) ⇒ Object
Adds settings to both the Application and the Namespace instance so that they can be configured independantly.
10 11 12 13 |
# File 'lib/active_admin/application.rb', line 10 def self.inheritable_setting(name, default) Namespace.setting name, nil setting name, default end |
Instance Method Details
#after_filter(*args, &block) ⇒ Object
237 238 239 |
# File 'lib/active_admin/application.rb', line 237 def after_filter(*args, &block) BaseController.after_filter(*args, &block) end |
#around_filter(*args, &block) ⇒ Object
241 242 243 |
# File 'lib/active_admin/application.rb', line 241 def around_filter(*args, &block) BaseController.around_filter(*args, &block) end |
#before_filter(*args, &block) ⇒ Object
Add before, around and after filters to each registered resource and pages.
eg:
ActiveAdmin.before_filter :authenticate_admin!
229 230 231 |
# File 'lib/active_admin/application.rb', line 229 def before_filter(*args, &block) BaseController.before_filter(*args, &block) end |
#dashboard_section(name, options = {}, &block) ⇒ Object
Helper method to add a dashboard section
246 247 248 |
# File 'lib/active_admin/application.rb', line 246 def dashboard_section(name, = {}, &block) ActiveAdmin::Dashboards.add_section(name, , &block) end |
#files_in_load_path ⇒ Object
Returns ALL the files to load from all the load paths
202 203 204 |
# File 'lib/active_admin/application.rb', line 202 def files_in_load_path load_paths.flatten.compact.uniq.collect{|path| Dir["#{path}/**/*.rb"] }.flatten end |
#find_or_create_namespace(name) {|namespace| ... } ⇒ Object Also known as: namespace
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 142 |
# File 'lib/active_admin/application.rb', line 128 def find_or_create_namespace(name) name ||= :root if namespaces[name] namespace = namespaces[name] else namespace = Namespace.new(self, name) namespaces[name] = namespace ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace end yield(namespace) if block_given? namespace end |
#load! ⇒ Object
Loads all of the ruby files that are within the load path of ActiveAdmin.load_paths. This should load all of the administration UIs so that they are available for the router to proceed.
The files are only loaded if we haven’t already loaded all the files and they aren’t marked for re-loading. To mark the files for re-loading you must first call ActiveAdmin.unload!
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/active_admin/application.rb', line 183 def load! # No work to do if we've already loaded return false if loaded? ActiveAdmin::Event.dispatch BeforeLoadEvent, self # Load files files_in_load_path.each{|file| load file } # If no configurations, let's make sure you can still login load_default_namespace if namespaces.values.empty? # Dispatch an ActiveAdmin::Application::LoadEvent with the Application ActiveAdmin::Event.dispatch AfterLoadEvent, self @@loaded = true end |
#load_default_namespace ⇒ Object
218 219 220 |
# File 'lib/active_admin/application.rb', line 218 def load_default_namespace find_or_create_namespace(default_namespace) end |
#loaded? ⇒ Boolean
Returns true if all the configuration files have been loaded.
162 163 164 |
# File 'lib/active_admin/application.rb', line 162 def loaded? @@loaded end |
#prepare! ⇒ Object
110 111 112 113 114 |
# File 'lib/active_admin/application.rb', line 110 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.
117 118 119 120 121 |
# File 'lib/active_admin/application.rb', line 117 def register(resource, = {}, &block) namespace_name = extract_namespace_name() namespace = find_or_create_namespace(namespace_name) namespace.register(resource, , &block) end |
#register_page(name, options = {}, &block) ⇒ Object
Register a page
@&block The registration block.
152 153 154 155 156 |
# File 'lib/active_admin/application.rb', line 152 def register_page(name, = {}, &block) namespace_name = extract_namespace_name() namespace = find_or_create_namespace(namespace_name) namespace.register_page(name, , &block) end |
#router ⇒ Object
206 207 208 |
# File 'lib/active_admin/application.rb', line 206 def router @router ||= Router.new(self) end |
#routes(rails_router) ⇒ Object
210 211 212 213 214 215 216 |
# File 'lib/active_admin/application.rb', line 210 def routes(rails_router) # Ensure that all the configurations (which define the routes) # are all loaded load! router.apply(rails_router) end |
#setup! ⇒ Object
106 107 108 |
# File 'lib/active_admin/application.rb', line 106 def setup! register_default_assets end |
#skip_before_filter(*args, &block) ⇒ Object
233 234 235 |
# File 'lib/active_admin/application.rb', line 233 def skip_before_filter(*args, &block) BaseController.skip_before_filter(*args, &block) end |
#unload! ⇒ Object
Removes all the controllers that were defined by registering resources for administration.
We remove them, then load them on each request in development to allow for changes without having to restart the server.
171 172 173 174 |
# File 'lib/active_admin/application.rb', line 171 def unload! namespaces.values.each{|namespace| namespace.unload! } @@loaded = false end |