Class: ActiveAdmin::Resource

Inherits:
Object
  • Object
show all
Includes:
Authorization, ActionItems, Base, Controllers, Menu, Naming, PagePresenters, Pagination, Routes, ScopeTo, Scopes, Sidebars, MethodOrProcHelper
Defined in:
lib/active_admin/resource.rb,
lib/active_admin/resource/menu.rb,
lib/active_admin/resource/scopes.rb,
lib/active_admin/resource/routes.rb,
lib/active_admin/resource/naming.rb,
lib/active_admin/resource/sidebars.rb,
lib/active_admin/resource/scope_to.rb,
lib/active_admin/resource/pagination.rb,
lib/active_admin/resource/belongs_to.rb,
lib/active_admin/resource/controllers.rb,
lib/active_admin/resource/action_items.rb,
lib/active_admin/resource/page_presenters.rb

Overview

Resource is the primary data storage for resource configuration in Active Admin

When you register a resource (ActiveAdmin.register Post) you are actually creating a new Resource instance within the given Namespace.

The instance of the current resource is available in ResourceController and views by calling the #active_admin_config method.

Defined Under Namespace

Modules: ActionItems, Base, Controllers, Menu, Naming, PagePresenters, Pagination, Routes, ScopeTo, Scopes, Sidebars Classes: BelongsTo, Name

Constant Summary

RegisterEvent =

Event dispatched when a new resource is registered

'active_admin.resource.register'.freeze

Constants included from Authorization

Authorization::CREATE, Authorization::DESTROY, Authorization::READ, Authorization::UPDATE

Instance Attribute Summary (collapse)

Attributes included from Pagination

#paginate, #per_page

Attributes included from Menu

#menu_item, #navigation_menu_name

Instance Method Summary (collapse)

Methods included from Routes

#route_collection_path, #route_instance_path, #route_prefix, #route_uncountable?

Methods included from Sidebars

#clear_sidebar_sections!, #sidebar_sections, #sidebar_sections?, #sidebar_sections_for

Methods included from ScopeTo

#scope_to, #scope_to?, #scope_to_association_method, #scope_to_config, #scope_to_method

Methods included from Scopes

#default_scope, #get_scope_by_id, #scope, #scopes

Methods included from Pagination

#initialize

Methods included from PagePresenters

#default_index_class, #find_index_class, #get_page_presenter, #page_presenters, #set_index_presenter, #set_page_presenter

Methods included from Naming

#plural_resource_label, #resource_label, #resource_name

Methods included from Menu

#add_to_menu, #default_menu_options, #include_in_menu?, #menu_item_options, #menu_item_options=, #navigation_menu

Methods included from Controllers

#controller, #controller_name

Methods included from ActionItems

#action_items, #action_items?, #action_items_for, #add_action_item, #clear_action_items!, #initialize

Methods included from Base

#initialize

Methods included from MethodOrProcHelper

#call_method_or_exec_proc, #call_method_or_proc_on, #render_in_context, #render_or_call_method_or_proc_on

Instance Attribute Details



140
141
142
# File 'lib/active_admin/resource.rb', line 140

def breadcrumb
  instance_variable_defined?(:@breadcrumb) ? @breadcrumb : namespace.breadcrumb
end

- (Object) collection_actions (readonly)

An array of collection actions defined for this resource



38
39
40
# File 'lib/active_admin/resource.rb', line 38

def collection_actions
  @collection_actions
end

- (Object) csv_builder

The csv builder for this resource



136
137
138
# File 'lib/active_admin/resource.rb', line 136

def csv_builder
  @csv_builder || default_csv_builder
end

- (Object) decorator_class_name

The string identifying a class to decorate our resource with for the view. nil to not decorate.



57
58
59
# File 'lib/active_admin/resource.rb', line 57

def decorator_class_name
  @decorator_class_name
end

- (Object) dsl

Store a reference to the DSL so that we can dereference it during garbage collection.



53
54
55
# File 'lib/active_admin/resource.rb', line 53

def dsl
  @dsl
end

- (Object) member_actions (readonly)

An array of member actions defined for this resource



35
36
37
# File 'lib/active_admin/resource.rb', line 35

def member_actions
  @member_actions
end

- (Object) namespace (readonly)

The namespace this config belongs to



29
30
31
# File 'lib/active_admin/resource.rb', line 29

def namespace
  @namespace
end

- (Object) resource_class_name (readonly)

The name of the resource class



32
33
34
# File 'lib/active_admin/resource.rb', line 32

def resource_class_name
  @resource_class_name
end

- (Object) sort_order



42
43
44
# File 'lib/active_admin/resource.rb', line 42

def sort_order
  @sort_order ||= (resource_class.respond_to?(:primary_key) ? resource_class.primary_key.to_s : 'id') + '_desc'
end

Instance Method Details

- (Object) belongs_to(target, options = {})



120
121
122
123
124
# File 'lib/active_admin/resource.rb', line 120

def belongs_to(target, options = {})
  @belongs_to = Resource::BelongsTo.new(self, target, options)
  self.navigation_menu_name = target unless @belongs_to.optional?
  controller.send :belongs_to, target, options.dup
end

- (Boolean) belongs_to?

Do we belong to another resource?

Returns:

  • (Boolean)


131
132
133
# File 'lib/active_admin/resource.rb', line 131

def belongs_to?
  !!belongs_to_config
end

- (Object) belongs_to_config



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

def belongs_to_config
  @belongs_to
end

- (Object) clear_collection_actions!



111
112
113
# File 'lib/active_admin/resource.rb', line 111

def clear_collection_actions!
  @collection_actions = []
end

- (Object) clear_member_actions!

Clears all the member actions this resource knows about



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

def clear_member_actions!
  @member_actions = []
end

- (Object) decorator_class



90
91
92
# File 'lib/active_admin/resource.rb', line 90

def decorator_class
  ActiveSupport::Dependencies.constantize(decorator_class_name) if decorator_class_name
end

- (Object) defined_actions

Return only defined resource actions



116
117
118
# File 'lib/active_admin/resource.rb', line 116

def defined_actions
  controller.instance_methods.map(&:to_sym) & ResourceController::ACTIVE_ADMIN_ACTIONS
end

- (Object) find_resource(id)



144
145
146
147
# File 'lib/active_admin/resource.rb', line 144

def find_resource(id)
  resource = resource_class.where(resource_class.primary_key => id).first
  decorator_class ? decorator_class.new(resource) : resource
end

- (Object) resource_class

The class this resource wraps. If you register the Post model, Resource#resource_class will point to the Post class



86
87
88
# File 'lib/active_admin/resource.rb', line 86

def resource_class
  ActiveSupport::Dependencies.constantize(resource_class_name)
end

- (Object) resource_column_names



98
99
100
# File 'lib/active_admin/resource.rb', line 98

def resource_column_names
  resource_class.column_names
end

- (Object) resource_quoted_column_name(column)



102
103
104
# File 'lib/active_admin/resource.rb', line 102

def resource_quoted_column_name(column)
  resource_class.connection.quote_column_name(column)
end

- (Object) resource_table_name



94
95
96
# File 'lib/active_admin/resource.rb', line 94

def resource_table_name
  resource_class.quoted_table_name
end