Class: Plutonium::Definition::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
Actions, ConfigAttr, DefineableProps, FormLayout, IndexViews, InheritableConfigAttr, Metadata, NestedInputs, Scoping, Search, Sorting, StructuredInputs, Wizards
Defined in:
lib/plutonium/definition/base.rb

Overview

This class is abstract.

Subclass and override #customize_fields, #customize_inputs, #customize_filters, #customize_scopes, and #customize_sorters to implement custom behavior.

Note:

This class is not thread-safe. Ensure proper synchronization if used in a multi-threaded environment.

Base class for Plutonium definitions

Examples:

class MyDefinition < Plutonium::Definition::Base
  field :name, as: :string
  input :email, as: :email
  filter :status, type: :select, collection: %w[active inactive]
  scope :active
  default_scope :active
  sorter :created_at

  def customize_fields
    field :custom_field, as: :integer
  end
end

Direct Known Subclasses

Resource::Definition

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 dialog

The kanban board has its own show_in that overrides this per-board.

[:modal, :page].freeze

Constants included from IndexViews

IndexViews::GRID_LAYOUTS, IndexViews::GRID_SLOTS, IndexViews::KNOWN_VIEWS

Constants included from FormLayout

FormLayout::UNGROUPED_KEY

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Metadata

#defined_metadata_fields

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 FormLayout

assign_ownership, #defined_form_layout, #resolve_form_sections, resolve_sections

Methods included from StructuredInputs

#defined_structured_inputs

Methods included from Search

#search_definition

Methods included from Scoping

#default_scope

Methods included from Sorting

#default_sort

Constructor Details

#initializeBase

Returns a new instance of Base.



148
149
150
# File 'lib/plutonium/definition/base.rb', line 148

def initialize
  super
end

Class Method Details

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.



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/plutonium/definition/base.rb', line 112

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

.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.



140
141
142
143
144
145
146
# File 'lib/plutonium/definition/base.rb', line 140

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_classObject



176
177
178
# File 'lib/plutonium/definition/base.rb', line 176

def collection_class
  self.class::Table
end

#detail_classObject



184
185
186
# File 'lib/plutonium/definition/base.rb', line 184

def detail_class
  self.class::Display
end

#edit_page_classObject



164
165
166
# File 'lib/plutonium/definition/base.rb', line 164

def edit_page_class
  self.class::EditPage
end

#form_classObject



172
173
174
# File 'lib/plutonium/definition/base.rb', line 172

def form_class
  self.class::Form
end

#grid_classObject



180
181
182
# File 'lib/plutonium/definition/base.rb', line 180

def grid_class
  self.class::Grid
end

#index_page_classObject



152
153
154
# File 'lib/plutonium/definition/base.rb', line 152

def index_page_class
  self.class::IndexPage
end

#interactive_action_page_classObject



168
169
170
# File 'lib/plutonium/definition/base.rb', line 168

def interactive_action_page_class
  self.class::InteractiveActionPage
end

#new_page_classObject



156
157
158
# File 'lib/plutonium/definition/base.rb', line 156

def new_page_class
  self.class::NewPage
end

#query_formObject



188
189
190
# File 'lib/plutonium/definition/base.rb', line 188

def query_form
  self.class::QueryForm
end

#show_page_classObject



160
161
162
# File 'lib/plutonium/definition/base.rb', line 160

def show_page_class
  self.class::ShowPage
end