Module: Edoxen::Cli::Batch

Defined in:
lib/edoxen/cli.rb,
sig/edoxen.rbs

Overview

Deep module behind the per-command interface. Owns the expand/sort/empty/header/loop/tally/summary/exit scaffold so validate and normalize collapse to one-line delegations. Also owns the per-profile shape sniffers that pick the correct model class for each YAML file (one of N shapes accepted by the canonical oneOf roots).

Constant Summary collapse

Result =

Returns:

  • (Struct[untyped])

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decision_kind(data) ⇒ Object

Discriminate the three top-level shapes the canonical schema/edoxen.yaml accepts via oneOf:

* :contacts   — `{ contacts: [...] }` (ContactRegister registry).
* :venues     — `{ venues: [...] }`   (VenueRegister registry).
* :decisions  — anything else (DecisionCollection, the default).


84
85
86
87
88
89
90
91
# File 'lib/edoxen/cli.rb', line 84

def decision_kind(data)
  return :decisions unless data.is_a?(Hash)

  return :contacts if data["contacts"].is_a?(Array)
  return :venues if data["venues"].is_a?(Array)

  :decisions
end

.expand(pattern) ⇒ Object



140
141
142
# File 'lib/edoxen/cli.rb', line 140

def expand(pattern)
  Dir.glob(pattern).select { |f| File.file?(f) && f.match?(/\.ya?ml\z/i) }.sort
end

.meetings_kind(data) ⇒ Object

Discriminate the three top-level shapes the canonical schema/meeting.yaml accepts via oneOf:

* :collection — `{ meetings: [...] }`
* :series     — `{ identifier: [...], meeting_refs: [...] }`
              (or any hash with `identifier` + `recurrence`)
* :meeting    — anything else (single Meeting).


100
101
102
103
104
105
106
107
108
# File 'lib/edoxen/cli.rb', line 100

def meetings_kind(data)
  return :meeting unless data.is_a?(Hash)

  return :collection if data["meetings"].is_a?(Array)
  return :series if data["identifier"].is_a?(Array) &&
                    (data.key?("meeting_refs") || data.key?("recurrence"))

  :meeting
end


144
145
146
147
148
149
150
151
152
# File 'lib/edoxen/cli.rb', line 144

def print_summary(cli, total, ok_count, bad_count, summary_extra)
  cli.say "\n📊 Summary:", :blue
  cli.say "  Total: #{total}", :blue
  cli.say "  Success: #{ok_count}, Failed: #{bad_count}",
          bad_count.positive? ? :red : :green
  rate = total.zero? ? 0 : ((ok_count.to_f / total) * 100).round(1)
  cli.say "  Success rate: #{rate}%", :blue
  summary_extra.each { |label, value| cli.say "  #{label}: #{value}", :blue }
end

.run(cli, pattern, header:, summary_extra: []) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/edoxen/cli.rb', line 110

def run(cli, pattern, header:, summary_extra: [])
  files = expand(pattern)
  if files.empty?
    cli.say "No files found matching pattern: #{pattern}", :red
    exit 1
  end

  cli.say "#{header} #{files.size} file(s)...", :blue

  ok_count = 0
  bad_count = 0

  files.each do |file|
    $stdout.print "  #{File.basename(file)}... "
    result = yield file
    if result.status == :ok
      label = result.message ? "#{result.message}" : ""
      cli.say label, :green
      ok_count += 1
    else
      cli.say "❌ INVALID", :red
      bad_count += 1
      Array(result.errors).each { |e| cli.say "    #{e}", :red }
    end
  end

  print_summary(cli, files.size, ok_count, bad_count, summary_extra)
  exit(bad_count.positive? ? 1 : 0)
end

Instance Method Details

#self?.expandArray[String]

Parameters:

  • pattern (String)

Returns:

  • (Array[String])


572
# File 'sig/edoxen.rbs', line 572

def self?.expand: (String pattern) -> Array[String]

#self?.print_summaryvoid

This method returns an undefined value.

Parameters:

  • cli (Object)
  • total (Integer)
  • ok (Integer)
  • bad (Integer)
  • extra (Array[[String, untyped]])


573
# File 'sig/edoxen.rbs', line 573

def self?.print_summary: (untyped cli, Integer total, Integer ok, Integer bad, Array[[String, untyped]] extra) -> void

#self?.run {|file| ... } ⇒ void

This method returns an undefined value.

Parameters:

  • cli (Object)
  • pattern (String)
  • header: (String)
  • summary_extra: (Array[[String, untyped]])

Yields:

Yield Parameters:

  • file (String)

Yield Returns:



571
# File 'sig/edoxen.rbs', line 571

def self?.run: (untyped cli, String pattern, ?header: String, ?summary_extra: Array[[String, untyped]]) { (String file) -> Result } -> void