Class: Admin::Base::Resource
- Inherits:
-
Object
- Object
- Admin::Base::Resource
- 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.
-
.export_formats ⇒ Object
readonly
Export 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.
-
.exportable(*formats) ⇒ void
Configures export formats.
-
.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.
-
.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.
-
.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.
Class Attribute Details
.actions_config ⇒ Object (readonly)
Actions configuration
56 57 58 |
# File 'lib/admin/base/resource.rb', line 56 def actions_config @actions_config end |
.export_formats ⇒ Object (readonly)
Export configuration
59 60 61 |
# File 'lib/admin/base/resource.rb', line 59 def export_formats @export_formats end |
.form_config ⇒ Object (readonly)
Form configuration
50 51 52 |
# File 'lib/admin/base/resource.rb', line 50 def form_config @form_config end |
.index_config ⇒ Object (readonly)
Index configuration
47 48 49 |
# File 'lib/admin/base/resource.rb', line 47 def index_config @index_config end |
.model_class ⇒ Object (readonly)
Model configuration
44 45 46 |
# File 'lib/admin/base/resource.rb', line 44 def model_class @model_class end |
.nav_icon ⇒ Object (readonly)
Model configuration
44 45 46 |
# File 'lib/admin/base/resource.rb', line 44 def nav_icon @nav_icon end |
.nav_label ⇒ Object (readonly)
Model configuration
44 45 46 |
# File 'lib/admin/base/resource.rb', line 44 def nav_label @nav_label end |
.nav_order ⇒ Object (readonly)
Model configuration
44 45 46 |
# File 'lib/admin/base/resource.rb', line 44 def nav_order @nav_order end |
.portal_name ⇒ Object (readonly)
Model configuration
44 45 46 |
# File 'lib/admin/base/resource.rb', line 44 def portal_name @portal_name end |
.section_name ⇒ Object (readonly)
Model configuration
44 45 46 |
# File 'lib/admin/base/resource.rb', line 44 def section_name @section_name end |
.show_config ⇒ Object (readonly)
Show configuration
53 54 55 |
# File 'lib/admin/base/resource.rb', line 53 def show_config @show_config end |
Class Method Details
.actions { ... } ⇒ void
This method returns an undefined value.
Configures actions
155 156 157 158 |
# File 'lib/admin/base/resource.rb', line 155 def actions(&block) @actions_config = ActionsConfig.new @actions_config.instance_eval(&block) if block_given? end |
.exportable(*formats) ⇒ void
This method returns an undefined value.
Configures export formats
164 165 166 |
# File 'lib/admin/base/resource.rb', line 164 def exportable(*formats) @export_formats = formats end |
.form { ... } ⇒ void
This method returns an undefined value.
Configures the form (new/edit)
137 138 139 140 |
# File 'lib/admin/base/resource.rb', line 137 def form(&block) @form_config = FormConfig.new @form_config.instance_eval(&block) if block_given? end |
.human_name ⇒ String
Returns the human-readable name
185 186 187 |
# File 'lib/admin/base/resource.rb', line 185 def human_name model_class&.model_name&.human || resource_name.humanize end |
.human_name_plural ⇒ String
Returns the human-readable plural name
192 193 194 |
# File 'lib/admin/base/resource.rb', line 192 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.
101 102 103 104 |
# File 'lib/admin/base/resource.rb', line 101 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
128 129 130 131 |
# File 'lib/admin/base/resource.rb', line 128 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
211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/admin/base/resource.rb', line 211 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.
110 111 112 113 |
# File 'lib/admin/base/resource.rb', line 110 def label(name = nil) @nav_label = name if name.present? @nav_label end |
.model(klass) ⇒ void
This method returns an undefined value.
Sets the model class for this resource
65 66 67 |
# File 'lib/admin/base/resource.rb', line 65 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.
91 92 93 94 95 |
# File 'lib/admin/base/resource.rb', line 91 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.
119 120 121 122 |
# File 'lib/admin/base/resource.rb', line 119 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
73 74 75 |
# File 'lib/admin/base/resource.rb', line 73 def portal(name) @portal_name = name end |
.registered_resources ⇒ Array<Class>
Returns all registered resources
199 200 201 |
# File 'lib/admin/base/resource.rb', line 199 def registered_resources @registered_resources ||= [] end |
.reset_registry! ⇒ void
This method returns an undefined value.
Clears the registry (useful for development reloads).
206 207 208 |
# File 'lib/admin/base/resource.rb', line 206 def reset_registry! @registered_resources = [] end |
.resource_name ⇒ String
Returns the resource name derived from class name
171 172 173 |
# File 'lib/admin/base/resource.rb', line 171 def resource_name name.demodulize.sub(/Resource$/, "").underscore end |
.resource_name_plural ⇒ String
Returns the plural resource name
178 179 180 |
# File 'lib/admin/base/resource.rb', line 178 def resource_name_plural resource_name.pluralize end |
.resources_for_portal(portal) ⇒ Array<Class>
Returns resources for a specific portal
227 228 229 |
# File 'lib/admin/base/resource.rb', line 227 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
236 237 238 |
# File 'lib/admin/base/resource.rb', line 236 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
81 82 83 |
# File 'lib/admin/base/resource.rb', line 81 def section(name) @section_name = name end |
.show { ... } ⇒ void
This method returns an undefined value.
Configures the show view
146 147 148 149 |
# File 'lib/admin/base/resource.rb', line 146 def show(&block) @show_config = ShowConfig.new @show_config.instance_eval(&block) if block_given? end |