Skip to content

Commit 81b0a07

Browse files
committed
Add XML manual generation rake
1 parent 9e48ce7 commit 81b0a07

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lib/tasks/xml.rake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace :xml do
2+
desc "Generate CME XML to a local file or stdout (no Azure). ENV: SCOPE=all_providers|single_provider LANGUAGE=<id|code|name> PROVIDER_ID=<id> DEST=<path or '-'>"
3+
task generate: :environment do
4+
require "fileutils"
5+
6+
scope = ENV.fetch("SCOPE", "all_providers")
7+
lang_param = ENV["LANGUAGE"]
8+
provider_id = ENV["PROVIDER_ID"]
9+
dest = ENV["DEST"] || "tmp/cmes.xml"
10+
11+
language = if lang_param.present?
12+
Language.find_by(id: lang_param) || Language.find_by(code: lang_param) || Language.find_by(name: lang_param)
13+
else
14+
Language.joins(:topics).distinct.first
15+
end
16+
abort "LANGUAGE not found or no languages with topics" unless language
17+
18+
service = case scope
19+
when "single_provider"
20+
abort "PROVIDER_ID required for single_provider" unless provider_id.present?
21+
provider = Provider.find(provider_id)
22+
XmlGenerator::SingleProvider.new(provider)
23+
when "all_providers"
24+
XmlGenerator::AllProviders.new(language)
25+
else
26+
abort "Unknown SCOPE: #{scope}"
27+
end
28+
29+
xml = service.perform
30+
31+
if dest == "-"
32+
puts xml
33+
else
34+
path = Rails.root.join(dest)
35+
FileUtils.mkdir_p(File.dirname(path))
36+
File.write(path, xml)
37+
puts "Wrote XML to #{path} (#{xml.bytesize} bytes)"
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)