Class: DGD::Manifest::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/dgd-tools/manifest.rb

Overview

This is a repo of everything DGD Manifest saves between runs. It includes downloaded Git repos, Goods files and more.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRepo

Returns a new instance of Repo.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dgd-tools/manifest.rb', line 34

def initialize
    @no_manifest_file = true
    @home = ENV["HOME"]
    @shared_dir = "#{@home}/.dgd-tools"
    Dir.mkdir(@shared_dir) unless File.directory?(@shared_dir)

    ["git", "goods"].each do |subdir|
        full_subdir = "#{@shared_dir}/#{subdir}"
        Dir.mkdir(full_subdir) unless File.directory?(full_subdir)
    end

    unless File.exist?("#{@shared_dir}/dgd/bin/dgd")
        dgd_dir = "#{@shared_dir}/dgd"
        if File.directory?(dgd_dir)
            # Not clear to me what to do here...
        else
            DGD::Manifest.system_call("git clone https://github.com/ChatTheatre/dgd.git #{dgd_dir}")
            Dir.chdir("#{@shared_dir}/dgd/src") do
                DGD::Manifest.system_call(DGD_BUILD_COMMAND)
            end
        end
    end
end

Instance Attribute Details

#shared_dirObject (readonly)

Returns the value of attribute shared_dir.



32
33
34
# File 'lib/dgd-tools/manifest.rb', line 32

def shared_dir
  @shared_dir
end

Instance Method Details

#assemble_app(location, verbose:) ⇒ Object



129
130
131
132
133
134
# File 'lib/dgd-tools/manifest.rb', line 129

def assemble_app(location, verbose:)
    Dir[File.join(dgd_root(location), "*")].each { |dir| FileUtils.rm_rf dir }
    Dir[File.join(dgd_root(location), "state", "*")].each { |dir| FileUtils.rm_rf dir }

    write_app_files(location, verbose: verbose)
end

#dgd_root(location) ⇒ Object



125
126
127
# File 'lib/dgd-tools/manifest.rb', line 125

def dgd_root(location)
    "#{File.expand_path(location)}/#{GENERATED_ROOT}"
end

#git_repo(git_url) ⇒ Object



58
59
60
61
# File 'lib/dgd-tools/manifest.rb', line 58

def git_repo(git_url)
    @git_repos ||= {}
    @git_repos[git_url] ||= GitRepo.new(self, git_url)
end

#manifest_file(path) ⇒ Object



63
64
65
66
67
68
# File 'lib/dgd-tools/manifest.rb', line 63

def manifest_file(path)
    raise "Already have a dgd.manifest file!" unless @no_manifest_file

    @no_manifest_file = false
    @manifest_file ||= AppFile.new(self, path, shared_dir: shared_dir)
end

#precheck(location, verbose:) ⇒ Object



185
186
187
188
189
190
191
192
# File 'lib/dgd-tools/manifest.rb', line 185

def precheck(location, verbose:)
    all_files = assembly_operations(location, verbose: verbose).flat_map { |sd| sd[:non_dirs] }

    if all_files.size != all_files.uniq.size
        repeated = all_files.uniq.select { |f| all_files.count(f) > 1 }
        raise "Error in dgd.manifest! Repeated files: #{repeated.inspect} / #{all_files.inspect}"
    end
end

#update_app(location, verbose:) ⇒ Object



136
137
138
139
# File 'lib/dgd-tools/manifest.rb', line 136

def update_app(location, verbose:)
    Dir[File.join(dgd_root(location), ".repos", "*")].each { |dir| FileUtils.rm_f dir }
    write_app_files(location, verbose: verbose)
end

#write_config_file(path) ⇒ Object



194
195
196
197
198
# File 'lib/dgd-tools/manifest.rb', line 194

def write_config_file(path)
    File.open(path, "wb") do |f|
        f.write @manifest_file.dgd_config.as_file
    end
end