Class: Plutonium::Definition::Base Abstract
- Inherits:
-
Object
- Object
- Plutonium::Definition::Base
- Includes:
- Actions, ConfigAttr, DefineableProps, DisplayLayout, FormLayout, IndexViews, InheritableConfigAttr, Metadata, NestedInputs, PageWidths, Scoping, Search, Sorting, StructuredInputs, Wizards, Positioning
- Defined in:
- lib/plutonium/definition/base.rb
Overview
Subclass and override #customize_fields, #customize_inputs, #customize_filters, #customize_scopes, and #customize_sorters to implement custom behavior.
This class is not thread-safe. Ensure proper synchronization if used in a multi-threaded environment.
Base class for Plutonium definitions
Direct Known Subclasses
Defined Under Namespace
Classes: Display, EditPage, Form, Grid, IndexPage, InteractiveActionPage, NewPage, QueryForm, ShowPage, Table, TextFilter
Constant Summary collapse
- VALID_MODAL_MODES =
modals — drive how :new / :edit and interactive actions render. Actions read these lazily at render time, so override order and subclass inheritance both work naturally.
[:centered, :slideover, false].freeze
- VALID_SHOW_IN =
show_in — how the :show page opens from a record link (table row, grid card). Unlike :new/:edit (which follow
modal_mode), the show page is ALWAYS centered when shown in a modal, so this is just a modal/page switch — not a style.:page (default) — full-page navigation to the show route :modal — open the show page in a centered dialogThe kanban board has its own
show_inthat overrides this per-board. [:modal, :page].freeze
Constants included from IndexViews
IndexViews::GRID_LAYOUTS, IndexViews::GRID_SLOTS, IndexViews::KNOWN_VIEWS
Constants included from FormLayout
Constants included from Positioning
Constants included from Sorting
Class Method Summary collapse
-
.modal(mode, size: :md) ⇒ Object
Sets
modal_modeandmodal_sizetogether with validation. -
.model_class ⇒ Object
The model this definition describes — the inverse of the
"#{resource_class}Definition"lookup controllers do (Plutonium::Resource::Controller#resource_definition). -
.show_in(value = :__not_set__) ⇒ Object
Validated setter — raises on an unknown mode rather than silently falling back, matching the kanban board's
show_in.
Instance Method Summary collapse
- #collection_class ⇒ Object
- #detail_class ⇒ Object
- #edit_page_class ⇒ Object
- #form_class ⇒ Object
- #grid_class ⇒ Object
- #index_page_class ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #interactive_action_page_class ⇒ Object
- #model_class ⇒ Object
- #new_page_class ⇒ Object
- #query_form ⇒ Object
- #show_page_class ⇒ Object
Methods included from Metadata
Methods included from IndexViews
#default_index_view, #defined_grid_columns, #defined_grid_fields, #defined_grid_layout, #defined_index_views, #defined_kanban_block, #defined_kanban_board
Methods included from PageWidths
#display_width_classes, #form_width_classes, #resolved_display_width, #resolved_form_width
Methods included from DisplayLayout
#defined_display_layout, #resolve_display_sections
Methods included from FormLayout
assign_ownership, #defined_form_layout, #resolve_form_sections, resolve_sections
Methods included from StructuredInputs
Methods included from Search
Methods included from Scoping
Methods included from Positioning
gap_exhausted?, position_between
Methods included from Sorting
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
199 200 201 |
# File 'lib/plutonium/definition/base.rb', line 199 def initialize super end |
Class Method Details
.modal(mode, size: :md) ⇒ Object
Sets modal_mode and modal_size together with validation.
- :slideover (default) — slide-in panel from the right
- :centered — centered dialog
- false — no modal; new/edit are full standalone pages
size: see Plutonium::UI::Modal::Base::VALID_SIZES. :auto
hugs the form's natural width.
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/plutonium/definition/base.rb', line 117 def self.modal(mode, size: :md) unless VALID_MODAL_MODES.include?(mode) raise ArgumentError, "modal must be one of #{VALID_MODAL_MODES.inspect}, got #{mode.inspect}" end unless Plutonium::UI::Modal::Base::VALID_SIZES.include?(size) raise ArgumentError, "modal size must be one of #{Plutonium::UI::Modal::Base::VALID_SIZES.inspect}, got #{size.inspect}" end modal_mode mode modal_size size end |
.model_class ⇒ Object
The model this definition describes — the inverse of the
"#{resource_class}Definition" lookup controllers do
(Plutonium::Resource::Controller#resource_definition).
A definition is frequently namespaced under a package or portal that
the model is NOT (AdminPortal::Blogging::TutorialDefinition describes
Blogging::Tutorial), so leading namespace segments are dropped one at
a time until an ActiveRecord model resolves.
One case is genuinely unresolvable by name alone: Admin::UserDefinition
where BOTH Admin::User and ::User are models. Innermost wins, since a
namespaced definition most often describes the namespaced model — if that
is the wrong guess, override model_class on the definition.
Resolved lazily and memoized: it constantizes the model, and a definition class body must stay loadable without forcing that.
169 170 171 |
# File 'lib/plutonium/definition/base.rb', line 169 def self.model_class @model_class ||= infer_model_class end |
.show_in(value = :__not_set__) ⇒ Object
Validated setter — raises on an unknown mode rather than silently
falling back, matching the kanban board's show_in.
145 146 147 148 149 150 151 |
# File 'lib/plutonium/definition/base.rb', line 145 def self.show_in(value = :__not_set__) return show_in_config if value == :__not_set__ unless VALID_SHOW_IN.include?(value) raise ArgumentError, "show_in must be one of #{VALID_SHOW_IN.inspect}, got #{value.inspect}" end self.show_in_config = value end |
Instance Method Details
#collection_class ⇒ Object
227 228 229 |
# File 'lib/plutonium/definition/base.rb', line 227 def collection_class self.class::Table end |
#detail_class ⇒ Object
235 236 237 |
# File 'lib/plutonium/definition/base.rb', line 235 def detail_class self.class::Display end |
#edit_page_class ⇒ Object
215 216 217 |
# File 'lib/plutonium/definition/base.rb', line 215 def edit_page_class self.class::EditPage end |
#form_class ⇒ Object
223 224 225 |
# File 'lib/plutonium/definition/base.rb', line 223 def form_class self.class::Form end |
#grid_class ⇒ Object
231 232 233 |
# File 'lib/plutonium/definition/base.rb', line 231 def grid_class self.class::Grid end |
#index_page_class ⇒ Object
203 204 205 |
# File 'lib/plutonium/definition/base.rb', line 203 def index_page_class self.class::IndexPage end |
#interactive_action_page_class ⇒ Object
219 220 221 |
# File 'lib/plutonium/definition/base.rb', line 219 def interactive_action_page_class self.class::InteractiveActionPage end |
#model_class ⇒ Object
197 |
# File 'lib/plutonium/definition/base.rb', line 197 def model_class = self.class.model_class |
#new_page_class ⇒ Object
207 208 209 |
# File 'lib/plutonium/definition/base.rb', line 207 def new_page_class self.class::NewPage end |
#query_form ⇒ Object
239 240 241 |
# File 'lib/plutonium/definition/base.rb', line 239 def query_form self.class::QueryForm end |
#show_page_class ⇒ Object
211 212 213 |
# File 'lib/plutonium/definition/base.rb', line 211 def show_page_class self.class::ShowPage end |