yamload 0.0.4 → 0.0.5
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/yamload/loader.rb +10 -3
- data/lib/yamload/version.rb +1 -1
- data/spec/fixtures/empty.yml +1 -0
- data/spec/loader_spec.rb +17 -2
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 161994d9e2aa6fad809740f83e92e1753b0b49ad
|
4
|
+
data.tar.gz: addc311926f473c5ab0863322bfda534b05ee992
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb4d5eef83acc10360ce1b93c03626f1728ec27a0220f96112fcef79ae676af874cec54f1732aa4f981ceb5401a714f3d151de4c2e3272d0df587ab13040dc02
|
7
|
+
data.tar.gz: 8efea007b9e6ba02aaa801ec3dc4ab29af39a3b821631c95867c3a68a38765a60028f00a9f4d391407b5913563f5b30de0d5c7569e6ae37af0ff7d859fd1a7ff
|
data/lib/yamload/loader.rb
CHANGED
@@ -26,7 +26,11 @@ module Yamload
|
|
26
26
|
loaded_hash
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
attr_writer :schema
|
30
|
+
|
31
|
+
def schema
|
32
|
+
@schema ||= {}
|
33
|
+
end
|
30
34
|
|
31
35
|
attr_writer :defaults
|
32
36
|
|
@@ -43,7 +47,7 @@ module Yamload
|
|
43
47
|
|
44
48
|
def validate!
|
45
49
|
@error = nil
|
46
|
-
ClassyHash.validate(loaded_hash,
|
50
|
+
ClassyHash.validate(loaded_hash, schema)
|
47
51
|
rescue RuntimeError => e
|
48
52
|
@error = e.message
|
49
53
|
raise SchemaError, @error
|
@@ -57,7 +61,10 @@ module Yamload
|
|
57
61
|
private
|
58
62
|
|
59
63
|
def load
|
60
|
-
|
64
|
+
fail IOError, "#{@file}.yml could not be found" unless exist?
|
65
|
+
YAML.load_file(filepath).tap do |hash|
|
66
|
+
fail IOError, "#{@file}.yml is invalid" unless hash.is_a? Hash
|
67
|
+
end
|
61
68
|
end
|
62
69
|
|
63
70
|
def filepath
|
data/lib/yamload/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
|
data/spec/loader_spec.rb
CHANGED
@@ -11,10 +11,16 @@ describe Yamload do
|
|
11
11
|
context 'with a non existing file' do
|
12
12
|
let(:file) { :non_existing }
|
13
13
|
specify { expect(loader).not_to exist }
|
14
|
+
specify { expect { config }.to raise_error IOError, 'non_existing.yml could not be found' }
|
14
15
|
end
|
15
16
|
|
16
|
-
let(:config)
|
17
|
-
|
17
|
+
let(:config) { loader.loaded_hash }
|
18
|
+
|
19
|
+
context 'with an empty file' do
|
20
|
+
let(:file) { :empty }
|
21
|
+
specify { expect(loader).to exist }
|
22
|
+
specify { expect { config }.to raise_error IOError, 'empty.yml is invalid' }
|
23
|
+
end
|
18
24
|
|
19
25
|
let(:expected_config) {
|
20
26
|
{
|
@@ -54,6 +60,9 @@ describe Yamload do
|
|
54
60
|
}
|
55
61
|
|
56
62
|
specify { expect(config).to eq expected_config }
|
63
|
+
|
64
|
+
let(:config_obj) { loader.obj }
|
65
|
+
|
57
66
|
specify { expect(config_obj.test).to eq true }
|
58
67
|
specify { expect(config_obj.users[0].first_name).to eq 'Testy' }
|
59
68
|
specify { expect(config_obj.users[0].last_name).to eq 'Tester' }
|
@@ -93,6 +102,12 @@ describe Yamload do
|
|
93
102
|
end
|
94
103
|
end
|
95
104
|
|
105
|
+
context 'when no schema is defined' do
|
106
|
+
specify { expect(loader).to be_valid }
|
107
|
+
specify { expect(loader.error).to be_nil }
|
108
|
+
specify { expect { loader.validate! }.not_to raise_error }
|
109
|
+
end
|
110
|
+
|
96
111
|
context 'when a schema is defined' do
|
97
112
|
let(:schema) {
|
98
113
|
{
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yamload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Berardi
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/yamload/hash_to_immutable_object.rb
|
171
171
|
- lib/yamload/loader.rb
|
172
172
|
- lib/yamload/version.rb
|
173
|
+
- spec/fixtures/empty.yml
|
173
174
|
- spec/fixtures/test.yml
|
174
175
|
- spec/loader_spec.rb
|
175
176
|
- spec/spec_helper.rb
|
@@ -199,6 +200,7 @@ signing_key:
|
|
199
200
|
specification_version: 4
|
200
201
|
summary: YAML files loader
|
201
202
|
test_files:
|
203
|
+
- spec/fixtures/empty.yml
|
202
204
|
- spec/fixtures/test.yml
|
203
205
|
- spec/loader_spec.rb
|
204
206
|
- spec/spec_helper.rb
|