Class: ConfCtl::Swpins::Core
- Inherits:
-
Object
- Object
- ConfCtl::Swpins::Core
show all
- Includes:
- Utils::File
- Defined in:
- lib/confctl/swpins/core.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#replace_symlink, #unlink_if_exists
Constructor Details
#initialize ⇒ Core
Returns a new instance of Core.
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/confctl/swpins/core.rb', line 29
def initialize
@name = 'core'
@path = File.join(ConfCtl::Swpins.core_dir, 'core.json')
settings = ConfCtl::Settings.instance
@channels = Swpins::ChannelList.get.select do |c|
settings.core_swpin_channels.include?(c.name)
end
@nix_specs = settings.core_swpin_pins
end
|
Instance Attribute Details
27
28
29
|
# File 'lib/confctl/swpins/core.rb', line 27
def channels
@channels
end
|
#name ⇒ String
18
19
20
|
# File 'lib/confctl/swpins/core.rb', line 18
def name
@name
end
|
#path ⇒ String
21
22
23
|
# File 'lib/confctl/swpins/core.rb', line 21
def path
@path
end
|
24
25
26
|
# File 'lib/confctl/swpins/core.rb', line 24
def specs
@specs
end
|
Class Method Details
7
8
9
10
11
12
13
|
# File 'lib/confctl/swpins/core.rb', line 7
def self.get
return @instance if @instance
@instance = new
@instance.parse
@instance
end
|
Instance Method Details
#parse ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/confctl/swpins/core.rb', line 42
def parse
@specs = {}
channels.each do |chan|
chan.specs.each do |name, chan_spec|
s = chan_spec.clone
s.channel = chan.name
specs[name] = s
end
end
@json_specs = if File.exist?(path)
JSON.parse(File.read(path))
else
{}
end
nix_specs.each do |name, nix_opts|
specs[name] = Swpins::Spec.for(nix_opts['type'].to_sym).new(
name,
nix_opts[nix_opts['type']],
json_specs[name]
)
end
end
|
#pre_evaluate ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/confctl/swpins/core.rb', line 100
def pre_evaluate
nix = ConfCtl::Nix.new
paths = nix.eval_core_swpins
FileUtils.mkdir_p(cache_dir)
paths.each do |pin, path|
name = "core-swpin.#{pin}"
link = File.join(cache_dir, name)
replace_symlink(link, path)
ConfCtl::GCRoot.add(name, link) unless ConfCtl::GCRoot.exist?(name)
end
end
|
#pre_evaluated_store_paths ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/confctl/swpins/core.rb', line 114
def pre_evaluated_store_paths
swpins_path = File.join(cache_dir, 'core.swpins')
return unless File.exist?(swpins_path)
swpins = JSON.parse(File.read(swpins_path))
missing_path = swpins.each_value.detect do |path|
!Dir.exist?(path)
end
return if missing_path
swpins
end
|
#save ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/confctl/swpins/core.rb', line 74
def save
custom = {}
specs.each do |name, s|
custom[name] = s unless s.from_channel?
end
if custom.empty?
begin
File.unlink(path)
rescue Errno::ENOENT
end
else
tmp = "#{path}.new"
FileUtils.mkdir_p(ConfCtl::Swpins.core_dir)
File.open(tmp, 'w') do |f|
f.puts(JSON.pretty_generate(custom))
end
File.rename(tmp, path)
end
end
|
#valid? ⇒ Boolean
70
71
72
|
# File 'lib/confctl/swpins/core.rb', line 70
def valid?
specs.values.all?(&:valid?)
end
|