Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/bin/gtn.rb
1677 views
1
# frozen_string_literal: true
2
3
CONTRIBUTORS = YAML.load_file('CONTRIBUTORS.yaml')
4
ORGANISATIONS = YAML.load_file('ORGANISATIONS.yaml')
5
GRANTS = YAML.load_file('GRANTS.yaml')
6
7
def automagic_loading(f)
8
# Remove our documentation
9
f.reject! { |k, v| k == 'description' and v.is_a?(String) }
10
f.reject! { |k| k == '_examples' }
11
12
# Auto-replace CONTRIBUTORS in enums.
13
f.each do |k, v|
14
if v.is_a?(Hash)
15
automagic_loading(v)
16
elsif v.is_a?(Array)
17
if k == 'enum'
18
repl = []
19
# If one of the elements in this array is CONTRIBUTORS, replace it with the same named variable
20
repl << CONTRIBUTORS.keys if v.find { |x| x == 'CONTRIBUTORS' }
21
repl << GRANTS.keys if v.find { |x| x == 'GRANTS' }
22
repl << ORGANISATIONS.keys if v.find { |x| x == 'ORGANISATIONS' }
23
v.replace repl.flatten if repl.length.positive?
24
end
25
v.flatten.each { |x| automagic_loading(x) if x.is_a?(Hash) }
26
end
27
end
28
f
29
end
30
31