Class: InlineForms::SchemaIntent
- Inherits:
-
Object
- Object
- InlineForms::SchemaIntent
- Defined in:
- lib/inline_forms/schema_intent.rb
Overview
A proposed schema change: "add attribute X of form-element Y to model Z, at this position". This is the unit the end-user-facing staging pipeline (see stuff/2026-07-11-end-user-schema-changes-staging-and-pending-gate.md) drafts, previews, and finally applies.
It is a plain value object — deliberately NOT an ActiveRecord model. Where intents are persisted (a drafts table) and edited (a GUI) is an app-level concern; the engine only needs the structured description plus the mapping to the generator that realizes it. Nothing renders from an intent at runtime, so it is an audit/work-queue artifact, not config-as-data.
STATUS is advisory metadata for a persisting app: draft -> approved -> applied (or failed).
Constant Summary collapse
- STATUSES =
%i[draft approved applied failed].freeze
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#before ⇒ Object
readonly
Returns the value of attribute before.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#form_element ⇒ Object
readonly
Returns the value of attribute form_element.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
-
#status ⇒ Object
Returns the value of attribute status.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#column_token ⇒ Object
The
attr:form_elementtoken exactly as the generator expects it. -
#generator_args ⇒ Object
argv for
rails g inline_forms_addto <Model> <attr:form_element> [--after=..]. -
#initialize(model_name:, attribute:, form_element:, values: nil, disabled: nil, after: nil, before: nil, status: :draft) ⇒ SchemaIntent
constructor
A new instance of SchemaIntent.
-
#model_class ⇒ Object
The model class this intent targets.
- #to_h ⇒ Object
Constructor Details
#initialize(model_name:, attribute:, form_element:, values: nil, disabled: nil, after: nil, before: nil, status: :draft) ⇒ SchemaIntent
Returns a new instance of SchemaIntent.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/inline_forms/schema_intent.rb', line 23 def initialize(model_name:, attribute:, form_element:, values: nil, disabled: nil, after: nil, before: nil, status: :draft) @model_name = model_name.to_s @attribute = attribute.to_sym @form_element = form_element.to_sym @values = values @disabled = disabled @after = after&.to_sym @before = before&.to_sym self.status = status end |
Instance Attribute Details
#after ⇒ Object (readonly)
Returns the value of attribute after.
20 21 22 |
# File 'lib/inline_forms/schema_intent.rb', line 20 def after @after end |
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
20 21 22 |
# File 'lib/inline_forms/schema_intent.rb', line 20 def attribute @attribute end |
#before ⇒ Object (readonly)
Returns the value of attribute before.
20 21 22 |
# File 'lib/inline_forms/schema_intent.rb', line 20 def before @before end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
20 21 22 |
# File 'lib/inline_forms/schema_intent.rb', line 20 def disabled @disabled end |
#form_element ⇒ Object (readonly)
Returns the value of attribute form_element.
20 21 22 |
# File 'lib/inline_forms/schema_intent.rb', line 20 def form_element @form_element end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
20 21 22 |
# File 'lib/inline_forms/schema_intent.rb', line 20 def model_name @model_name end |
#status ⇒ Object
Returns the value of attribute status.
21 22 23 |
# File 'lib/inline_forms/schema_intent.rb', line 21 def status @status end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
20 21 22 |
# File 'lib/inline_forms/schema_intent.rb', line 20 def values @values end |
Instance Method Details
#column_token ⇒ Object
The attr:form_element token exactly as the generator expects it.
51 52 53 |
# File 'lib/inline_forms/schema_intent.rb', line 51 def column_token "#{attribute}:#{form_element}" end |
#generator_args ⇒ Object
argv for rails g inline_forms_addto <Model> <attr:form_element> [--after=..].
56 57 58 59 60 61 |
# File 'lib/inline_forms/schema_intent.rb', line 56 def generator_args args = [ model_name, column_token ] args << "--after=#{after}" if after args << "--before=#{before}" if before args end |
#model_class ⇒ Object
The model class this intent targets. Raises NameError if it is not defined (an app should validate the name before drafting).
46 47 48 |
# File 'lib/inline_forms/schema_intent.rb', line 46 def model_class model_name.constantize end |
#to_h ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/inline_forms/schema_intent.rb', line 63 def to_h { model_name: model_name, attribute: attribute, form_element: form_element, values: values, disabled: disabled, after: after, before: before, status: status } end |