class_composer 1.0.1 → 1.0.2
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/README.md +23 -2
- data/lib/class_composer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d53fe12431ff8f1dd4c42d7282d11a64637a0c3ab573e24a7d83443a8a9cac2
|
4
|
+
data.tar.gz: 0376e66b2fef6bc976289dd1f4e4517830dd0a63c0e12519730efc9786865c9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b08e706f2f55865e6d4fab779896450dab524b946412ee8e8be8a673b205a8f3ded0a438db6dbce53d8ebc06c6a88a2dc6cba5a4da3bd5e22a599a205ea9cc0f
|
7
|
+
data.tar.gz: bfa9491b16358fc59b221bd5ac847b861c52a6a5793dca4fc59c81a8ceef3e12c1d3148bd8679833e4c5a643e5738788a9647a1619f9aadc2171b9d497bd0f34
|
data/README.md
CHANGED
@@ -42,11 +42,32 @@ class MyConfigurableClass
|
|
42
42
|
ALLOWED_FIBONACCI = [0, 2, 8, 13, 34]
|
43
43
|
|
44
44
|
add_composer :status, allowed: Integer, default: 35
|
45
|
-
add_composer :number, allowed: Integer, default: 0, validator: -> (val) {
|
45
|
+
add_composer :number, allowed: Integer, default: 0, validator: -> (val) { val < 50 }
|
46
46
|
# when no default is provided, nil will be returned
|
47
|
-
add_composer :fibbonacci, allowed: Array, validator: ->(val) { val.all? {|i| i.is_a?(Integer) } &&
|
47
|
+
add_composer :fibbonacci, allowed: Array, validator: ->(val) { val.all? {|i| i.is_a?(Integer) } && val.all? { |i| ALLOWED_FIBONACCI.include?(i) } }, invalid_message: ->(val) { "We only allow #{ALLOWED_FIBONACCI} numbers. Received #{val}" }
|
48
48
|
# Allowed can be passed an array of allowed class types
|
49
49
|
add_composer :type, allowed: [Proc, Integer], default: 35
|
50
|
+
end
|
51
|
+
|
52
|
+
instance = MyConfigurableClass.new
|
53
|
+
instance.type
|
54
|
+
=> 35
|
55
|
+
instance.number = 75
|
56
|
+
ClassComposer::ValidatorError: MyConfigurableClass.number failed validation. number is expected to be Integer.
|
57
|
+
from /gem/lib/class_composer/generator.rb:71:in `block in __composer_assignment__`
|
58
|
+
instance.number = 15
|
59
|
+
=> 15
|
60
|
+
instance.number
|
61
|
+
=> 15
|
62
|
+
instance.fibbonacci
|
63
|
+
=> nil
|
64
|
+
instance.fibbonacci = [1,2,3]
|
65
|
+
ClassComposer::ValidatorError: MyConfigurableClass.fibbonacci failed validation. fibbonacci is expected to be [Array]. We only allow [0, 2, 8, 13, 34] numbers. Received [1, 2, 3]
|
66
|
+
from /gem/lib/class_composer/generator.rb:71:in `block in __composer_assignment__`
|
67
|
+
instance.fibbonacci = [0,13,34]
|
68
|
+
=> [0, 13, 34]
|
69
|
+
instance.fibbonacci
|
70
|
+
=> [0, 13, 34]
|
50
71
|
```
|
51
72
|
|
52
73
|
### KWarg Options
|