Class: ActiveAdmin::Application
- Includes:
- AssetRegistration, Settings
- 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
- #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
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
70 71 72 |
# File 'lib/active_admin/application.rb', line 70 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
65 66 67 |
# File 'lib/active_admin/application.rb', line 65 def admin_notes @admin_notes end |
Instance Method Details
#after_filter(*args, &block) ⇒ Object
176 177 178 |
# File 'lib/active_admin/application.rb', line 176 def after_filter(*args, &block) ResourceController.after_filter(*args, &block) end |
#around_filter(*args, &block) ⇒ Object
180 181 182 |
# File 'lib/active_admin/application.rb', line 180 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!
168 169 170 |
# File 'lib/active_admin/application.rb', line 168 def before_filter(*args, &block) ResourceController.before_filter(*args, &block) end |
#dashboard_section(name, options = {}, &block) ⇒ Object
Helper method to add a dashboard section
185 186 187 |
# File 'lib/active_admin/application.rb', line 185 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
141 142 143 |
# File 'lib/active_admin/application.rb', line 141 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
88 89 90 91 92 93 94 95 |
# File 'lib/active_admin/application.rb', line 88 def find_or_create_namespace(name) name ||= :root 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!
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/active_admin/application.rb', line 124 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
157 158 159 |
# File 'lib/active_admin/application.rb', line 157 def load_default_namespace find_or_create_namespace(default_namespace) end |
#loaded? ⇒ Boolean
Returns true if all the configuration files have been loaded.
102 103 104 |
# File 'lib/active_admin/application.rb', line 102 def loaded? @@loaded end |
#prepare! ⇒ Object
74 75 76 77 78 |
# File 'lib/active_admin/application.rb', line 74 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.
81 82 83 84 85 |
# File 'lib/active_admin/application.rb', line 81 def register(resource, = {}, &block) namespace_name = .has_key?(:namespace) ? [:namespace] : default_namespace namespace = find_or_create_namespace(namespace_name) namespace.register(resource, , &block) end |
#router ⇒ Object
145 146 147 |
# File 'lib/active_admin/application.rb', line 145 def router @router ||= Router.new(self) end |
#routes(rails_router) ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/active_admin/application.rb', line 149 def routes(rails_router) # Ensure that all the configurations (which define the routes) # are all loaded load! router.apply(rails_router) end |
#skip_before_filter(*args, &block) ⇒ Object
172 173 174 |
# File 'lib/active_admin/application.rb', line 172 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.
111 112 113 114 115 |
# File 'lib/active_admin/application.rb', line 111 def unload! namespaces.values.each{|namespace| namespace.unload! } self.namespaces = {} @@loaded = false end |