Class: Eco::API::UseCases::GraphQL::Samples::Pages::Template::Deploy::SyncReadiness

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/usecases/graphql/samples/pages/template/deploy/sync_readiness.rb

Overview

Sync-readiness monitoring.

Given a register subset (its entries) and the register's ACTIVE template, report which entries CAN sync vs which cannot — where "can sync" means: every field the template marks REQUIRED is present on the entry with a non-empty value AND typed correctly (the entry field's type matches the template field's type). This is the pre-flight an integration runs before pushing entries downstream, and the drift-detection the customer-facing integrations mandate needs.

Operates on raw docs (template doc + entry docs) so it is session-less and offline-runnable:

  • template doc: the JSON the gem returns for a template (stages/sections/dataFields).
  • entry docs: each register entry as { 'id' =>, 'fields' => [ id/label/type/value, ... ] } (or anything exposing the same shape). A field is matched to a template field by id first, then by label — mirroring how the pairing engine falls back.

monitor = SyncReadiness.new(template_doc: tpl, entries: [e1, e2, ...]) monitor.ready # => [EntryReadiness(ready: true), ...] monitor.not_ready # => [EntryReadiness(ready: false, ...), ...] monitor.summary # => { total:, ready:, not_ready: } monitor.report # => human summary

Defined Under Namespace

Classes: EntryReadiness

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_doc:, entries:) ⇒ SyncReadiness

Returns a new instance of SyncReadiness.

Parameters:

  • template_doc (Hash)

    the active template doc.

  • entries (Array<Hash,#id>)

    register entry docs to assess.



48
49
50
51
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/sync_readiness.rb', line 48

def initialize(template_doc:, entries:)
  @template_doc = template_doc || {}
  @entries      = Array(entries)
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



44
45
46
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/sync_readiness.rb', line 44

def entries
  @entries
end

Instance Method Details

#not_readyObject



61
62
63
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/sync_readiness.rb', line 61

def not_ready
  verdicts.reject(&:ready?)
end

#readyObject



57
58
59
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/sync_readiness.rb', line 57

def ready
  verdicts.select(&:ready?)
end

#reportObject



73
74
75
76
77
78
79
80
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/sync_readiness.rb', line 73

def report
  lines = ["SYNC READINESS: #{summary[:ready]}/#{summary[:total]} entries ready"]
  not_ready.each do |v|
    lines << "  * entry #{v.entry_id}: NOT READY"
    v.reasons.each { |r| lines << "      - #{r}" }
  end
  lines.join("\n")
end

#summaryObject



65
66
67
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/sync_readiness.rb', line 65

def summary
  { total: verdicts.size, ready: ready.size, not_ready: not_ready.size }
end

#to_hObject



69
70
71
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/sync_readiness.rb', line 69

def to_h
  { summary: summary, entries: verdicts.map(&:to_h) }
end

#verdictsObject



53
54
55
# File 'lib/eco/api/usecases/graphql/samples/pages/template/deploy/sync_readiness.rb', line 53

def verdicts
  @verdicts ||= @entries.map { |entry| assess(entry) }
end