cfa 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/{config_files_api → cfa}/augeas_parser.rb +8 -3
- data/lib/{config_files_api → cfa}/base_model.rb +7 -6
- data/lib/{config_files_api → cfa}/matcher.rb +4 -2
- data/lib/{config_files_api → cfa}/memory_file.rb +1 -1
- data/lib/{config_files_api → cfa}/placer.rb +1 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a42d93bb712da73feacfe946e0c86f5d4dd7e58
|
4
|
+
data.tar.gz: 685ff8ce8306ee7fc6774d6315467025d7949a56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bfc91bbc8091d276004cfc5f772c13bc146ae52df5e5843afa22548c2ab00683a06c6a48323b12fd54cc7f000eee31839945aee7e2d2313f072563892fb427a
|
7
|
+
data.tar.gz: 784e7db8da973a2f64e11e82f9e93a25206afb5ae75daca59e027e7ca1e18ba7f14c1062c279cf6dac5bd4a8079becf015ac186e13f745989fd53b002737b78c
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require "augeas"
|
2
2
|
require "forwardable"
|
3
|
-
require "
|
3
|
+
require "cfa/placer"
|
4
4
|
|
5
|
-
module
|
5
|
+
module CFA
|
6
6
|
# Represents list of same config options in augeas.
|
7
7
|
# For example comments are often stored in collections.
|
8
8
|
class AugeasCollection
|
@@ -175,7 +175,7 @@ module ConfigFilesApi
|
|
175
175
|
# @example read, print, modify and serialize again
|
176
176
|
# require "config_files/augeas_parser"
|
177
177
|
#
|
178
|
-
# parser =
|
178
|
+
# parser = CFA::AugeasParser.new("sysconfig.lns")
|
179
179
|
# data = parser.parse(File.read("/etc/default/grub"))
|
180
180
|
#
|
181
181
|
# puts data["GRUB_DISABLE_OS_PROBER"]
|
@@ -218,6 +218,11 @@ module ConfigFilesApi
|
|
218
218
|
end
|
219
219
|
end
|
220
220
|
|
221
|
+
# Returns empty tree that can be filled for future serialization
|
222
|
+
def empty
|
223
|
+
AugeasTree.new
|
224
|
+
end
|
225
|
+
|
221
226
|
private
|
222
227
|
|
223
228
|
def report_error(aug)
|
@@ -1,23 +1,24 @@
|
|
1
|
-
module
|
1
|
+
module CFA
|
2
2
|
# A base class for models. Represents a configuration file as an object
|
3
3
|
# with domain-specific attributes/methods. For persistent storage,
|
4
4
|
# use load and save,
|
5
5
|
# Non-responsibilities: actual storage and parsing (both delegated).
|
6
6
|
# There is no caching involved.
|
7
7
|
class BaseModel
|
8
|
-
# @param parser [.parse, .serialize] parser that can convert object
|
9
|
-
# string and vice versa. It have to provide methods
|
10
|
-
# `string #serialize(object)
|
11
|
-
# For example see {
|
8
|
+
# @param parser [.parse, .serialize, .empty] parser that can convert object
|
9
|
+
# to string and vice versa. It have to provide methods
|
10
|
+
# `string #serialize(object)`, `object #parse(string)` and `object #empty`
|
11
|
+
# For example see {CFA::AugeasParser}
|
12
12
|
# @param file_path [String] expected path passed to file_handler
|
13
13
|
# @param file_handler [.read, .write] object, that can read/write string.
|
14
14
|
# It have to provide methods `string read(string)` and
|
15
|
-
# `write(string, string)`. For example see {
|
15
|
+
# `write(string, string)`. For example see {CFA::MemoryFile}
|
16
16
|
def initialize(parser, file_path, file_handler: File)
|
17
17
|
@file_handler = file_handler
|
18
18
|
@parser = parser
|
19
19
|
@file_path = file_path
|
20
20
|
@loaded = false
|
21
|
+
self.data = parser.empty
|
21
22
|
end
|
22
23
|
|
23
24
|
def save(changes_only: false)
|
@@ -1,13 +1,15 @@
|
|
1
|
-
module
|
1
|
+
module CFA
|
2
2
|
# Class used to create matcher, that allows to find specific option in augeas
|
3
3
|
# tree or subtree
|
4
4
|
# TODO: examples of usage
|
5
5
|
class Matcher
|
6
|
-
|
6
|
+
# @block_yield matcher based on block. block gets two params, key and value
|
7
|
+
def initialize(key: nil, collection: nil, value_matcher: nil, &block)
|
7
8
|
@matcher = lambda do |element|
|
8
9
|
return false unless key_match?(element, key)
|
9
10
|
return false unless collection_match?(element, collection)
|
10
11
|
return false unless value_match?(element, value_matcher)
|
12
|
+
return false unless !block || block.call(element[:key], element[:value])
|
11
13
|
return true
|
12
14
|
end
|
13
15
|
end
|
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: 0.2.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: 2015-12-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-augeas
|
@@ -33,13 +33,14 @@ executables: []
|
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
-
- lib/
|
37
|
-
- lib/
|
38
|
-
- lib/
|
39
|
-
- lib/
|
40
|
-
- lib/
|
36
|
+
- lib/cfa/augeas_parser.rb
|
37
|
+
- lib/cfa/base_model.rb
|
38
|
+
- lib/cfa/matcher.rb
|
39
|
+
- lib/cfa/memory_file.rb
|
40
|
+
- lib/cfa/placer.rb
|
41
41
|
homepage: http://github.com/config-files-api/config_files_api
|
42
|
-
licenses:
|
42
|
+
licenses:
|
43
|
+
- LGPLv3
|
43
44
|
metadata: {}
|
44
45
|
post_install_message:
|
45
46
|
rdoc_options: []
|
@@ -57,10 +58,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
58
|
version: 1.3.6
|
58
59
|
requirements: []
|
59
60
|
rubyforge_project:
|
60
|
-
rubygems_version: 2.
|
61
|
+
rubygems_version: 2.2.2
|
61
62
|
signing_key:
|
62
63
|
specification_version: 4
|
63
|
-
summary: CFA (Config Files API) provides easy way to create
|
64
|
-
|
64
|
+
summary: CFA (Config Files API) provides an easy way to create models on top of configuration
|
65
|
+
files
|
65
66
|
test_files: []
|
66
67
|
has_rdoc:
|