frise 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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +1 -0
- data/lib/frise/defaults_loader.rb +2 -2
- data/lib/frise/loader.rb +1 -1
- data/lib/frise/parser.rb +1 -1
- data/lib/frise/validator.rb +29 -3
- data/lib/frise/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 658ef151a4948ba72f32f7dc5b51f5ddb3e6fb69
|
4
|
+
data.tar.gz: 8b7498f11685e3c5d1a4bbce70c732d8a62e8eb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 998d82e9c1a58efb14b5edd44deb4c85c62ced21cec664f29cffa3753f3742fc9e876fad96c9c3902fa2fc6a55d57622695bfe579acb6abb246695f8f7fe8b91
|
7
|
+
data.tar.gz: f1a5e4ee436e6081a93fd204cfd7ee434aeb3d6ada5e90853f42467cf6339ca8a6c4dbc0b8d4b335d4e1d75e211e965736f84010cc3ffb31e6c37b668fafce9c
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
### 0.2.0 (unreleased)
|
2
|
+
|
3
|
+
- New features
|
4
|
+
- New schema types `$enum` and `$one_of` for specifying enumerations and values with multiple
|
5
|
+
possible schemas ([#5](https://github.com/ShiftForward/frise/pull/5)).
|
6
|
+
- Bug fixes
|
7
|
+
- Deal correctly with non-existing schema files in the load path
|
8
|
+
([#4](https://github.com/ShiftForward/frise/pull/4)).
|
9
|
+
|
10
|
+
### 0.1.0 (August 10, 2017)
|
11
|
+
|
12
|
+
Initial version.
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Frise
|
2
2
|
[![Build Status](https://travis-ci.org/ShiftForward/frise.svg?branch=master)](https://travis-ci.org/ShiftForward/frise)
|
3
3
|
[![Coverage Status](https://coveralls.io/repos/github/ShiftForward/frise/badge.svg?branch=master)](https://coveralls.io/github/ShiftForward/frise?branch=master)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/frise.svg)](https://badge.fury.io/rb/frise)
|
4
5
|
|
5
6
|
Frise is a library for loading configuration files as native Ruby structures. Besides reading and
|
6
7
|
parsing the files themselves, it also:
|
@@ -56,12 +56,12 @@ module Frise
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def merge_defaults(config, defaults_file, symbol_table = config)
|
59
|
-
defaults = Parser.parse(defaults_file, symbol_table)
|
59
|
+
defaults = Parser.parse(defaults_file, symbol_table) || {}
|
60
60
|
merge_defaults_obj(config, defaults)
|
61
61
|
end
|
62
62
|
|
63
63
|
def merge_defaults_at(config, at_path, defaults_file, symbol_table = config)
|
64
|
-
defaults = Parser.parse(defaults_file, symbol_table)
|
64
|
+
defaults = Parser.parse(defaults_file, symbol_table) || {}
|
65
65
|
merge_defaults_obj_at(config, at_path, defaults)
|
66
66
|
end
|
67
67
|
end
|
data/lib/frise/loader.rb
CHANGED
@@ -16,7 +16,7 @@ module Frise
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def load(config_file, exit_on_fail = true, symbol_table = {})
|
19
|
-
config = Parser.parse(config_file, symbol_table)
|
19
|
+
config = Parser.parse(config_file, symbol_table) || {}
|
20
20
|
config_name = File.basename(config_file)
|
21
21
|
|
22
22
|
@pre_loaders.each do |pre_loader|
|
data/lib/frise/parser.rb
CHANGED
@@ -7,7 +7,7 @@ module Frise
|
|
7
7
|
module Parser
|
8
8
|
class << self
|
9
9
|
def parse(file, symbol_table = nil)
|
10
|
-
return
|
10
|
+
return nil unless File.file? file
|
11
11
|
content = File.open(file).read
|
12
12
|
content = Liquid::Template.parse(content).render symbol_table if symbol_table
|
13
13
|
YAML.safe_load(content, [], [], true) || {}
|
data/lib/frise/validator.rb
CHANGED
@@ -32,7 +32,9 @@ module Frise
|
|
32
32
|
|
33
33
|
def get_full_schema(schema)
|
34
34
|
case schema
|
35
|
-
when Hash then
|
35
|
+
when Hash then
|
36
|
+
default_type = schema[:enum] || schema[:one_of] ? 'Object' : 'Hash'
|
37
|
+
{ type: default_type }.merge(schema)
|
36
38
|
when Symbol then { type: 'Object', validate: schema }
|
37
39
|
when Array then
|
38
40
|
if schema.size == 1
|
@@ -87,6 +89,28 @@ module Frise
|
|
87
89
|
true
|
88
90
|
end
|
89
91
|
|
92
|
+
def validate_enum(full_schema, obj, path)
|
93
|
+
if full_schema[:enum] && !full_schema[:enum].include?(obj)
|
94
|
+
add_validation_error(path, "invalid value #{obj.inspect}. " \
|
95
|
+
"Accepted values are #{full_schema[:enum].map(&:inspect).join(', ')}")
|
96
|
+
return false
|
97
|
+
end
|
98
|
+
true
|
99
|
+
end
|
100
|
+
|
101
|
+
def validate_one_of(full_schema, obj, path)
|
102
|
+
if full_schema[:one_of]
|
103
|
+
full_schema[:one_of].each do |schema_opt|
|
104
|
+
opt_validator = Validator.new(@root, @validators)
|
105
|
+
opt_validator.validate_object(path, obj, schema_opt)
|
106
|
+
return true if opt_validator.errors.empty?
|
107
|
+
end
|
108
|
+
add_validation_error(path, "#{obj.inspect} does not match any of the possible schemas")
|
109
|
+
return false
|
110
|
+
end
|
111
|
+
true
|
112
|
+
end
|
113
|
+
|
90
114
|
def validate_spec_keys(full_schema, obj, path, processed_keys)
|
91
115
|
full_schema.each do |spec_key, spec_value|
|
92
116
|
next if spec_key.is_a?(Symbol)
|
@@ -122,6 +146,8 @@ module Frise
|
|
122
146
|
return unless validate_optional(full_schema, obj, path)
|
123
147
|
return unless validate_type(full_schema, obj, path)
|
124
148
|
return unless validate_custom(full_schema, obj, path)
|
149
|
+
return unless validate_enum(full_schema, obj, path)
|
150
|
+
return unless validate_one_of(full_schema, obj, path)
|
125
151
|
|
126
152
|
processed_keys = Set.new
|
127
153
|
return unless validate_spec_keys(full_schema, obj, path, processed_keys)
|
@@ -156,12 +182,12 @@ module Frise
|
|
156
182
|
end
|
157
183
|
|
158
184
|
def self.validate(config, schema_file, options = {})
|
159
|
-
schema = parse_symbols(Parser.parse(schema_file))
|
185
|
+
schema = parse_symbols(Parser.parse(schema_file) || { allow_unknown_keys: true })
|
160
186
|
validate_obj(config, schema, options)
|
161
187
|
end
|
162
188
|
|
163
189
|
def self.validate_at(config, at_path, schema_file, options = {})
|
164
|
-
schema = parse_symbols(Parser.parse(schema_file))
|
190
|
+
schema = parse_symbols(Parser.parse(schema_file) || { allow_unknown_keys: true })
|
165
191
|
at_path.reverse.each { |key| schema = { key => schema, :allow_unknown_keys => true } }
|
166
192
|
validate_obj(config, schema, options)
|
167
193
|
end
|
data/lib/frise/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ShiftForward
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: liquid
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- ".rspec"
|
120
120
|
- ".rubocop.yml"
|
121
121
|
- ".travis.yml"
|
122
|
+
- CHANGELOG.md
|
122
123
|
- Gemfile
|
123
124
|
- LICENSE.txt
|
124
125
|
- README.md
|