Class: Textus::Domain::Policy::Predicates::SchemaValid
- Inherits:
-
Object
- Object
- Textus::Domain::Policy::Predicates::SchemaValid
- Defined in:
- lib/textus/domain/policy/predicates/schema_valid.rb
Instance Attribute Summary collapse
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Instance Method Summary collapse
-
#call(entry:, store:) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
- #name ⇒ Object
Instance Attribute Details
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
6 7 8 |
# File 'lib/textus/domain/policy/predicates/schema_valid.rb', line 6 def reason @reason end |
Instance Method Details
#call(entry:, store:) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/textus/domain/policy/predicates/schema_valid.rb', line 12 def call(entry:, store:) # rubocop:disable Metrics/PerceivedComplexity return true if entry.nil? || store.nil? target_key = entry.&.dig("proposal", "target_key") return true unless target_key mentry, = store.manifest.resolve(target_key) schema_ref = mentry&.schema return true unless schema_ref schema = store.schema_for(schema_ref) return true unless schema frontmatter = entry.&.dig("frontmatter") || {} begin schema.validate!(frontmatter) rescue Textus::SchemaViolation => e @reason = e..dup d = e.details if d.is_a?(Hash) if d["missing"] @reason = "missing required fields: #{Array(d["missing"]).join(", ")}" elsif d["field"] @reason = "field '#{d["field"]}': #{d["reason"]}" end end return false end true rescue StandardError => e @reason = "schema validation error: #{e.}" false end |
#name ⇒ Object
8 9 10 |
# File 'lib/textus/domain/policy/predicates/schema_valid.rb', line 8 def name "schema_valid" end |