class DidGood::AppFile
Attributes
path[R]
repo[R]
specs[R]
Public Class Methods
new(repo, path)
click to toggle source
# File lib/didgood.rb, line 170 def initialize(repo, path) @path = path @repo = repo raise("No such dgd.didgood file as #{path.inspect}!") unless File.exist?(path) contents = JSON.load(File.read(path)) read_didgood_file(contents) paths = @specs.flat_map { |s| s.paths } unless paths == paths.uniq repeated_paths = paths.select { |p| paths.count(p) > 1 } raise "Repeated (conflicting?) paths in dgd.didgood! #{repeated_paths.inspect}" end # Make sure the dgd.didgood file overrides either no kernel paths or both/all if KERNEL_PATHS.any? { |kp| paths.include?(kp) } unless KERNEL_PATHS.all? { |kp| paths.include?(kp) } raise "dgd.didgood file #{path.inspect} includes some Kernel Library paths but not all! All needed: #{KERNEL_PATHS}!" end puts "This dgd.didgood file overrides the Kernel Library with its own." else # This app has specified no kernellib paths -- add them git_repo = @repo.git_repo(DEFAULT_KERNELLIB_URL) kl_paths = { "src/kernel" => "/kernel", "src/include/kernel" => "/include/kernel", "src/doc/kernel" => "/doc/kernel" } klib_spec = GoodsSpec.new @repo, name: "default Kernel Library", source: git_repo, paths: kl_paths specs.push klib_spec end nil end
Public Instance Methods
read_didgood_file(contents)
click to toggle source
# File lib/didgood.rb, line 202 def read_didgood_file(contents) raise "Expected a top-level JSON object in dgd.didgood!" unless contents.is_a?(Hash) @specs = [] if contents["unbundled_goods"] raise "Unbundled_goods must be an array!" unless contents["unbundled_goods"].is_a?(Array) @specs += contents["unbundled_goods"].map { |item| unbundled_json_to_spec(item) } end if contents["goods"] raise "Goods must be an array!" unless contents["goods"].is_a?(Array) @specs += contents["goods"].map do |goods_url| begin json_contents = JSON.parse(URI.open(goods_url).read) rescue STDERR.puts "Error reading or parsing by URL: #{goods_url.inspect}" raise end unbundled_json_to_spec(json_contents) end end end
unbundled_json_to_spec(fields)
click to toggle source
# File lib/didgood.rb, line 228 def unbundled_json_to_spec(fields) source = nil source_details = nil if fields["git"] raise "A git source requires a git url: #{fields.inspect}!" unless fields["git"]["url"] source = @repo.git_repo(fields["git"]["url"]) source_details = fields["git"] # May contain branch info, etc. else raise "Didgood currently requires a Git-based source!" end unless fields["paths"].all? { |k, v| k.is_a?(String) && v.is_a?(String) } raise "Paths in Goods files must map strings to strings! #{fields["paths"].inspect}" end spec = GoodsSpec.new(@repo, name: fields["name"], source: source, source_details: source_details, paths: fields["paths"]) return spec end