Class: Insika::Evidence::Spec
- Inherits:
-
Data
- Object
- Data
- Insika::Evidence::Spec
- Defined in:
- lib/insika/evidence.rb
Overview
The declaration (D1/C2.1). Parses three authorable shapes:
{ "evidence": "products" } // bare kind
{ "evidence": { "kind": "products" } } // full form
{ "evidence": { "kind": "products",
"items": "results",
"attachments": "cards" } } // non-default paths
kind is the PILOT PACK's value, never a gem constant (the
engine owns nothing about product shape).
Constant Summary collapse
- PATH_RE =
/\A[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*\z/
Instance Attribute Summary collapse
-
#attachments_path ⇒ Object
readonly
Returns the value of attribute attachments_path.
-
#items_path ⇒ Object
readonly
Returns the value of attribute items_path.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
Class Method Summary collapse
-
.parse(raw) ⇒ Object
String | Hash | nil -> Spec | nil.
Instance Method Summary collapse
Instance Attribute Details
#attachments_path ⇒ Object (readonly)
Returns the value of attribute attachments_path
29 30 31 |
# File 'lib/insika/evidence.rb', line 29 def @attachments_path end |
#items_path ⇒ Object (readonly)
Returns the value of attribute items_path
29 30 31 |
# File 'lib/insika/evidence.rb', line 29 def items_path @items_path end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind
29 30 31 |
# File 'lib/insika/evidence.rb', line 29 def kind @kind end |
Class Method Details
.parse(raw) ⇒ Object
String | Hash | nil -> Spec | nil. Raises ValidationError on a blank kind or an empty/ill-formed path. All at ingestion, never at the turn.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/insika/evidence.rb', line 34 def self.parse(raw) return nil if raw.nil? || raw == false h = raw.is_a?(String) ? { "kind" => raw } : Coercion.deep_stringify(raw) h = h.is_a?(Hash) ? h : {} kind = Coercion.presence(h["kind"]) raise Insika::ValidationError, "evidence.kind is required" if kind.nil? items = presence_path(h["items"], "items") = presence_path(h["attachments"], "attachments") new(kind: kind, items_path: items, attachments_path: ) end |
Instance Method Details
#to_h ⇒ Object
47 48 49 |
# File 'lib/insika/evidence.rb', line 47 def to_h { "kind" => kind, "items" => items_path, "attachments" => }.compact end |