Module: LcpRuby::ModelFactory::ManagedTracking
- Included in:
- AssociationApplicator, SchemaManager
- Defined in:
- lib/lcp_ruby/model_factory/managed_tracking.rb
Overview
Per-class introspection for items LCP added to a ‘bind_to:` host class via `lcp_managed: true`. Mixed into SchemaManager (records added columns) and AssociationApplicator (records declared AR macros) so both write into the same per-host-class summary Hash.
Consumers of ‘host_class.lcp_managed_summary`:
-
‘AssociationApplicator#already_managed?` — reload-safety guard so `Engine.reload!` does not silently re-execute `belongs_to` and replace the AR reflection.
-
‘ConfigurationValidator#validate_managed_assoc_collisions` — same carve-out for “validate after boot in same process”.
-
Developer-console / spec assertions (“what did LCP add to this class?”).
Constant Summary collapse
- EMPTY_SUMMARY =
{ columns: [], associations: [] }.freeze
Class Attribute Summary collapse
-
.tracked_host_classes ⇒ Object
readonly
Returns the value of attribute tracked_host_classes.
Class Method Summary collapse
-
.reset_all! ⇒ Object
Clear the summary on every previously-tracked host class.
Instance Method Summary collapse
Class Attribute Details
.tracked_host_classes ⇒ Object (readonly)
Returns the value of attribute tracked_host_classes.
21 22 23 |
# File 'lib/lcp_ruby/model_factory/managed_tracking.rb', line 21 def tracked_host_classes @tracked_host_classes end |
Class Method Details
.reset_all! ⇒ Object
Clear the summary on every previously-tracked host class.
NOT called from ‘LcpRuby.reset!` / `Engine.reload!`: tracking is process-lifetime state, and wiping it would defeat the `already_managed?` reload guard (next pass would re-execute `belongs_to` and stack duplicate callbacks).
Provided for explicit use by tests that need a clean slate (e.g. to assert “what does LCP add to a fresh class” without inheriting tracking state from an earlier example).
33 34 35 36 |
# File 'lib/lcp_ruby/model_factory/managed_tracking.rb', line 33 def reset_all! @tracked_host_classes.each(&:reset_lcp_managed_summary!) @tracked_host_classes = Set.new end |
Instance Method Details
#track!(host_class, kind, name) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lcp_ruby/model_factory/managed_tracking.rb', line 39 def track!(host_class, kind, name) summary = host_class.instance_variable_get(:@lcp_managed_summary) unless summary install_summary_accessors!(host_class) summary = host_class.instance_variable_get(:@lcp_managed_summary) ManagedTracking.tracked_host_classes << host_class end bucket = summary[kind] || raise(ArgumentError, "ManagedTracking#track!: unknown kind #{kind.inspect}, expected :columns or :associations") bucket << name unless bucket.include?(name) end |