Class: ConfCtl::Generation::Build
- Inherits:
-
Object
- Object
- ConfCtl::Generation::Build
- Defined in:
- lib/confctl/generation/build.rb
Instance Attribute Summary collapse
- #current ⇒ Boolean
- #date ⇒ Time readonly
- #host ⇒ String readonly
- #name ⇒ String readonly
- #swpin_names ⇒ Array<String> readonly
- #swpin_paths ⇒ Hash readonly
- #swpin_specs ⇒ Hash readonly
- #toplevel ⇒ String readonly
Instance Method Summary collapse
- #add_gcroot ⇒ Object
- #create(toplevel, swpin_paths, swpin_specs, date: nil) ⇒ Object
- #destroy ⇒ Object
- #dir ⇒ Object
-
#initialize(host) ⇒ Build
constructor
A new instance of Build.
- #load(name) ⇒ Object
- #remove_gcroot ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(host) ⇒ Build
Returns a new instance of Build.
33 34 35 |
# File 'lib/confctl/generation/build.rb', line 33 def initialize(host) @host = host end |
Instance Attribute Details
#current ⇒ Boolean
30 31 32 |
# File 'lib/confctl/generation/build.rb', line 30 def current @current end |
#date ⇒ Time (readonly)
14 15 16 |
# File 'lib/confctl/generation/build.rb', line 14 def date @date end |
#host ⇒ String (readonly)
8 9 10 |
# File 'lib/confctl/generation/build.rb', line 8 def host @host end |
#name ⇒ String (readonly)
11 12 13 |
# File 'lib/confctl/generation/build.rb', line 11 def name @name end |
#swpin_names ⇒ Array<String> (readonly)
20 21 22 |
# File 'lib/confctl/generation/build.rb', line 20 def swpin_names @swpin_names end |
#swpin_paths ⇒ Hash (readonly)
23 24 25 |
# File 'lib/confctl/generation/build.rb', line 23 def swpin_paths @swpin_paths end |
#swpin_specs ⇒ Hash (readonly)
26 27 28 |
# File 'lib/confctl/generation/build.rb', line 26 def swpin_specs @swpin_specs end |
#toplevel ⇒ String (readonly)
17 18 19 |
# File 'lib/confctl/generation/build.rb', line 17 def toplevel @toplevel end |
Instance Method Details
#add_gcroot ⇒ Object
105 106 107 108 109 110 |
# File 'lib/confctl/generation/build.rb', line 105 def add_gcroot GCRoot.add(gcroot_name('toplevel'), toplevel_path) swpin_paths.each_key do |name| GCRoot.add(gcroot_name("swpin.#{name}"), toplevel_path) end end |
#create(toplevel, swpin_paths, swpin_specs, date: nil) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/confctl/generation/build.rb', line 41 def create(toplevel, swpin_paths, swpin_specs, date: nil) @toplevel = toplevel @swpin_names = swpin_paths.keys @swpin_paths = swpin_paths @swpin_specs = swpin_specs @date = date || Time.now @name = date.strftime('%Y-%m-%d--%H-%M-%S') end |
#destroy ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/confctl/generation/build.rb', line 97 def destroy remove_gcroot File.unlink(toplevel_path) swpin_paths.each_key { |name| File.unlink(swpin_path(name)) } File.unlink(config_path) Dir.rmdir(dir) end |
#dir ⇒ Object
119 120 121 |
# File 'lib/confctl/generation/build.rb', line 119 def dir @dir ||= File.join(ConfDir.generation_dir, escaped_host, name) end |
#load(name) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/confctl/generation/build.rb', line 51 def load(name) @name = name cfg = JSON.parse(File.read(config_path)) @toplevel = cfg['toplevel'] @swpin_names = [] @swpin_paths = {} @swpin_specs = {} cfg['swpins'].each do |swpin_name, swpin| @swpin_names << swpin_name @swpin_paths[swpin_name] = swpin['path'] @swpin_specs[swpin_name] = Swpins::Spec.for(swpin['spec']['type'].to_sym).new( swpin_name, swpin['spec']['nix_options'], swpin['spec'] ) end @date = Time.iso8601(cfg['date']) rescue StandardError => e raise Error, "invalid generation '#{name}': #{e.}" end |
#remove_gcroot ⇒ Object
112 113 114 115 116 117 |
# File 'lib/confctl/generation/build.rb', line 112 def remove_gcroot GCRoot.remove(gcroot_name('toplevel')) swpin_paths.each_key do |name| GCRoot.remove(gcroot_name("swpin.#{name}")) end end |
#save ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/confctl/generation/build.rb', line 76 def save FileUtils.mkdir_p(dir) File.symlink(toplevel, toplevel_path) swpin_paths.each do |name, path| File.symlink(path, swpin_path(name)) end File.open(config_path, 'w') do |f| f.puts(JSON.pretty_generate({ date: date.iso8601, toplevel:, swpins: swpin_paths.to_h do |name, path| [name, { path:, spec: swpin_specs[name].as_json }] end })) end add_gcroot end |