ultra_config 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/ultra_config/validator.rb +16 -5
- data/ultra_config.gemspec +1 -1
- 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: 7fe814320bd63df05e458ca40594c0924825cd32
|
4
|
+
data.tar.gz: 6df1c641ed3ec366186d49ffeaedf36642f360b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ff2629253dbdc620322059e94fe436ddff426a01d07882ad8f148f0637557c38dbd0b3275796b9b37f0be786b6b4a342968004f799422fe413d7b69085b4d39
|
7
|
+
data.tar.gz: bb46e4c2058e26aa23288937b712b3999b8a33528baacf690c3015c37fbaa2af137ed4573008755ee795e87d43100fb5eba1ab841bb6f883bb447d616a2bd65b
|
data/README.md
CHANGED
@@ -56,7 +56,7 @@ end
|
|
56
56
|
|
57
57
|
# It can then be used like:
|
58
58
|
|
59
|
-
ConfigTest.
|
59
|
+
ConfigTest.space2.space3.default
|
60
60
|
|
61
61
|
```
|
62
62
|
|
@@ -68,7 +68,7 @@ After checking out the repo, run `bundle install` to install dependencies. Then,
|
|
68
68
|
|
69
69
|
## Contributing
|
70
70
|
|
71
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/SpyMachine/ultra_config.
|
72
72
|
|
73
73
|
## License
|
74
74
|
|
@@ -8,19 +8,26 @@ module UltraConfig
|
|
8
8
|
class TypeValidationError < ValidationError; end
|
9
9
|
|
10
10
|
def self.validate(old, new, &validation)
|
11
|
+
@old_value = old
|
11
12
|
@test_value = new
|
12
|
-
type_safety(old) if Settings.type_safety == :strong
|
13
13
|
|
14
14
|
self.instance_eval(&validation) if validation
|
15
|
+
|
16
|
+
type_safety(Settings.type_safety) unless @explicit_type_safety
|
15
17
|
ensure
|
16
18
|
@test_value = nil
|
19
|
+
@old_value = nil
|
20
|
+
@explicit_type_safety = false
|
17
21
|
end
|
18
22
|
|
19
|
-
def self.type_safety(
|
20
|
-
|
21
|
-
return
|
23
|
+
def self.type_safety(type)
|
24
|
+
@explicit_type_safety = true
|
25
|
+
return unless type == :strong
|
26
|
+
|
27
|
+
return if @old_value.nil?
|
28
|
+
return if @old_value.is_a?(Boolean) && @test_value.is_a?(Boolean)
|
22
29
|
|
23
|
-
raise TypeValidationError if
|
30
|
+
raise TypeValidationError if @old_value.class != @test_value.class
|
24
31
|
end
|
25
32
|
|
26
33
|
def self.one_of(list)
|
@@ -34,5 +41,9 @@ module UltraConfig
|
|
34
41
|
def self.range(low, high)
|
35
42
|
raise ValidationError unless (@test_value >= low && @test_value <= high)
|
36
43
|
end
|
44
|
+
|
45
|
+
def self.custom(&block)
|
46
|
+
raise ValidationError unless block.call(@test_value)
|
47
|
+
end
|
37
48
|
end
|
38
49
|
end
|
data/ultra_config.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ultra_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory Kuruc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|