-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathstrings.rb
More file actions
33 lines (29 loc) · 1.24 KB
/
strings.rb
File metadata and controls
33 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true
require 'puppet_references'
require 'json'
# @@string_data_cached class var usage is intentional here
# rubocop:disable Style/ClassVars
module PuppetReferences
module Puppet
class Strings < Hash
STRINGS_JSON_FILE = PuppetReferences::OUTPUT_DIR + 'openvox/strings.json'
@@strings_data_cached = false
def initialize(force_cached: false)
super()
@@strings_data_cached = true if force_cached
generate_strings_data unless @@strings_data_cached
merge!(JSON.parse(File.read(STRINGS_JSON_FILE)))
# We can't keep the actual data hash in an instance variable, because if you duplicate the main hash, all its
# deeply nested members will be assigned by reference to the new hash, and you'll get leakage across objects.
end
def generate_strings_data
puts 'Generating Puppet Strings JSON data...'
rubyfiles = Dir.glob("#{PuppetReferences::PUPPET_DIR}/lib/puppet/**/*.rb")
system("bundle exec puppet strings generate --format json --out #{STRINGS_JSON_FILE} #{rubyfiles.join(' ')}")
puts "Strings data: Done! (#{STRINGS_JSON_FILE})"
@@strings_data_cached = true
end
end
end
end
# rubocop:enable Style/ClassVars