cfa 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: b0bc2e08acdb945ee444cd4cc4161f8486269624
4
- data.tar.gz: 63f48a1e6955ed2eaf9ab2a2a7e349fbc599e181
3
+ metadata.gz: 2a42d93bb712da73feacfe946e0c86f5d4dd7e58
4
+ data.tar.gz: 685ff8ce8306ee7fc6774d6315467025d7949a56
5
5
  SHA512:
6
- metadata.gz: 3d378441e8342f71da3787af6f8c4addcad952421b60928546eb9c7c455455cfb482cc9ae398f219c8d9456fefd20d1c79465d107f84676fb458c66245d1b948
7
- data.tar.gz: 187f9e0e23a30f3b952aed40f028d193d759581ea7801f3b945218da964f90a4ef2f42e669507c6ebce8c4a9f015b2e07a506622869f38e7d13faf2e0eaae3bf
6
+ metadata.gz: 4bfc91bbc8091d276004cfc5f772c13bc146ae52df5e5843afa22548c2ab00683a06c6a48323b12fd54cc7f000eee31839945aee7e2d2313f072563892fb427a
7
+ data.tar.gz: 784e7db8da973a2f64e11e82f9e93a25206afb5ae75daca59e027e7ca1e18ba7f14c1062c279cf6dac5bd4a8079becf015ac186e13f745989fd53b002737b78c
@@ -1,8 +1,8 @@
1
1
  require "augeas"
2
2
  require "forwardable"
3
- require "config_files_api/placer"
3
+ require "cfa/placer"
4
4
 
5
- module ConfigFilesApi
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 = ConfigFilesApi::AugeasParser.new("sysconfig.lns")
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 ConfigFilesApi
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 to
9
- # string and vice versa. It have to provide methods
10
- # `string #serialize(object)` and `object #parse(string)`.
11
- # For example see {ConfigFilesApi::AugeasParser}
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 {ConfigFilesApi::MemoryFile}
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 ConfigFilesApi
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
- def initialize(key: nil, collection: nil, value_matcher: nil)
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
@@ -1,4 +1,4 @@
1
- module ConfigFilesApi
1
+ module CFA
2
2
  # memory file is used when string is stored only in memory.
3
3
  # Useful for testing. For remote read or socket read, own File class
4
4
  # creation is recommended.
@@ -1,4 +1,4 @@
1
- module ConfigFilesApi
1
+ module CFA
2
2
  # allows to place element at the end of configuration. Default one.
3
3
  class AppendPlacer
4
4
  def new_element(tree)
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.1.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-03 00:00:00.000000000 Z
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/config_files_api/augeas_parser.rb
37
- - lib/config_files_api/base_model.rb
38
- - lib/config_files_api/matcher.rb
39
- - lib/config_files_api/memory_file.rb
40
- - lib/config_files_api/placer.rb
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.4.5.1
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 model on top of configuration
64
- file
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: