normalizr 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +5 -5
- data/lib/normalizr/concern.rb +2 -2
- data/lib/normalizr/version.rb +1 -1
- data/lib/normalizr.rb +1 -1
- data/spec/lib/normalizr_spec.rb +2 -26
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a1ea6ea124dcfb9150f5baa5014afd7c48d22a6
|
4
|
+
data.tar.gz: 8edcc27a488527db1fcee49f784011c4432f47f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea84b47043932b32f5fb5f23ec1c8cda39c20765e355ead63adda7d7eb462322c11c5a0b5bc12a22a72db0ce615c4d230949d3d47898fc084e794c2d8358506e
|
7
|
+
data.tar.gz: 97ae21ee80ba0b1bc824ca36e5005225736feab1341bb0648a1821052ccf9d605c1292c8d8a114ea5446b3467e9a620502eee31478a3096a0cc8c037628cabc0
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -50,7 +50,7 @@ Normalizr.configure do
|
|
50
50
|
end
|
51
51
|
```
|
52
52
|
|
53
|
-
|
53
|
+
Register custom normalizer:
|
54
54
|
|
55
55
|
```ruby
|
56
56
|
Normalizr.configure do
|
@@ -93,12 +93,12 @@ class Currency
|
|
93
93
|
end
|
94
94
|
```
|
95
95
|
|
96
|
-
Normalize
|
96
|
+
Normalize values outside of class:
|
97
97
|
|
98
98
|
```ruby
|
99
|
-
Normalizr.
|
100
|
-
Normalizr.
|
101
|
-
Normalizr.
|
99
|
+
Normalizr.normalize(value)
|
100
|
+
Normalizr.normalize(value, :strip, :blank)
|
101
|
+
Normalizr.normalize(value, :strip, truncate: { length: 20 })
|
102
102
|
```
|
103
103
|
|
104
104
|
### Built-in normalizers
|
data/lib/normalizr/concern.rb
CHANGED
@@ -19,8 +19,8 @@ module Normalizr
|
|
19
19
|
prepend Module.new {
|
20
20
|
options.attributes.each do |method|
|
21
21
|
define_method :"#{method}=" do |value|
|
22
|
-
value = Normalizr.
|
23
|
-
value = Normalizr.
|
22
|
+
value = Normalizr.normalize(value, *options.pre)
|
23
|
+
value = Normalizr.normalize(value, *options.post) if options.post.any?
|
24
24
|
super(value)
|
25
25
|
end
|
26
26
|
end
|
data/lib/normalizr/version.rb
CHANGED
data/lib/normalizr.rb
CHANGED
data/spec/lib/normalizr_spec.rb
CHANGED
@@ -31,33 +31,9 @@ describe Normalizr do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe '#
|
34
|
+
describe '#normalize' do
|
35
35
|
before { configuration.default_normalizers = [:strip, :blank] }
|
36
|
-
subject { described_class.
|
37
|
-
|
38
|
-
context 'normalizers is empty' do
|
39
|
-
let(:normalizers) { [] }
|
40
|
-
let(:value) { ' text ' }
|
41
|
-
it { should == 'text' }
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'normalizers is not empty' do
|
45
|
-
let(:normalizers) { [truncate: { length: 8, omission: '...' }] }
|
46
|
-
let(:value) { 'Lorem ipsum dolor sit amet' }
|
47
|
-
it { should == 'Lorem...' }
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'proc' do
|
51
|
-
let(:normalizers) { [proc { |v| v.first(5) }] }
|
52
|
-
let(:value) { 'Lorem ipsum dolor sit amet' }
|
53
|
-
it { should == 'Lorem' }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
describe '#do' do
|
59
|
-
before { configuration.default_normalizers = [:strip, :blank] }
|
60
|
-
subject { described_class.do(value, *normalizers) }
|
36
|
+
subject { described_class.normalize(value, *normalizers) }
|
61
37
|
|
62
38
|
context 'normalizers is empty' do
|
63
39
|
let(:normalizers) { [] }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: normalizr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimko
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- ".gitignore"
|
133
133
|
- ".rspec"
|
134
134
|
- ".travis.yml"
|
135
|
+
- CHANGELOG.md
|
135
136
|
- Gemfile
|
136
137
|
- LICENSE.txt
|
137
138
|
- README.md
|