Class: ActiveAdmin::Application
- Inherits:
-
Object
- Object
- ActiveAdmin::Application
- Includes:
- AssetRegistration, Settings
- Defined in:
- lib/active_admin/application.rb
Constant Summary collapse
- LoadEvent =
Event that gets triggered on load of Active Admin
'active_admin.application.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
-
.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.
-
#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
Instance Attribute Details
#admin_notes ⇒ Object
DEPRECATED: This option is deprecated and will be removed. Use the #allow_comments_in option instead
78 79 80 |
# File 'lib/active_admin/application.rb', line 78 def admin_notes @admin_notes end |
Class Method Details
.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
211 212 213 |
# File 'lib/active_admin/application.rb', line 211 def after_filter(*args, &block) ResourceController.after_filter(*args, &block) end |
#around_filter(*args, &block) ⇒ Object
215 216 217 |
# File 'lib/active_admin/application.rb', line 215 def around_filter(*args, &block) ResourceController.around_filter(*args, &block) end |
#before_filter(*args, &block) ⇒ Object
Add before, around and after filters to each registered resource.
eg:
ActiveAdmin.before_filter :authenticate_admin!
203 204 205 |
# File 'lib/active_admin/application.rb', line 203 def before_filter(*args, &block) ResourceController.before_filter(*args, &block) end |
#dashboard_section(name, options = {}, &block) ⇒ Object
Helper method to add a dashboard section
220 221 222 |
# File 'lib/active_admin/application.rb', line 220 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
176 177 178 |
# File 'lib/active_admin/application.rb', line 176 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
107 108 109 110 111 112 113 114 115 |
# File 'lib/active_admin/application.rb', line 107 def find_or_create_namespace(name) name ||= :root return namespaces[name] if namespaces[name] namespace = Namespace.new(self, name) namespaces[name] = namespace ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace 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!
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/active_admin/application.rb', line 156 def load! # No work to do if we've already loaded return false if loaded? # 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? # Load Menus namespaces.values.each{|namespace| namespace. } # Dispatch an ActiveAdmin::Application::LoadEvent with the Application ActiveAdmin::Event.dispatch LoadEvent, self @@loaded = true end |
#load_default_namespace ⇒ Object
192 193 194 |
# File 'lib/active_admin/application.rb', line 192 def load_default_namespace find_or_create_namespace(default_namespace) end |
#loaded? ⇒ Boolean
Returns true if all the configuration files have been loaded.
135 136 137 |
# File 'lib/active_admin/application.rb', line 135 def loaded? @@loaded end |
#prepare! ⇒ Object
89 90 91 92 93 |
# File 'lib/active_admin/application.rb', line 89 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.
96 97 98 99 100 |
# File 'lib/active_admin/application.rb', line 96 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.
125 126 127 128 129 |
# File 'lib/active_admin/application.rb', line 125 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
180 181 182 |
# File 'lib/active_admin/application.rb', line 180 def router @router ||= Router.new(self) end |
#routes(rails_router) ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/active_admin/application.rb', line 184 def routes(rails_router) # Ensure that all the configurations (which define the routes) # are all loaded load! router.apply(rails_router) end |
#setup! ⇒ Object
85 86 87 |
# File 'lib/active_admin/application.rb', line 85 def setup! register_default_assets end |
#skip_before_filter(*args, &block) ⇒ Object
207 208 209 |
# File 'lib/active_admin/application.rb', line 207 def skip_before_filter(*args, &block) ResourceController.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.
144 145 146 147 |
# File 'lib/active_admin/application.rb', line 144 def unload! namespaces.values.each{|namespace| namespace.unload! } @@loaded = false end |