Class: ActiveAdmin::Application

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

Instance Method Summary collapse

Methods included from AssetRegistration

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

Constructor Details

#initializeApplication

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_notesObject

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, options = {}, &block)
  ActiveAdmin::Dashboards.add_section(name, options, &block)
end

#files_in_load_pathObject

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.load_menu! }

  @@loaded = true
end

#load_default_namespaceObject



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.

Returns:

  • (Boolean)


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, options = {}, &block)
  namespace_name = options.has_key?(:namespace) ? options[:namespace] : default_namespace
  namespace = find_or_create_namespace(namespace_name)
  namespace.register(resource, options, &block)
end

#routerObject



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