Class: InlineForms::SchemaIntent

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#afterObject (readonly)

Returns the value of attribute after.



20
21
22
# File 'lib/inline_forms/schema_intent.rb', line 20

def after
  @after
end

#attributeObject (readonly)

Returns the value of attribute attribute.



20
21
22
# File 'lib/inline_forms/schema_intent.rb', line 20

def attribute
  @attribute
end

#beforeObject (readonly)

Returns the value of attribute before.



20
21
22
# File 'lib/inline_forms/schema_intent.rb', line 20

def before
  @before
end

#disabledObject (readonly)

Returns the value of attribute disabled.



20
21
22
# File 'lib/inline_forms/schema_intent.rb', line 20

def disabled
  @disabled
end

#form_elementObject (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_nameObject (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

#statusObject

Returns the value of attribute status.



21
22
23
# File 'lib/inline_forms/schema_intent.rb', line 21

def status
  @status
end

#valuesObject (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_tokenObject

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_argsObject

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_classObject

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_hObject



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