cfa 0.7.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cfa/augeas_parser.rb +3 -0
- data/lib/cfa/augeas_parser/keys_cache.rb +2 -0
- data/lib/cfa/augeas_parser/reader.rb +2 -0
- data/lib/cfa/augeas_parser/writer.rb +2 -0
- data/lib/cfa/base_model.rb +25 -15
- data/lib/cfa/matcher.rb +2 -0
- data/lib/cfa/memory_file.rb +2 -0
- data/lib/cfa/placer.rb +8 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a1b7d04b80d8f3847c52a299c581eb93ce99504aa21df9ff777766fbdd9a693
|
4
|
+
data.tar.gz: eb11d86a2949be4b60227c4e6a2d834ad8c8fa9f142db99bbd4b011827cc27aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f6e65715be7e500b23ab82c025082c97c035af9ca878f76543fa571b3a22ea3feda7dc535fd974704d5e6b2a13465723068fa066dcd7eef75a1e28b9023d4bf
|
7
|
+
data.tar.gz: c4e7641eb00264924223db6491e09a80f4acb1c987074c579e63e78b22eae6caa94fe57319ba28d9fe4b4fea5a703f097579ce9a413641fc29c52decc364f09e
|
data/lib/cfa/augeas_parser.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "set"
|
2
4
|
require "augeas"
|
3
5
|
require "forwardable"
|
@@ -323,6 +325,7 @@ module CFA
|
|
323
325
|
@data.insert(index, new_entry)
|
324
326
|
# the entry is not yet in the tree
|
325
327
|
if old_entry[:operation] == :add
|
328
|
+
key = old_entry[:key]
|
326
329
|
@data.delete_if { |d| d[:key] == key }
|
327
330
|
else
|
328
331
|
old_entry[:operation] = :remove
|
data/lib/cfa/base_model.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "cfa/matcher"
|
2
4
|
require "cfa/placer"
|
3
5
|
# FIXME: tree should be generic and not augeas specific,
|
@@ -37,8 +39,7 @@ module CFA
|
|
37
39
|
# then *parser* may raise an error.
|
38
40
|
# A properly written BaseModel subclass should prevent that by preventing
|
39
41
|
# insertion of such values in the first place.
|
40
|
-
def save
|
41
|
-
merge_changes if changes_only
|
42
|
+
def save
|
42
43
|
@parser.file_name = @file_path if @parser.respond_to?(:file_name=)
|
43
44
|
@file_handler.write(@file_path, @parser.serialize(data))
|
44
45
|
end
|
@@ -131,13 +132,6 @@ module CFA
|
|
131
132
|
|
132
133
|
attr_accessor :data
|
133
134
|
|
134
|
-
def merge_changes
|
135
|
-
new_data = data.dup
|
136
|
-
read
|
137
|
-
# TODO: recursive merge
|
138
|
-
data.merge(new_data)
|
139
|
-
end
|
140
|
-
|
141
135
|
# Modify an **existing** entry and return `true`,
|
142
136
|
# or do nothing and return `false`.
|
143
137
|
# @return [Boolean]
|
@@ -172,10 +166,16 @@ module CFA
|
|
172
166
|
end
|
173
167
|
end
|
174
168
|
|
175
|
-
#
|
169
|
+
# Represents a boolean value switcher in default grub configuration file.
|
176
170
|
# Allows easy switching and questioning for boolean value, even if
|
177
|
-
# represented by text in config file
|
171
|
+
# represented by text in config file.
|
172
|
+
# It's tristate: if unset, {#enabled?} and {#disabled?} return `nil`
|
173
|
+
# (but once set, we cannot return to an unset state).
|
178
174
|
class BooleanValue
|
175
|
+
# @param name [String]
|
176
|
+
# @param model [BaseModel]
|
177
|
+
# @param true_value [String]
|
178
|
+
# @param false_value [String]
|
179
179
|
def initialize(name, model, true_value: "true", false_value: "false")
|
180
180
|
@name = name
|
181
181
|
@model = model
|
@@ -183,32 +183,42 @@ module CFA
|
|
183
183
|
@false_value = false_value
|
184
184
|
end
|
185
185
|
|
186
|
+
# Set to *true*
|
186
187
|
def enable
|
187
188
|
@model.generic_set(@name, @true_value)
|
188
189
|
end
|
189
190
|
|
191
|
+
# Set to *false*
|
190
192
|
def disable
|
191
193
|
@model.generic_set(@name, @false_value)
|
192
194
|
end
|
193
195
|
|
196
|
+
# @return [Boolean,nil] true, false, (nil if undefined)
|
194
197
|
def enabled?
|
195
|
-
|
198
|
+
d = data
|
199
|
+
return nil unless d
|
196
200
|
|
197
|
-
|
201
|
+
d == @true_value
|
198
202
|
end
|
199
203
|
|
204
|
+
# @return [Boolean,nil] true, false, (nil if undefined)
|
200
205
|
def disabled?
|
201
|
-
|
206
|
+
d = data
|
207
|
+
return nil unless d
|
202
208
|
|
203
|
-
|
209
|
+
d != @true_value
|
204
210
|
end
|
205
211
|
|
212
|
+
# @return [Boolean]
|
213
|
+
# true if the key has a value;
|
214
|
+
# false if {#enabled?} and {#disabled?} return `nil`.
|
206
215
|
def defined?
|
207
216
|
!data.nil?
|
208
217
|
end
|
209
218
|
|
210
219
|
# sets boolean value, recommend to use for generic boolean setter.
|
211
220
|
# for constants prefer to use enable/disable
|
221
|
+
# @param value [Boolean]
|
212
222
|
def value=(value)
|
213
223
|
@model.generic_set(@name, value ? @true_value : @false_value)
|
214
224
|
end
|
data/lib/cfa/matcher.rb
CHANGED
data/lib/cfa/memory_file.rb
CHANGED
data/lib/cfa/placer.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CFA
|
2
4
|
# Places a new {AugeasElement} into an {AugeasTree}.
|
3
5
|
# @abstract Subclasses implement different ways **where**
|
4
6
|
# to place the entry by overriding {#new_element}.
|
5
7
|
class Placer
|
6
|
-
# @
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# @overload new_element(tree)
|
9
|
+
# @param [AugeasTree] tree
|
10
|
+
# @return [AugeasElement,Hash] the new element; it is empty!
|
11
|
+
# Note that the return value is actually a Hash; {AugeasElement}
|
12
|
+
# documents its structure.
|
10
13
|
def new_element(_tree)
|
11
14
|
raise NotImplementedError,
|
12
|
-
|
15
|
+
"Subclasses of #{Module.nesting.first} must override #{__method__}"
|
13
16
|
end
|
14
17
|
|
15
18
|
protected
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josef Reidinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-augeas
|