Class: ActiveAdmin::Resource
- Inherits:
-
Object
- Object
- ActiveAdmin::Resource
- 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/naming.rb,
lib/active_admin/resource/routes.rb,
lib/active_admin/resource/scopes.rb,
lib/active_admin/resource/scope_to.rb,
lib/active_admin/resource/sidebars.rb,
lib/active_admin/resource/belongs_to.rb,
lib/active_admin/resource/pagination.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 collapse
- 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
-
#breadcrumb ⇒ Object
Set breadcrumb builder.
-
#collection_actions ⇒ Object
readonly
An array of collection actions defined for this resource.
-
#csv_builder ⇒ Object
The csv builder for this resource.
-
#decorator_class_name ⇒ Object
The string identifying a class to decorate our resource with for the view.
-
#dsl ⇒ Object
Store a reference to the DSL so that we can dereference it during garbage collection.
-
#member_actions ⇒ Object
readonly
An array of member actions defined for this resource.
-
#namespace ⇒ Object
readonly
The namespace this config belongs to.
-
#resource_class_name ⇒ Object
readonly
The name of the resource class.
- #sort_order ⇒ Object
Attributes included from Pagination
Attributes included from Menu
#menu_item, #navigation_menu_name
Instance Method Summary collapse
- #belongs_to(target, options = {}) ⇒ Object
-
#belongs_to? ⇒ Boolean
Do we belong to another resource?.
- #belongs_to_config ⇒ Object
- #clear_collection_actions! ⇒ Object
-
#clear_member_actions! ⇒ Object
Clears all the member actions this resource knows about.
- #decorator_class ⇒ Object
-
#defined_actions ⇒ Object
Return only defined resource actions.
- #find_resource(id) ⇒ Object
- #resource ⇒ Object deprecated Deprecated.
-
#resource_class ⇒ Object
The class this resource wraps.
- #resource_column_names ⇒ Object
- #resource_quoted_column_name(column) ⇒ Object
- #resource_table_name ⇒ Object
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
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
Methods included from ActionItems
#action_items, #action_items?, #action_items_for, #add_action_item, #clear_action_items!, #initialize
Methods included from Base
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
#breadcrumb ⇒ Object
Set breadcrumb builder
50 51 52 |
# File 'lib/active_admin/resource.rb', line 50 def @breadcrumb end |
#collection_actions ⇒ Object (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 |
#csv_builder ⇒ Object
The csv builder for this resource
137 138 139 |
# File 'lib/active_admin/resource.rb', line 137 def csv_builder @csv_builder || default_csv_builder end |
#decorator_class_name ⇒ Object
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 |
#dsl ⇒ Object
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 |
#member_actions ⇒ Object (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 |
#namespace ⇒ Object (readonly)
The namespace this config belongs to
29 30 31 |
# File 'lib/active_admin/resource.rb', line 29 def namespace @namespace end |
#resource_class_name ⇒ Object (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 |
#sort_order ⇒ Object
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
#belongs_to(target, options = {}) ⇒ Object
121 122 123 124 125 |
# File 'lib/active_admin/resource.rb', line 121 def belongs_to(target, = {}) @belongs_to = Resource::BelongsTo.new(self, target, ) self. = target unless @belongs_to.optional? controller.send :belongs_to, target, .dup end |
#belongs_to? ⇒ Boolean
Do we belong to another resource?
132 133 134 |
# File 'lib/active_admin/resource.rb', line 132 def belongs_to? !!belongs_to_config end |
#belongs_to_config ⇒ Object
127 128 129 |
# File 'lib/active_admin/resource.rb', line 127 def belongs_to_config @belongs_to end |
#clear_collection_actions! ⇒ Object
112 113 114 |
# File 'lib/active_admin/resource.rb', line 112 def clear_collection_actions! @collection_actions = [] end |
#clear_member_actions! ⇒ Object
Clears all the member actions this resource knows about
108 109 110 |
# File 'lib/active_admin/resource.rb', line 108 def clear_member_actions! @member_actions = [] end |
#decorator_class ⇒ Object
91 92 93 |
# File 'lib/active_admin/resource.rb', line 91 def decorator_class ActiveSupport::Dependencies.constantize(decorator_class_name) if decorator_class_name end |
#defined_actions ⇒ Object
Return only defined resource actions
117 118 119 |
# File 'lib/active_admin/resource.rb', line 117 def defined_actions controller.instance_methods.map(&:to_sym) & ResourceController::ACTIVE_ADMIN_ACTIONS end |
#find_resource(id) ⇒ Object
141 142 143 144 |
# File 'lib/active_admin/resource.rb', line 141 def find_resource(id) resource = resource_class.where(resource_class.primary_key => id).first decorator_class ? decorator_class.new(resource) : resource end |
#resource ⇒ Object
147 148 149 |
# File 'lib/active_admin/resource.rb', line 147 def resource resource_class end |
#resource_class ⇒ Object
The class this resource wraps. If you register the Post model, Resource#resource_class will point to the Post class
87 88 89 |
# File 'lib/active_admin/resource.rb', line 87 def resource_class ActiveSupport::Dependencies.constantize(resource_class_name) end |
#resource_column_names ⇒ Object
99 100 101 |
# File 'lib/active_admin/resource.rb', line 99 def resource_column_names resource_class.column_names end |
#resource_quoted_column_name(column) ⇒ Object
103 104 105 |
# File 'lib/active_admin/resource.rb', line 103 def resource_quoted_column_name(column) resource_class.connection.quote_column_name(column) end |
#resource_table_name ⇒ Object
95 96 97 |
# File 'lib/active_admin/resource.rb', line 95 def resource_table_name resource_class.quoted_table_name end |