module ArchSpec::Facts
A versioned snapshot of externally established references and generated methods. Producers may run application code; consumers only read data.
Constants
- DOCUMENT_KEYS
- LOCATION_KEYS
- VERSION
Public Instance Methods
Source
# File lib/archspec/facts.rb, line 29 def load_into(graph, directory) paths = Dir.glob(File.join(File.expand_path(directory, graph.root), '*.yml')).sort raise Error, "no facts found in #{directory}; run `archspec reflect` or your facts producer" if paths.empty? current = snapshot(graph, excluding: directory) paths.each do |path| document = YAML.safe_load_file(path, permitted_classes: [], aliases: false) validate_document(document, path, current) apply_document(graph, document, path) end graph.clear_method_caches rescue Psych::Exception, SystemCallError => error raise Error, "could not load facts: #{error.message}" end
# File lib/archspec/facts.rb, line 18 def snapshot(graph, excluding: 'archspec_facts') excluded = File.expand_path(excluding, graph.root) inputs = Dir.glob(File.join(graph.root, 'config/**/*.{rb,yml,yaml}')) + Dir.glob(File.join(graph.root, '{Gemfile,Gemfile.lock,*.gemspec,.ruby-version}')) (graph.files.keys + inputs).select { |path| File.file?(path) } .reject { |path| path == excluded || path.start_with?("#{excluded}/") } .uniq.sort.to_h do |path| [Pathname(path).relative_path_from(Pathname(graph.root)).to_s, Digest::SHA256.file(path).hexdigest] end end
Source
# File lib/archspec/facts.rb, line 44 def write(path, document) FileUtils.mkdir_p(File.dirname(path)) Tempfile.create(['.archspec-facts-', '.yml'], File.dirname(path)) do |file| file.write(document.to_yaml) file.flush file.close File.rename(file.path, path) end rescue SystemCallError => error raise Error, "could not write facts #{path}: #{error.message}" end