Class: LcpRuby::ModelFactory::InheritedParentValidatorApplicator
- Inherits:
-
Object
- Object
- LcpRuby::ModelFactory::InheritedParentValidatorApplicator
- Defined in:
- lib/lcp_ruby/model_factory/inherited_parent_validator_applicator.rb
Overview
Wires LcpRuby::Authorization::InheritedParentValidator on host AR classes bound via ‘bind_to:`. Triggered by smart-auto in `apply_bind_to_features` when the model’s permission has ‘inherits_from`, OR by explicit opt-in via `bind_to_apply: [inherited_parent_validator]` (for DB-backed permissions that aren’t visible at boot).
Idempotent at the validator-class granularity: re-running the applicator on the same host class does not double-wire the validator. AR’s ‘validates_with` does NOT de-duplicate by class (each call adds another validator instance), so we check `model_class.validators` explicitly. The `@lcp_applied_features` Set guard in `apply_bind_to_features` already prevents repeated execution within a single boot, but the in-class check is a safer second line of defense for hot-reload edge cases.
Instance Method Summary collapse
- #apply! ⇒ Object
-
#initialize(model_class, model_def) ⇒ InheritedParentValidatorApplicator
constructor
A new instance of InheritedParentValidatorApplicator.
Constructor Details
#initialize(model_class, model_def) ⇒ InheritedParentValidatorApplicator
Returns a new instance of InheritedParentValidatorApplicator.
19 20 21 22 |
# File 'lib/lcp_ruby/model_factory/inherited_parent_validator_applicator.rb', line 19 def initialize(model_class, model_def) @model_class = model_class @model_def = model_def end |
Instance Method Details
#apply! ⇒ Object
24 25 26 27 28 |
# File 'lib/lcp_ruby/model_factory/inherited_parent_validator_applicator.rb', line 24 def apply! return if already_wired? @model_class.validates_with(LcpRuby::Authorization::InheritedParentValidator) end |