Class: Admin::Base::Resource
- Inherits:
-
Object
- Object
- Admin::Base::Resource
- Extended by:
- AdminSuite::Deprecation
- Defined in:
- lib/admin/base/resource.rb
Overview
Base class for admin resource definitions
Provides a declarative DSL for defining admin resources with:
- Index configuration (columns, filters, search, sort, stats)
- Form configuration (fields with various types)
- Actions (single and bulk)
- Show page sections
- Export capabilities
Defined Under Namespace
Classes: ActionDefinition, ActionsConfig, ColumnDefinition, ColumnsBuilder, FieldDefinition, FilterDefinition, FiltersBuilder, FormConfig, IndexConfig, RowDefinition, SectionDefinition, ShowConfig, ShowSectionDefinition, StatDefinition, StatsBuilder
Constant Summary collapse
- SectionEnd =
Class.new
- RowEnd =
Class.new
Class Attribute Summary collapse
-
.actions_config ⇒ Object
readonly
Actions configuration.
-
.form_config ⇒ Object
readonly
Form configuration.
-
.index_config ⇒ Object
readonly
Index configuration.
-
.model_class ⇒ Object
readonly
Model configuration.
-
.nav_icon ⇒ Object
readonly
Model configuration.
-
.nav_label ⇒ Object
readonly
Model configuration.
-
.nav_order ⇒ Object
readonly
Model configuration.
-
.portal_name ⇒ Object
readonly
Model configuration.
-
.section_name ⇒ Object
readonly
Model configuration.
-
.show_config ⇒ Object
readonly
Show configuration.
Class Method Summary collapse
-
.actions { ... } ⇒ void
Configures actions.
-
.form { ... } ⇒ void
Configures the form (new/edit).
-
.human_name ⇒ String
Returns the human-readable name.
-
.human_name_plural ⇒ String
Returns the human-readable plural name.
-
.icon(name = nil) ⇒ String, ...
Convenience setter/getter for nav icon.
-
.index { ... } ⇒ void
Configures the index view.
-
.inherited(subclass) ⇒ Object
Called when a subclass is created.
-
.label(name = nil) ⇒ String?
Convenience setter/getter for nav label.
-
.mcp(enabled) ⇒ Object
Opts this resource out of the model-facing MCP surface.
- .mcp_enabled? ⇒ Boolean
-
.model(klass) ⇒ void
Sets the model class for this resource.
-
.nav(label: nil, icon: nil, order: nil) ⇒ void
Navigation metadata for this resource.
-
.order(value = nil) ⇒ Integer?
Convenience setter/getter for nav order.
-
.portal(name) ⇒ void
Sets the portal this resource belongs to.
-
.read_only(value = true) ⇒ Object
Declares whether the generic resource routes may mutate records.
- .read_only? ⇒ Boolean
-
.registered_resources ⇒ Array<Class>
Returns all registered resources.
-
.reset_registry! ⇒ void
Clears the registry (useful for development reloads).
-
.resource_name ⇒ String
Returns the resource name derived from class name.
-
.resource_name_plural ⇒ String
Returns the plural resource name.
-
.resources_for_portal(portal) ⇒ Array<Class>
Returns resources for a specific portal.
-
.resources_for_section(portal, section) ⇒ Array<Class>
Returns resources for a specific section.
-
.section(name) ⇒ void
Sets the section within the portal.
-
.show { ... } ⇒ void
Configures the show view.
Methods included from AdminSuite::Deprecation
reset_deprecation_notices!, warn_once, warn_once_sink
Class Attribute Details
.actions_config ⇒ Object (readonly)
Actions configuration
58 59 60 |
# File 'lib/admin/base/resource.rb', line 58 def actions_config @actions_config end |
.form_config ⇒ Object (readonly)
Form configuration
52 53 54 |
# File 'lib/admin/base/resource.rb', line 52 def form_config @form_config end |
.index_config ⇒ Object (readonly)
Index configuration
49 50 51 |
# File 'lib/admin/base/resource.rb', line 49 def index_config @index_config end |
.model_class ⇒ Object (readonly)
Model configuration
46 47 48 |
# File 'lib/admin/base/resource.rb', line 46 def model_class @model_class end |
.nav_icon ⇒ Object (readonly)
Model configuration
46 47 48 |
# File 'lib/admin/base/resource.rb', line 46 def nav_icon @nav_icon end |
.nav_label ⇒ Object (readonly)
Model configuration
46 47 48 |
# File 'lib/admin/base/resource.rb', line 46 def nav_label @nav_label end |
.nav_order ⇒ Object (readonly)
Model configuration
46 47 48 |
# File 'lib/admin/base/resource.rb', line 46 def nav_order @nav_order end |
.portal_name ⇒ Object (readonly)
Model configuration
46 47 48 |
# File 'lib/admin/base/resource.rb', line 46 def portal_name @portal_name end |
.section_name ⇒ Object (readonly)
Model configuration
46 47 48 |
# File 'lib/admin/base/resource.rb', line 46 def section_name @section_name end |
.show_config ⇒ Object (readonly)
Show configuration
55 56 57 |
# File 'lib/admin/base/resource.rb', line 55 def show_config @show_config end |
Class Method Details
.actions { ... } ⇒ void
This method returns an undefined value.
Configures actions
154 155 156 157 |
# File 'lib/admin/base/resource.rb', line 154 def actions(&block) @actions_config = ActionsConfig.new @actions_config.instance_eval(&block) if block_given? end |
.form { ... } ⇒ void
This method returns an undefined value.
Configures the form (new/edit)
136 137 138 139 |
# File 'lib/admin/base/resource.rb', line 136 def form(&block) @form_config = FormConfig.new @form_config.instance_eval(&block) if block_given? end |
.human_name ⇒ String
Returns the human-readable name
196 197 198 |
# File 'lib/admin/base/resource.rb', line 196 def human_name model_class&.model_name&.human || resource_name.humanize end |
.human_name_plural ⇒ String
Returns the human-readable plural name
203 204 205 |
# File 'lib/admin/base/resource.rb', line 203 def human_name_plural model_class&.model_name&.human(count: 2) || resource_name.pluralize.humanize end |
.icon(name = nil) ⇒ String, ...
Convenience setter/getter for nav icon.
100 101 102 103 |
# File 'lib/admin/base/resource.rb', line 100 def icon(name = nil) @nav_icon = name if name.present? @nav_icon end |
.index { ... } ⇒ void
This method returns an undefined value.
Configures the index view
127 128 129 130 |
# File 'lib/admin/base/resource.rb', line 127 def index(&block) @index_config = IndexConfig.new @index_config.instance_eval(&block) if block_given? end |
.inherited(subclass) ⇒ Object
Called when a subclass is created
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/admin/base/resource.rb', line 222 def inherited(subclass) super return if subclass.name&.include?("Base") existing_idx = registered_resources.index { |r| r.name == subclass.name } if existing_idx registered_resources[existing_idx] = subclass else registered_resources << subclass end end |
.label(name = nil) ⇒ String?
Convenience setter/getter for nav label.
109 110 111 112 |
# File 'lib/admin/base/resource.rb', line 109 def label(name = nil) @nav_label = name if name.present? @nav_label end |
.mcp(enabled) ⇒ Object
Opts this resource out of the model-facing MCP surface.
171 172 173 |
# File 'lib/admin/base/resource.rb', line 171 def mcp(enabled) @mcp_enabled = enabled end |
.mcp_enabled? ⇒ Boolean
175 176 177 |
# File 'lib/admin/base/resource.rb', line 175 def mcp_enabled? @mcp_enabled.nil? ? true : !!@mcp_enabled end |
.model(klass) ⇒ void
This method returns an undefined value.
Sets the model class for this resource
64 65 66 |
# File 'lib/admin/base/resource.rb', line 64 def model(klass) @model_class = klass end |
.nav(label: nil, icon: nil, order: nil) ⇒ void
This method returns an undefined value.
Navigation metadata for this resource.
90 91 92 93 94 |
# File 'lib/admin/base/resource.rb', line 90 def nav(label: nil, icon: nil, order: nil) @nav_label = label if label.present? @nav_icon = icon if icon.present? @nav_order = order unless order.nil? end |
.order(value = nil) ⇒ Integer?
Convenience setter/getter for nav order.
118 119 120 121 |
# File 'lib/admin/base/resource.rb', line 118 def order(value = nil) @nav_order = value unless value.nil? @nav_order end |
.portal(name) ⇒ void
This method returns an undefined value.
Sets the portal this resource belongs to
72 73 74 |
# File 'lib/admin/base/resource.rb', line 72 def portal(name) @portal_name = name end |
.read_only(value = true) ⇒ Object
Declares whether the generic resource routes may mutate records. Read-only resources retain index/show access while the controller rejects direct requests to every built-in mutation endpoint.
162 163 164 |
# File 'lib/admin/base/resource.rb', line 162 def read_only(value = true) @read_only = value end |
.read_only? ⇒ Boolean
166 167 168 |
# File 'lib/admin/base/resource.rb', line 166 def read_only? @read_only == true end |
.registered_resources ⇒ Array<Class>
Returns all registered resources
210 211 212 |
# File 'lib/admin/base/resource.rb', line 210 def registered_resources @registered_resources ||= [] end |
.reset_registry! ⇒ void
This method returns an undefined value.
Clears the registry (useful for development reloads).
217 218 219 |
# File 'lib/admin/base/resource.rb', line 217 def reset_registry! @registered_resources = [] end |
.resource_name ⇒ String
Returns the resource name derived from class name
182 183 184 |
# File 'lib/admin/base/resource.rb', line 182 def resource_name name.demodulize.sub(/Resource$/, "").underscore end |
.resource_name_plural ⇒ String
Returns the plural resource name
189 190 191 |
# File 'lib/admin/base/resource.rb', line 189 def resource_name_plural resource_name.pluralize end |
.resources_for_portal(portal) ⇒ Array<Class>
Returns resources for a specific portal
238 239 240 |
# File 'lib/admin/base/resource.rb', line 238 def resources_for_portal(portal) registered_resources.select { |r| r.portal_name == portal } end |
.resources_for_section(portal, section) ⇒ Array<Class>
Returns resources for a specific section
247 248 249 |
# File 'lib/admin/base/resource.rb', line 247 def resources_for_section(portal, section) registered_resources.select { |r| r.portal_name == portal && r.section_name == section } end |
.section(name) ⇒ void
This method returns an undefined value.
Sets the section within the portal
80 81 82 |
# File 'lib/admin/base/resource.rb', line 80 def section(name) @section_name = name end |
.show { ... } ⇒ void
This method returns an undefined value.
Configures the show view
145 146 147 148 |
# File 'lib/admin/base/resource.rb', line 145 def show(&block) @show_config = ShowConfig.new @show_config.instance_eval(&block) if block_given? end |