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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0256a5d406e5ed0a4bbedd2c59fe6ed3947b35286697301543285c8e588e1753
4
- data.tar.gz: 0361b40d6ee2a3fc94a0f2218a2cec6c4c6c2c833942d62fe67513b65d776450
3
+ metadata.gz: 4a1b7d04b80d8f3847c52a299c581eb93ce99504aa21df9ff777766fbdd9a693
4
+ data.tar.gz: eb11d86a2949be4b60227c4e6a2d834ad8c8fa9f142db99bbd4b011827cc27aa
5
5
  SHA512:
6
- metadata.gz: d0b02d8195de9b6f72e347924253ad534b76de671f44f8c598f324ab1059473aa7f5039c0f1b16e5a2eb85651ed0fc51d162dd5c49cd4b0ff0efc3be6c5b66d3
7
- data.tar.gz: d576b43dab99a7711f6012a4c270d53a409e5b7f2b9c7868dd9e31a87de6d616a0c4565e22970a1e481801b0572c8bbe1229b5f56d6f677d66419fa651da91df
6
+ metadata.gz: 0f6e65715be7e500b23ab82c025082c97c035af9ca878f76543fa571b3a22ea3feda7dc535fd974704d5e6b2a13465723068fa066dcd7eef75a1e28b9023d4bf
7
+ data.tar.gz: c4e7641eb00264924223db6491e09a80f4acb1c987074c579e63e78b22eae6caa94fe57319ba28d9fe4b4fea5a703f097579ce9a413641fc29c52decc364f09e
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CFA
2
4
  # A cache that holds all avaiable keys in an Augeas tree. It is used to
3
5
  # prevent too many `aug.match` calls which are expensive.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "cfa/augeas_parser/keys_cache"
2
4
  require "cfa/augeas_parser"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CFA
2
4
  # The goal of this class is to write the data stored in {AugeasTree}
3
5
  # back to Augeas.
@@ -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(changes_only: false)
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
- # Representing boolean value switcher in default grub configuration file.
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
- return nil unless data
198
+ d = data
199
+ return nil unless d
196
200
 
197
- data == @true_value
201
+ d == @true_value
198
202
  end
199
203
 
204
+ # @return [Boolean,nil] true, false, (nil if undefined)
200
205
  def disabled?
201
- return nil unless data
206
+ d = data
207
+ return nil unless d
202
208
 
203
- data != @true_value
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CFA
2
4
  # The Matcher is used as a predicate on {AugeasElement}.
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CFA
2
4
  # memory file is used when string is stored only in memory.
3
5
  # Useful for testing. For remote read or socket read, own File class
@@ -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
- # @param [AugeasTree] tree
7
- # @return [AugeasElement,Hash] the new element; it is empty!
8
- # Note that the return value is actually a Hash; {AugeasElement}
9
- # documents its structure.
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
- "Subclasses of #{Module.nesting.first} must override #{__method__}"
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.7.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: 2018-11-08 00:00:00.000000000 Z
11
+ date: 2019-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-augeas