eapi 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/eapi/methods/properties.rb +4 -0
- data/lib/eapi/version.rb +1 -1
- data/spec/ignore_default_spec.rb +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed4d9b9872835a5ee521394efc52e6c68161032a
|
4
|
+
data.tar.gz: ba5624ff813cb94a6cf979a33f556f5c323c3071
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7b5f6a3856d15a5969f8497b910eb55b2f8927773f7111ce5bd0d5357313e5998339e9574273547944f0176092771290f8cc2d331fd7607a080b34c6b5f2efc
|
7
|
+
data.tar.gz: 731378d506958e49440a4b3b250bf8abbb2767e0ec5affd8258ad46db600e38fc945b7dc082af9b0e3c6487d981b8e3af051290642cdd15f92451c494c2e0e1d
|
data/README.md
CHANGED
@@ -14,8 +14,14 @@ Main features:
|
|
14
14
|
* list support
|
15
15
|
* validation
|
16
16
|
* rendering to `Hash` or `Array`
|
17
|
+
* custom conversion of values
|
17
18
|
* raw `Hash` or `Array` support to skip type check validations
|
18
19
|
* omit `nil` values automatically
|
20
|
+
* custom preparation of values before validation
|
21
|
+
|
22
|
+
## WIP Warning
|
23
|
+
|
24
|
+
Until the release of the first stable version `1.0`, new versions can contain breaking changes.
|
19
25
|
|
20
26
|
## Usage
|
21
27
|
|
@@ -436,7 +442,7 @@ x.one # => :fluent
|
|
436
442
|
res.equal? x # => true
|
437
443
|
```
|
438
444
|
|
439
|
-
#### `converted_or_default_value_for` method
|
445
|
+
#### `converted_or_default_value_for` method (aka `final_value_for`)
|
440
446
|
|
441
447
|
It will return the converted value for the property. If that value is to be ignored (following the rules described with the `ignore` option) then it will return the default one (defined by the `default` option), or `nil` if there is no default value.
|
442
448
|
|
@@ -450,9 +456,11 @@ end
|
|
450
456
|
x = TestKlassWithDefault.new
|
451
457
|
x.something ''
|
452
458
|
x.converted_or_default_value_for(:something) # => 123
|
459
|
+
x.final_value_for(:something) # => 123
|
453
460
|
|
454
461
|
x.something 'not blank'
|
455
462
|
x.converted_or_default_value_for(:something) # => 'not blank'
|
463
|
+
x.final_value_for(:something) # => 'not blank'
|
456
464
|
|
457
465
|
|
458
466
|
class TestKlassWithoutDefault
|
@@ -464,9 +472,11 @@ end
|
|
464
472
|
x = TestKlassWithoutDefault.new
|
465
473
|
x.something ''
|
466
474
|
x.converted_or_default_value_for(:something) # => nil
|
475
|
+
x.final_value_for(:something) # => nil
|
467
476
|
|
468
477
|
x.something 'not blank'
|
469
478
|
x.converted_or_default_value_for(:something) # => 'not blank'
|
479
|
+
x.final_value_for(:something) # => 'not blank'
|
470
480
|
```
|
471
481
|
|
472
482
|
#### `yield_final_value_for` method
|
@@ -41,6 +41,10 @@ module Eapi
|
|
41
41
|
yield_final_value_for(property) { |val| return val }
|
42
42
|
end
|
43
43
|
|
44
|
+
def final_value_for(property)
|
45
|
+
converted_or_default_value_for(property)
|
46
|
+
end
|
47
|
+
|
44
48
|
# will yield the converted value if it is not to be ignored,
|
45
49
|
# will yield the default value if it is set and the converted value is to be ignored
|
46
50
|
# will not yield anything otherwise
|
data/lib/eapi/version.rb
CHANGED
data/spec/ignore_default_spec.rb
CHANGED
@@ -29,15 +29,17 @@ RSpec.describe Eapi do
|
|
29
29
|
expect(subject.render).to eq expected
|
30
30
|
end
|
31
31
|
|
32
|
-
describe '#converted_or_default_value_for' do
|
32
|
+
describe '#converted_or_default_value_for and #final_value_for (same)' do
|
33
33
|
it 'returns the converted value if it is not ignored' do
|
34
34
|
subject.something 1
|
35
35
|
expect(subject.converted_or_default_value_for :something).to eq 1
|
36
|
+
expect(subject.final_value_for :something).to eq 1
|
36
37
|
end
|
37
38
|
|
38
39
|
it 'returns the default value if it is ignored' do
|
39
40
|
subject.something ""
|
40
41
|
expect(subject.converted_or_default_value_for :something).to eq 123
|
42
|
+
expect(subject.final_value_for :something).to eq 123
|
41
43
|
end
|
42
44
|
|
43
45
|
describe 'without default value' do
|
@@ -46,6 +48,7 @@ RSpec.describe Eapi do
|
|
46
48
|
it 'returns nil if the converted value is ignored' do
|
47
49
|
subject.something ""
|
48
50
|
expect(subject.converted_or_default_value_for :something).to be_nil
|
51
|
+
expect(subject.final_value_for :something).to be_nil
|
49
52
|
end
|
50
53
|
end
|
51
54
|
end
|