dotcfg 0.2.5.1 → 1.0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +52 -15
  3. data/Rakefile +15 -12
  4. data/VERSION +1 -1
  5. data/dotcfg.gemspec +6 -5
  6. data/test/dotcfg.rb +99 -0
  7. metadata +28 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fceaa5b08885b44f7253fcd0ae6c1a0d04341490
4
- data.tar.gz: a16b4eef3b2ae96a9fa03c909552d97b1a1cfa55
2
+ SHA256:
3
+ metadata.gz: 0007d2541e8532fec0e178a746ee16fdb912f11982fde3a37c02b8773af76691
4
+ data.tar.gz: 31312857a1ae306544500c59262275e4905509e8250d2192042c4db47dc561e3
5
5
  SHA512:
6
- metadata.gz: 7fe781e92e9307c2eafc8f8a30c8d531bd91083b76d349f4b080a54e0d977cb0b1cfbb818f4c7f3b5a8abbea61bd2089159537c6771fc0c36983fd754982c13f
7
- data.tar.gz: 86bfe8acee0d030bfb068ad9ecaa2e5679d2a84568875b5d40fe8de14c551b1a93eb2a1cf56671253ccc77a94845dccd3346402d6573da93ece5a6deae807dbc
6
+ metadata.gz: d3ac6d4557968bdfecffbe73fedf152b1db4e5a6d0274bae11b595ee9b84694ed0db682da902735aa54c1a0fe25eab512cb1ea7c5c87475a80686e2d0dc72201
7
+ data.tar.gz: 802a1677fe69d411a9d21fe5bb86cc3c01e5a250d368d4c2647dcf0479e426bb9f06b786eacdc7b22160eacb07793d3aa05c93177cf0a6bb48c53eed1a596640
data/README.md CHANGED
@@ -1,29 +1,66 @@
1
+ [![CI Status](https://github.com/rickhull/dotcfg/actions/workflows/ci.yaml/badge.svg)](https://github.com/rickhull/dotcfg/actions/workflows/ci.yaml)
1
2
  [![Gem Version](https://badge.fury.io/rb/dotcfg.svg)](http://badge.fury.io/rb/dotcfg)
2
3
  [![Code Climate](https://codeclimate.com/github/rickhull/dotcfg/badges/gpa.svg)](https://codeclimate.com/github/rickhull/dotcfg/badges)
3
- [![Dependency Status](https://gemnasium.com/rickhull/dotcfg.svg)](https://gemnasium.com/rickhull/dotcfg)
4
- [![Security Status](https://hakiri.io/github/rickhull/dotcfg/master.svg)](https://hakiri.io/github/rickhull/dotcfg/master)
5
4
 
6
- dotcfg
7
- ======
5
+ # dotcfg
6
+
8
7
  dotcfg is a simple, intuitive way for your app to store configuration data on the filesystem -- ideally within the user's home directory, presumably in a dotfile. If your config data can be represented by a Hash, then dotcfg can easily serialize and persist that data between runs.
9
8
 
10
- ### Serialization Formats
9
+ ## Serialization Formats
11
10
  dotcfg currently understands [JSON](http://json.org) and [YAML](http://yaml.org), defaulting to YAML.
12
11
 
13
- Installation
14
- ------------
15
- Install the gem:
12
+ # Usage
13
+
14
+ ## Install
15
+
16
+ 3 options:
17
+
18
+ * `git clone`
19
+ * `gem install`
20
+ * [Bundler](http://bundler.io/) `Gemfile`
21
+
22
+ ### `git clone`
23
+
24
+ Clone the repo, then `cd dotcfg`
25
+
26
+ Optional, if you use *direnv* and want to use Nix flakes to load a dev env:
27
+ `direnv allow`
28
+
29
+ From here, use `-I lib` with calls to e.g. `ruby` or `irb` to make dotcfg
30
+ available without having the gem installed. e.g.
31
+
16
32
  ```
17
- $ gem install dotcfg # sudo as necessary
33
+ $ irb -Ilib -rdotcfg
34
+
35
+ irb(main):001:0> CFG = DotCfg.new 'example.cfg'
36
+ =>
37
+ #<DotCfg:0x00007f75d06b83a0
38
+ ...
39
+ irb(main):002:0> CFG[:does_not_exist]
40
+ => nil
41
+ irb(main):003:0> CFG['hello'] = 'world'
42
+ => "world"
43
+ irb(main):004:0> CFG['hello']
44
+ => "world"
45
+ irb(main):005:0>
18
46
  ```
19
47
 
20
- Or, if using [Bundler](http://bundler.io/), add to your Gemfile:
48
+ ### `gem install`
49
+
50
+ ```
51
+ gem install dotcfg
52
+ ```
53
+
54
+ ### [Bundler](http://bundler.io/) `Gemfile`
55
+
56
+ Add to your Gemfile:
57
+
21
58
  ```ruby
22
- gem 'dotcfg', '~> 0.1'
59
+ gem 'dotcfg', '~> 1.0'
23
60
  ```
24
61
 
25
- Usage
26
- -----
62
+ ## Usage
63
+
27
64
  ```ruby
28
65
  require 'dotcfg'
29
66
 
@@ -68,8 +105,8 @@ CFG.serialize
68
105
  # ...
69
106
  ```
70
107
 
71
- Details
72
- -------
108
+ ## Details
109
+
73
110
  ### Symbols and Strings
74
111
 
75
112
  When JSON consumes symbols, it emits strings. So if you want to use JSON, use strings rather than symbols for your config items. YAML cycles strings and symbols independently, so stick to one or the other.
data/Rakefile CHANGED
@@ -1,3 +1,17 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new :test do |t|
4
+ t.pattern = 'test/*.rb'
5
+ t.warning = true
6
+ end
7
+
8
+ Rake::TestTask.new bench: :test do |t|
9
+ t.pattern = 'test/bench/*.rb'
10
+ t.warning = true
11
+ end
12
+
13
+ task default: :test
14
+
1
15
  begin
2
16
  require 'buildar'
3
17
 
@@ -7,16 +21,5 @@ begin
7
21
  b.use_git = true
8
22
  end
9
23
  rescue LoadError
10
- # ok
11
- end
12
-
13
- begin
14
- require 'rake/testtask'
15
-
16
- Rake::TestTask.new do |t|
17
- t.test_files = FileList['test/**/*.rb']
18
- end
19
- desc "Run tests"
20
- rescue Exception => e
21
- warn "rake/testtask error: #{e}"
24
+ warn "buildar tasks unavailable"
22
25
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5.1
1
+ 1.0.0.1
data/dotcfg.gemspec CHANGED
@@ -5,13 +5,13 @@ Gem::Specification.new do |s|
5
5
  s.homepage = 'https://github.com/rickhull/dotcfg'
6
6
  s.license = 'MIT'
7
7
  s.description = 'JSON and YAML config serialization and persistence'
8
- s.add_runtime_dependency 'json', '>= 1.7.7'
8
+
9
+ s.required_ruby_version = '~> 3.0'
10
+ s.add_runtime_dependency 'json', '~> 2.5'
11
+ s.add_runtime_dependency 'yaml', '~> 0.1'
9
12
  s.add_development_dependency 'buildar', '~> 2'
10
13
 
11
- # set version dynamically from version file contents
12
- this_dir = File.expand_path('..', __FILE__)
13
- version_file = File.join(this_dir, 'VERSION')
14
- s.version = File.read(version_file).chomp
14
+ s.version = File.read(File.join(__dir__, 'VERSION')).chomp
15
15
 
16
16
  s.files = %w[
17
17
  dotcfg.gemspec
@@ -19,5 +19,6 @@ Gem::Specification.new do |s|
19
19
  README.md
20
20
  Rakefile
21
21
  lib/dotcfg.rb
22
+ test/dotcfg.rb
22
23
  ]
23
24
  end
data/test/dotcfg.rb ADDED
@@ -0,0 +1,99 @@
1
+ require 'minitest/autorun'
2
+ require 'dotcfg'
3
+
4
+ describe DotCfg do
5
+ def new_filename
6
+ begin
7
+ Dir::Tmpname.make_tmpname('/tmp/dotcfg', nil)
8
+ rescue
9
+ ['/tmp/dotcfg', rand(9**9)].join
10
+ end
11
+ end
12
+
13
+ before do
14
+ @filename = new_filename
15
+ @dc = DotCfg.new(@filename)
16
+ end
17
+
18
+ describe "bad initialization" do
19
+ it "raises" do
20
+ expect { DotCfg.new('does/not/exist') }.must_raise Errno::ENOENT
21
+ end
22
+ it "creates a new file" do
23
+ expect(File.exist?(@filename)).must_equal true
24
+ end
25
+ end
26
+
27
+ describe "config manipulation" do
28
+ describe "accessing keys" do
29
+ before do
30
+ @dc['hello'] = 'world'
31
+ end
32
+
33
+ describe "nonexistent keys" do
34
+ it "returns nil" do
35
+ expect(@dc[:does_not_exist]).must_be_nil
36
+ end
37
+ end
38
+
39
+ describe "existing keys" do
40
+ it "returns the value" do
41
+ expect(@dc['hello']).must_equal 'world'
42
+ end
43
+ end
44
+
45
+ describe "key removal" do
46
+ it "returns nil" do
47
+ @dc[:hello] = :world
48
+ expect(@dc[:hello]).must_equal :world
49
+ @dc.delete :hello
50
+ expect(@dc[:hello]).must_be_nil
51
+ end
52
+ end
53
+
54
+ after do
55
+ @dc.delete 'hello'
56
+ end
57
+ end
58
+ end
59
+
60
+ describe "serialization" do
61
+ before do
62
+ @dc['hello'] = 'world'
63
+ @dc['goodbye'] = 'cruel world'
64
+ end
65
+
66
+ it "serializes to a string" do
67
+ expect(@dc.serialize).must_be_kind_of String
68
+ end
69
+
70
+ it "deserializes its serialization" do
71
+ hsh = @dc.deserialize(@dc.serialize)
72
+ expect(hsh).must_be_kind_of Hash
73
+ expect(hsh).must_equal({ 'hello' => 'world', 'goodbye' => 'cruel world' })
74
+ expect(@dc['hello']).must_equal 'world'
75
+ expect(@dc['goodbye']).must_equal 'cruel world'
76
+ end
77
+
78
+ it "overwrites when deserializing" do
79
+ str = @dc.serialize
80
+ @dc.delete 'hello'
81
+ @dc.deserialize(str)
82
+ expect(@dc['hello']).must_equal 'world'
83
+ end
84
+
85
+ it "responds to pretty with a string" do
86
+ expect(@dc.pretty).must_be_kind_of String
87
+ end
88
+
89
+ # eh, needed?
90
+ after do
91
+ @dc.delete 'hello'
92
+ @dc.delete 'goodbye'
93
+ end
94
+ end
95
+
96
+ after do
97
+ File.unlink(@filename)
98
+ end
99
+ end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotcfg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5.1
4
+ version: 1.0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Hull
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.7.7
19
+ version: '2.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.7.7
26
+ version: '2.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yaml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: buildar
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +53,7 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '2'
41
55
  description: JSON and YAML config serialization and persistence
42
- email:
56
+ email:
43
57
  executables: []
44
58
  extensions: []
45
59
  extra_rdoc_files: []
@@ -49,28 +63,28 @@ files:
49
63
  - VERSION
50
64
  - dotcfg.gemspec
51
65
  - lib/dotcfg.rb
66
+ - test/dotcfg.rb
52
67
  homepage: https://github.com/rickhull/dotcfg
53
68
  licenses:
54
69
  - MIT
55
70
  metadata: {}
56
- post_install_message:
71
+ post_install_message:
57
72
  rdoc_options: []
58
73
  require_paths:
59
74
  - lib
60
75
  required_ruby_version: !ruby/object:Gem::Requirement
61
76
  requirements:
62
- - - ">="
77
+ - - "~>"
63
78
  - !ruby/object:Gem::Version
64
- version: '0'
79
+ version: '3.0'
65
80
  required_rubygems_version: !ruby/object:Gem::Requirement
66
81
  requirements:
67
82
  - - ">="
68
83
  - !ruby/object:Gem::Version
69
84
  version: '0'
70
85
  requirements: []
71
- rubyforge_project:
72
- rubygems_version: 2.6.8
73
- signing_key:
86
+ rubygems_version: 3.2.26
87
+ signing_key:
74
88
  specification_version: 4
75
89
  summary: simple filesystem de/serialization for app configs
76
90
  test_files: []