Class: ActiveAdmin::Application

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AssetRegistration

#clear_javascripts!, #clear_stylesheets!, #javascripts, #register_javascript, #register_stylesheet, #stylesheets

Methods included from Settings

#read_default_setting

Instance Attribute Details

#admin_notesObject

DEPRECATED: This option is deprecated and will be removed. Use the #allow_comments_in option instead



107
108
109
# File 'lib/active_admin/application.rb', line 107

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

#dashboard_section(name, options = {}, &block) ⇒ Object

Helper method to add a dashboard section



212
213
214
# File 'lib/active_admin/application.rb', line 212

def dashboard_section(name, options = {}, &block)
  ActiveAdmin::Dashboards.add_section(name, options, &block)
end

#filesObject

Returns ALL the files to be loaded



187
188
189
# File 'lib/active_admin/application.rb', line 187

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!`



176
177
178
179
180
181
182
183
184
# File 'lib/active_admin/application.rb', line 176

def load!
  unless loaded?
    ActiveAdmin::Event.dispatch BeforeLoadEvent, self # before_load hook
    files.each{ |file| load file }                    # load files
    namespace(nil)                                    # init AA resources
    ActiveAdmin::Event.dispatch AfterLoadEvent, self  # after_load hook
    @@loaded = true
  end
end

#loaded?Boolean

Whether all configuration files have been loaded



163
164
165
# File 'lib/active_admin/application.rb', line 163

def loaded?
  @@loaded ||= false
end

#namespace(name) {|namespace| ... } ⇒ Object

Creates a namespace for the given name

Yields the namespace if a block is given

Yields:



136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/active_admin/application.rb', line 136

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



119
120
121
122
123
# File 'lib/active_admin/application.rb', line 119

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.



126
127
128
129
# File 'lib/active_admin/application.rb', line 126

def register(resource, options = {}, &block)
  ns_name = namespace_name(options)
  namespace(ns_name).register resource, options, &block
end

#register_page(name, options = {}, &block) ⇒ Object

Register a page

@&block The registration block.



157
158
159
160
# File 'lib/active_admin/application.rb', line 157

def register_page(name, options = {}, &block)
  ns_name = namespace_name(options)
  namespace(ns_name).register_page name, options, &block
end

#routerObject



191
192
193
# File 'lib/active_admin/application.rb', line 191

def router
  @router ||= Router.new(self)
end

#routes(rails_router) ⇒ Object

One-liner called by user’s config/routes.rb file



196
197
198
199
# File 'lib/active_admin/application.rb', line 196

def routes(rails_router)
  load!
  router.apply(rails_router)
end

#setup!Object



115
116
117
# File 'lib/active_admin/application.rb', line 115

def setup!
  register_default_assets
end

#unload!Object

Removes all defined controllers from memory. Useful in development, where they are reloaded on each request.



169
170
171
172
# File 'lib/active_admin/application.rb', line 169

def unload!
  namespaces.values.each{ |namespace| namespace.unload! }
  @@loaded = false
end