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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95c0063635d01cefbf8b13f9ddcfd182b26ca813
4
- data.tar.gz: ba8848c099ce2a893a117504c7b3c35dc9a98668
3
+ metadata.gz: 161994d9e2aa6fad809740f83e92e1753b0b49ad
4
+ data.tar.gz: addc311926f473c5ab0863322bfda534b05ee992
5
5
  SHA512:
6
- metadata.gz: 36b03720933bad55161fd27024cb91d2d3ea332f53c20a004248576727cc56c0f2b9496a949fe902a83fd7228695c7cb052b919abe1476a9f3e2bc55ebeb1901
7
- data.tar.gz: 2a9fe5d50851c24b96b3bc2f0d466cf2d33eefbed6ba260dc515c15ad3851dc857aebb6723dbcdd48e74d79c6a4dcd75ea1745a09f27bd5c51e5dccf882c5e26
6
+ metadata.gz: cb4d5eef83acc10360ce1b93c03626f1728ec27a0220f96112fcef79ae676af874cec54f1732aa4f981ceb5401a714f3d151de4c2e3272d0df587ab13040dc02
7
+ data.tar.gz: 8efea007b9e6ba02aaa801ec3dc4ab29af39a3b821631c95867c3a68a38765a60028f00a9f4d391407b5913563f5b30de0d5c7569e6ae37af0ff7d859fd1a7ff
@@ -26,7 +26,11 @@ module Yamload
26
26
  loaded_hash
27
27
  end
28
28
 
29
- attr_accessor :schema
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, @schema)
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
- YAML.load_file(filepath)
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
@@ -1,3 +1,3 @@
1
1
  module Yamload
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -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) { loader.loaded_hash }
17
- let(:config_obj) { loader.obj }
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
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