Module: LcpRuby::Metadata::ReservedNames
- Defined in:
- lib/lcp_ruby/metadata/reserved_names.rb
Constant Summary collapse
- RESERVED_ATTRIBUTE_NAMES =
%w[ id type class save save! destroy destroy! delete update update! create valid? invalid? errors new_record? persisted? frozen? hash object_id send respond_to? freeze dup clone inspect to_s to_param to_model model_name reload assign_attributes becomes attributes read_attribute write_attribute attribute_names changed? changes serializable_hash ].freeze
Class Method Summary collapse
-
.reserved_clashes_for_macro(macro, model_definition) ⇒ Object
Returns method/association names the macro GENERATES on the model’s AR class that would shadow a user-declared field of the same name.
Class Method Details
.reserved_clashes_for_macro(macro, model_definition) ⇒ Object
Returns method/association names the macro GENERATES on the model’s AR class that would shadow a user-declared field of the same name.
Two distinct clash sources combined:
-
**Generated AR-instance methods** (static per macro) — e.g. tree’s ‘ancestors`/`descendants`, positioning’s ‘move_higher`, workflow’s ‘available_transitions`.
-
**Generated AR associations** (dynamic per model) — e.g. tree’s ‘belongs_to model_definition.tree_parent_name`. A user `field :parent, :string` would shadow the auto-generated `belongs_to :parent` reader. Dynamic lookup uses the model’s actual rename so a configured ‘tree_parent_name: “boss”` flags “boss” and not “parent” (Decision 13).
**Excluded by design:** structural COLUMNS the macro USES (not generates) — ‘positioning_field`, `tree_position_field`, workflow’s ‘wf.field`. A user declaring `field :position, :integer` alongside `positioning: true`, or `field :state, :enum` alongside a workflow, IS the correct setup — the macro consumes that column. Including them in the clash list would false-positive on every correct macro setup. The generator’s preflight makes the same choice (synthetic injection skips when user already declared, and explicit declaration isn’t flagged).
Caller responsibilities:
-
Pass the model’s actual ‘ModelDefinition` (or an OpenStruct duck-type wrapping CLI flags for generator preflight, per Decision 13).
-
Skip the call entirely for ‘bind_to:` models — the host AR class owns its own field-name surface.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lcp_ruby/metadata/reserved_names.rb', line 42 def self.reserved_clashes_for_macro(macro, model_definition) case macro when :tree # Generated methods + the two associations tree creates # (belongs_to + has_many). tree_position_field is a USED column, # not a generated method — excluded. base = %w[ancestors descendants subtree subtree_ids siblings depth path root root? leaf?] if model_definition.respond_to?(:tree_parent_name) && model_definition.tree_parent_name base << model_definition.tree_parent_name.to_s end if model_definition.respond_to?(:tree_children_name) && model_definition.tree_children_name base << model_definition.tree_children_name.to_s end base when :positioning # Generated movement methods only. positioning_field (the column) # is USED, not generated — excluded. %w[move_higher move_lower] when :workflow # Generated AR-instance methods from workflow_applicator.rb:57-138. # wf.field (canonical state column) is USED, not generated — # excluded. No per-transition methods (transitions execute via # the generic `record.execute_transition!(name, ...)` which # delegates to Workflow::TransitionExecutor.execute). return [] unless model_definition.workflow %w[ workflow_definition available_transitions execute_transition! current_workflow_state active_approval_request approval_tasks_for_user workflow_audit_logs ] else [] end end |