normalizr 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/gemfiles/activerecord-4.0.x.gemfile +7 -0
- data/gemfiles/activerecord-4.2.x.gemfile +7 -0
- data/lib/normalizr/normalizers.rb +3 -1
- data/lib/normalizr/version.rb +1 -1
- data/spec/models/author_spec.rb +22 -18
- data/spec/support/models/author.rb +8 -7
- data/spec/support/schema.rb +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f01b405bb0c605fb3d1ee13165c30708a209ac2
|
4
|
+
data.tar.gz: 585231449522b519400d785946f8d226fee9a1c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfe8b07219b1869ce39d2e9795b98c0bf34af89547274e4e6e22c112ef47df6286be7c2098032584d9c40811280ecfc4ea139bbce4bc53a2a64415f0b8a6cebd
|
7
|
+
data.tar.gz: f7ca6b8dc3cc39ae349a753190eb809f734c00334bf22c5a676addd5f0485cc2c822f5801be8180f22d5e08272da66368c7a2bf446eef2da67ea09bfb4767205
|
data/.travis.yml
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
language: ruby
|
2
|
+
cache: bundler
|
2
3
|
rvm:
|
3
|
-
- 2.0
|
4
|
-
- 2.1
|
4
|
+
- 2.0
|
5
|
+
- 2.1
|
6
|
+
- 2.2
|
5
7
|
gemfile:
|
6
8
|
- gemfiles/activerecord-3.2.x.gemfile
|
9
|
+
- gemfiles/activerecord-4.0.x.gemfile
|
7
10
|
- gemfiles/activerecord-4.1.x.gemfile
|
11
|
+
- gemfiles/activerecord-4.2.x.gemfile
|
8
12
|
addons:
|
9
13
|
code_climate:
|
10
14
|
repo_token: 1cac54041089115a5bf218169b62c76c8b87a5896f5aa973f89637a8553c0376
|
@@ -48,7 +48,9 @@ Normalizr.configure do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
[:capitalize, :downcase, :strip, :upcase].each do |name|
|
51
|
+
[:capitalize, :downcase, :parameterize, :strip, :upcase].each do |name|
|
52
|
+
next unless String.method_defined?(name)
|
53
|
+
|
52
54
|
add name do |value|
|
53
55
|
if String === value
|
54
56
|
value.send(:"#{name}")
|
data/lib/normalizr/version.rb
CHANGED
data/spec/models/author_spec.rb
CHANGED
@@ -3,36 +3,40 @@ require 'spec_helper'
|
|
3
3
|
describe Author do
|
4
4
|
context 'Testing the built in normalizers' do
|
5
5
|
# default normalization [ :strip, :blank ]
|
6
|
-
it { should
|
7
|
-
it { should
|
8
|
-
it { should
|
6
|
+
it { should normalize(:name) }
|
7
|
+
it { should normalize(:name).from(' this ').to('this') }
|
8
|
+
it { should normalize(:name).from(' ').to(nil) }
|
9
9
|
|
10
10
|
# :strip normalizer
|
11
|
-
it { should
|
12
|
-
it { should
|
11
|
+
it { should normalize(:first_name).from(' this ').to('this') }
|
12
|
+
it { should normalize(:first_name).from(' ').to('') }
|
13
13
|
|
14
14
|
# :squish normalizer
|
15
|
-
it { should
|
15
|
+
it { should normalize(:nickname).from(' this nickname ').to('this nickname') }
|
16
16
|
|
17
17
|
# :blank normalizer
|
18
|
-
it { should
|
19
|
-
it { should
|
20
|
-
it { should
|
18
|
+
it { should normalize(:last_name).from('').to(nil) }
|
19
|
+
it { should normalize(:last_name).from(' ').to(nil) }
|
20
|
+
it { should normalize(:last_name).from(' this ').to(' this ') }
|
21
21
|
|
22
22
|
# :whitespace normalizer
|
23
|
-
it { should
|
24
|
-
it { should
|
25
|
-
it { should
|
26
|
-
it { should
|
23
|
+
it { should normalize(:biography).from(" this line\nbreak ").to("this line\nbreak") }
|
24
|
+
it { should normalize(:biography).from("\tthis\tline\nbreak ").to("this line\nbreak") }
|
25
|
+
it { should normalize(:biography).from(" \tthis \tline \nbreak \t \nthis").to("this line\nbreak\nthis") }
|
26
|
+
it { should normalize(:biography).from(' ').to('') }
|
27
27
|
|
28
28
|
# :control_chars normalizer
|
29
|
-
it { should
|
30
|
-
it { should
|
29
|
+
it { should normalize(:bibliography).from("No \bcontrol\u0003 chars").to("No control chars") }
|
30
|
+
it { should normalize(:bibliography).from("Except for\tspaces.\r\nAll kinds").to("Except for\tspaces.\r\nAll kinds") }
|
31
|
+
|
32
|
+
# :parameterize normalizer
|
33
|
+
it { should normalize(:slug).from("Obi One Kenobi").to("obi-one-kenobi") }
|
34
|
+
it { should normalize(:slug).from(" ").to("") }
|
31
35
|
end
|
32
36
|
|
33
37
|
context 'on default attribute with the default normalizer changed' do
|
34
|
-
it { should
|
35
|
-
it { should
|
36
|
-
it { should
|
38
|
+
it { should normalize(:phone_number).from('no-numbers-here').to(nil) }
|
39
|
+
it { should normalize(:phone_number).from('1.877.987.9875').to('18779879875') }
|
40
|
+
it { should normalize(:phone_number).from('+ 1 (877) 987-9875').to('18779879875') }
|
37
41
|
end
|
38
42
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class Author < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
normalize :name
|
3
|
+
normalize :nickname, with: :squish
|
4
|
+
normalize :first_name, with: :strip
|
5
|
+
normalize :last_name, with: :blank
|
6
|
+
normalize :phone_number, with: :phone
|
7
|
+
normalize :biography, with: :whitespace
|
8
|
+
normalize :bibliography, with: :control_chars
|
9
|
+
normalize :slug, with: :parameterize
|
9
10
|
end
|
data/spec/support/schema.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: normalizr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -152,7 +152,9 @@ files:
|
|
152
152
|
- README.md
|
153
153
|
- Rakefile
|
154
154
|
- gemfiles/activerecord-3.2.x.gemfile
|
155
|
+
- gemfiles/activerecord-4.0.x.gemfile
|
155
156
|
- gemfiles/activerecord-4.1.x.gemfile
|
157
|
+
- gemfiles/activerecord-4.2.x.gemfile
|
156
158
|
- lib/normalizr.rb
|
157
159
|
- lib/normalizr/concern.rb
|
158
160
|
- lib/normalizr/configuration.rb
|
@@ -211,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
213
|
version: '0'
|
212
214
|
requirements: []
|
213
215
|
rubyforge_project:
|
214
|
-
rubygems_version: 2.
|
216
|
+
rubygems_version: 2.4.8
|
215
217
|
signing_key:
|
216
218
|
specification_version: 4
|
217
219
|
summary: Writer methods parameters normalization
|