kefir 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/kefir/file_store.rb +8 -5
- data/lib/kefir/version.rb +1 -1
- data/lib/kefir.rb +3 -4
- data/spec/kefir/config_spec.rb +4 -2
- data/spec/kefir/file_store_spec.rb +50 -5
- data/spec/kefir_spec.rb +10 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcea3ed21f0ba7fe31416b37b53786d25aaf13e9
|
4
|
+
data.tar.gz: bfd8a92a87f778b27c4664a10d93908aa7fe6222
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eeb38996768205b6aeb63dbd484c0f0568ab6a9e37db182141a6fe350eadaccc4e542adf62ec275ac9b3b85b3a332758b1622ea762bf466a48331837ffa8b75
|
7
|
+
data.tar.gz: ad213f47117c01e9f56a132c9be97483f33e04e1dddd9a57fd7e99d1584e7e503f92c719eb025c1337cdf0386592189374c6626c9c761140034b82287c2735c3
|
data/Gemfile.lock
CHANGED
data/lib/kefir/file_store.rb
CHANGED
@@ -2,17 +2,20 @@ module Kefir
|
|
2
2
|
class FileStore
|
3
3
|
attr_reader :path
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(options = {})
|
6
|
+
@dir = options[:cwd]
|
7
|
+
@path = File.expand_path(options[:config_name], @dir)
|
7
8
|
end
|
8
9
|
|
9
10
|
def read
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
FileUtils.mkdir_p(@dir)
|
12
|
+
YAML.load_file(@path) || {}
|
13
|
+
rescue Errno::ENOENT
|
14
|
+
{}
|
13
15
|
end
|
14
16
|
|
15
17
|
def write(data)
|
18
|
+
FileUtils.mkdir_p(@dir)
|
16
19
|
File.write(@path, YAML.dump(data))
|
17
20
|
end
|
18
21
|
end
|
data/lib/kefir/version.rb
CHANGED
data/lib/kefir.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'dig_rb'
|
2
|
+
require 'fileutils'
|
2
3
|
require 'env_paths'
|
3
4
|
require 'yaml'
|
4
5
|
require 'kefir/version'
|
@@ -16,7 +17,7 @@ module Kefir
|
|
16
17
|
raise MissingNamespaceError, 'You must supply a namespace for your configuration files' if namespace.nil? || namespace.empty?
|
17
18
|
|
18
19
|
parsed_options = parse_options(namespace, options)
|
19
|
-
store = FileStore.new(parsed_options
|
20
|
+
store = FileStore.new(parsed_options)
|
20
21
|
|
21
22
|
Config.new(store, options)
|
22
23
|
end
|
@@ -25,9 +26,7 @@ module Kefir
|
|
25
26
|
|
26
27
|
def self.parse_options(namespace, options)
|
27
28
|
parsed = DEFAULT_OPTIONS.merge(options)
|
28
|
-
cwd = parsed.fetch(:cwd, EnvPaths.get(namespace).config)
|
29
|
-
parsed[:config_file_path] = File.expand_path(parsed[:config_name], cwd)
|
30
|
-
|
29
|
+
parsed[:cwd] = parsed.fetch(:cwd, EnvPaths.get(namespace).config)
|
31
30
|
parsed
|
32
31
|
end
|
33
32
|
end
|
data/spec/kefir/config_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
RSpec.describe Kefir::Config do
|
2
|
-
let(:store_double)
|
2
|
+
let(:store_double) do
|
3
|
+
double(Kefir::FileStore, read: {}, write: nil, path: 'custom_path')
|
4
|
+
end
|
3
5
|
let(:config) { Kefir::Config.new(store_double, {}) }
|
4
6
|
|
5
7
|
describe 'initialize' do
|
@@ -74,7 +76,7 @@ RSpec.describe Kefir::Config do
|
|
74
76
|
|
75
77
|
describe 'path' do
|
76
78
|
it 'returns the path of its store' do
|
77
|
-
store =
|
79
|
+
store = double(Kefir::FileStore, path: '/config/path')
|
78
80
|
config = Kefir::Config.new(store, {})
|
79
81
|
|
80
82
|
expect(config.path).to eq('/config/path')
|
@@ -1,6 +1,12 @@
|
|
1
1
|
RSpec.describe Kefir::FileStore do
|
2
|
-
let(:data)
|
3
|
-
|
2
|
+
let(:data) do
|
3
|
+
{
|
4
|
+
secret: 'dont tell',
|
5
|
+
users: [{ name: 'bob' }, { name: 'jane' }]
|
6
|
+
}
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:file_path) { File.join(@temp_dir, 'config.yml') }
|
4
10
|
|
5
11
|
before(:each) do
|
6
12
|
@temp_dir = Dir.mktmpdir
|
@@ -10,9 +16,14 @@ RSpec.describe Kefir::FileStore do
|
|
10
16
|
FileUtils.remove_dir(@temp_dir)
|
11
17
|
end
|
12
18
|
|
19
|
+
it 'gives its path' do
|
20
|
+
store = Kefir::FileStore.new(cwd: @temp_dir, config_name: 'config.yml')
|
21
|
+
expect(store.path).to eq(File.join(@temp_dir, 'config.yml'))
|
22
|
+
end
|
23
|
+
|
13
24
|
it 'reads a configuration file' do
|
14
25
|
File.write(file_path, YAML.dump(data))
|
15
|
-
Kefir::FileStore.new(
|
26
|
+
Kefir::FileStore.new(cwd: @temp_dir, config_name: 'config.yml')
|
16
27
|
parsed = YAML.load_file(file_path)
|
17
28
|
|
18
29
|
expect(parsed).to eq(
|
@@ -26,8 +37,7 @@ RSpec.describe Kefir::FileStore do
|
|
26
37
|
|
27
38
|
it 'writes to a configuration file' do
|
28
39
|
File.write(file_path, YAML.dump(data))
|
29
|
-
store = Kefir::FileStore.new(
|
30
|
-
|
40
|
+
store = Kefir::FileStore.new(cwd: @temp_dir, config_name: 'config.yml')
|
31
41
|
store.write(data.merge(secret: 'changed'))
|
32
42
|
|
33
43
|
parsed = YAML.load_file(file_path)
|
@@ -40,4 +50,39 @@ RSpec.describe Kefir::FileStore do
|
|
40
50
|
]
|
41
51
|
)
|
42
52
|
end
|
53
|
+
|
54
|
+
it 'returns an empty hash when file is empty' do
|
55
|
+
FileUtils.touch(file_path)
|
56
|
+
store = Kefir::FileStore.new(cwd: @temp_dir, config_name: 'config.yml')
|
57
|
+
expect(store.read).to eq({})
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'creates nonexistant directories' do
|
61
|
+
nonexistant_path = File.join(@temp_dir, 'cool/beans')
|
62
|
+
Kefir::FileStore.new(
|
63
|
+
cwd: nonexistant_path,
|
64
|
+
config_name: 'config.yml'
|
65
|
+
).read
|
66
|
+
expect(File.directory?(nonexistant_path)).to eq(true)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns an empty hash when reading nonexistant files' do
|
70
|
+
store = Kefir::FileStore.new(
|
71
|
+
cwd: @temp_dir,
|
72
|
+
config_name: 'config.yml'
|
73
|
+
)
|
74
|
+
|
75
|
+
expect(store.read).to eq({})
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'succesfully writes to nonexistant files' do
|
79
|
+
store = Kefir::FileStore.new(
|
80
|
+
cwd: @temp_dir,
|
81
|
+
config_name: 'config.yml'
|
82
|
+
)
|
83
|
+
|
84
|
+
store.write(foo: 'bar')
|
85
|
+
|
86
|
+
expect(YAML.load_file(File.join(@temp_dir, 'config.yml'))).to eq(foo: 'bar')
|
87
|
+
end
|
43
88
|
end
|
data/spec/kefir_spec.rb
CHANGED
@@ -13,7 +13,8 @@ RSpec.describe Kefir do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'returns a fully functioning config object that can read config' do
|
16
|
-
allow(File).to receive(:
|
16
|
+
allow(File).to receive(:directory?).and_return(true)
|
17
|
+
allow(YAML).to receive(:load_file).and_return('user' => 'bob')
|
17
18
|
|
18
19
|
config = Kefir.config('test')
|
19
20
|
|
@@ -21,7 +22,8 @@ RSpec.describe Kefir do
|
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'returns a fully functioning config object that can write config' do
|
24
|
-
allow(File).to receive(:
|
25
|
+
allow(File).to receive(:directory?).and_return(true)
|
26
|
+
allow(YAML).to receive(:load_file).with(/config\.yml$/).and_return(false)
|
25
27
|
expect(File).to receive(:write)
|
26
28
|
|
27
29
|
config = Kefir.config('test')
|
@@ -30,14 +32,16 @@ RSpec.describe Kefir do
|
|
30
32
|
|
31
33
|
context 'options' do
|
32
34
|
it 'provides defaults' do
|
33
|
-
|
35
|
+
allow(File).to receive(:directory?).and_return(true)
|
36
|
+
expect(YAML).to receive(:load_file).with(/config\.yml$/).and_return(false)
|
34
37
|
config = Kefir.config('test')
|
35
38
|
config.get(:foo)
|
36
39
|
end
|
37
40
|
|
38
41
|
it 'allows overriding current directory' do
|
39
42
|
custom_cwd = File.expand_path('custom/path', '/')
|
40
|
-
|
43
|
+
allow(File).to receive(:directory?).and_return(true)
|
44
|
+
expect(YAML).to receive(:load_file).with(File.join(custom_cwd, 'config.yml')).and_return(false)
|
41
45
|
|
42
46
|
config = Kefir.config('test', cwd: custom_cwd)
|
43
47
|
config.get(:foo)
|
@@ -45,7 +49,8 @@ RSpec.describe Kefir do
|
|
45
49
|
|
46
50
|
it 'allows overriding the :config_name' do
|
47
51
|
custom_cwd = File.expand_path('custom/path', '/')
|
48
|
-
|
52
|
+
allow(File).to receive(:directory?).and_return(true)
|
53
|
+
expect(YAML).to receive(:load_file).with(File.join(custom_cwd, 'custom_config_name.yml')).and_return(false)
|
49
54
|
|
50
55
|
config = Kefir.config('test', cwd: custom_cwd, config_name: 'custom_config_name.yml')
|
51
56
|
config.get(:foo)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kefir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Tomlin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: env_paths
|