Class: ActiveAdmin::Application
- Includes:
- AssetRegistration
- Defined in:
- lib/active_admin/application.rb
Constant Summary collapse
- @@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.
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) ⇒ Object
Creates a namespace for the given name.
-
#initialize ⇒ Application
constructor
A new instance of Application.
-
#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.
- #router ⇒ Object
- #routes(rails_router) ⇒ 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
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
60 61 62 |
# File 'lib/active_admin/application.rb', line 60 def initialize register_default_assets end |
Instance Attribute Details
#admin_notes ⇒ Object
DEPRECATED: This option is deprecated and will be removed. Use the #allow_comments_in option instead
36 37 38 |
# File 'lib/active_admin/application.rb', line 36 def admin_notes @admin_notes end |
Instance Method Details
#after_filter(*args, &block) ⇒ Object
161 162 163 |
# File 'lib/active_admin/application.rb', line 161 def after_filter(*args, &block) ResourceController.after_filter(*args, &block) end |
#around_filter(*args, &block) ⇒ Object
165 166 167 |
# File 'lib/active_admin/application.rb', line 165 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!
157 158 159 |
# File 'lib/active_admin/application.rb', line 157 def before_filter(*args, &block) ResourceController.before_filter(*args, &block) end |
#dashboard_section(name, options = {}, &block) ⇒ Object
Helper method to add a dashboard section
170 171 172 |
# File 'lib/active_admin/application.rb', line 170 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
130 131 132 |
# File 'lib/active_admin/application.rb', line 130 def files_in_load_path load_paths.flatten.compact.uniq.collect{|path| Dir["#{path}/**/*.rb"] }.flatten end |
#find_or_create_namespace(name) ⇒ Object
Creates a namespace for the given name
78 79 80 81 82 83 84 |
# File 'lib/active_admin/application.rb', line 78 def find_or_create_namespace(name) return namespaces[name] if namespaces[name] namespace = Namespace.new(self, name) ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace namespaces[name] = namespace 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!
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/active_admin/application.rb', line 113 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. } @@loaded = true end |
#load_default_namespace ⇒ Object
146 147 148 |
# File 'lib/active_admin/application.rb', line 146 def load_default_namespace find_or_create_namespace(default_namespace) end |
#loaded? ⇒ Boolean
Returns true if all the configuration files have been loaded.
91 92 93 |
# File 'lib/active_admin/application.rb', line 91 def loaded? @@loaded end |
#prepare! ⇒ Object
64 65 66 67 68 |
# File 'lib/active_admin/application.rb', line 64 def prepare! remove_active_admin_load_paths_from_rails_autoload_and_eager_load append_active_admin_views_path generate_stylesheets end |
#register(resource, options = {}, &block) ⇒ Object
Registers a brand new configuration for the given resource.
71 72 73 74 75 |
# File 'lib/active_admin/application.rb', line 71 def register(resource, = {}, &block) namespace_name = [:namespace] == false ? :root : ([:namespace] || default_namespace || :root) namespace = find_or_create_namespace(namespace_name) namespace.register(resource, , &block) end |
#router ⇒ Object
134 135 136 |
# File 'lib/active_admin/application.rb', line 134 def router @router ||= Router.new(self) end |
#routes(rails_router) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/active_admin/application.rb', line 138 def routes(rails_router) # Ensure that all the configurations (which define the routes) # are all loaded load! router.apply(rails_router) 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.
100 101 102 103 104 |
# File 'lib/active_admin/application.rb', line 100 def unload! namespaces.values.each{|namespace| namespace.unload! } self.namespaces = {} @@loaded = false end |