Module: LcpRuby::Conditions::Validator
- Defined in:
- lib/lcp_ruby/conditions/validator.rb
Overview
Static shape predicate for condition hashes (visible_when:, etc.).
Returns true when the hash matches a recognized condition shape (role-shortcut, field/service/compound/collection per ‘ConditionEvaluator.condition_type`). Returns false otherwise.
This is a static predicate — it never invokes the evaluator and never raises on missing user methods or missing fields. It exists so the boot-time RuntimeInvariantValidator (AUTH-002/003) can decide “is this a well-shaped condition” without runtime context.
See docs/design/authorization_hardening.md § “The ‘parseable?` predicate is a new shared helper”.
Class Method Summary collapse
Class Method Details
.parseable?(condition) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lcp_ruby/conditions/validator.rb', line 19 def parseable?(condition) return false unless condition.is_a?(Hash) return false if condition.empty? normalized = condition.transform_keys(&:to_s) # Role-shortcut shape: { "role" => "admin" } or { "role" => [...] } # The runtime evaluator (zone_resolution#zone_visible?) special-cases # this before delegating to ConditionEvaluator. return true if normalized.key?("role") # Recognized condition_object shapes (field/service/compound/collection) !ConditionEvaluator.condition_type(normalized).nil? end |