Module: Textus::Manifest::Schema::Semantics::CrossField
- Included in:
- Textus::Manifest::Schema::Semantics
- Defined in:
- lib/textus/manifest/schema/semantics/cross_field.rb
Instance Method Summary collapse
- #check_cross_field!(raw) ⇒ Object
- #check_lane_kind_consistency!(raw) ⇒ Object
- #check_owner!(owner, path) ⇒ Object
- #check_owners!(lanes, entries) ⇒ Object
- #valid_owner?(token) ⇒ Boolean
Instance Method Details
#check_cross_field!(raw) ⇒ Object
6 7 8 9 |
# File 'lib/textus/manifest/schema/semantics/cross_field.rb', line 6 def check_cross_field!(raw) check_owners!(raw["lanes"], raw["entries"]) check_lane_kind_consistency!(raw) end |
#check_lane_kind_consistency!(raw) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/textus/manifest/schema/semantics/cross_field.rb', line 36 def check_lane_kind_consistency!(raw) held = Capabilities.resolve(raw["roles"]).values.flatten.uniq Array(raw["lanes"]).each_with_index do |z, i| verb = KIND_REQUIRES_VERB[z["kind"]] next if verb.nil? || held.include?(verb) raise BadManifest.new( "lane '#{z["name"]}' (#{z["kind"]}) at '$.lanes[#{i}]' " \ "needs a role with capability '#{verb}'; none declared", ) end end |
#check_owner!(owner, path) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/textus/manifest/schema/semantics/cross_field.rb', line 16 def check_owner!(owner, path) return if owner.nil? return if valid_owner?(owner) raise BadManifest.new( "invalid owner '#{owner}' at '#{path}' " \ "(expected <archetype> or <archetype>:<subject>, archetype one of: #{Textus::Value::Role::NAMES.join(", ")})", ) end |
#check_owners!(lanes, entries) ⇒ Object
11 12 13 14 |
# File 'lib/textus/manifest/schema/semantics/cross_field.rb', line 11 def check_owners!(lanes, entries) Array(lanes).each_with_index { |z, i| check_owner!(z["owner"], "$.lanes[#{i}]") } Array(entries).each_with_index { |e, i| check_owner!(e["owner"], "$.entries[#{i}]") } end |
#valid_owner?(token) ⇒ Boolean
26 27 28 29 30 31 32 33 34 |
# File 'lib/textus/manifest/schema/semantics/cross_field.rb', line 26 def valid_owner?(token) return false unless token.is_a?(String) && !token.empty? archetype, subject = token.split(":", 2) return false unless Textus::Value::Role::NAMES.include?(archetype) return true if subject.nil? OWNER_SUBJECT_PATTERN.match?(subject) end |