normalizr 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +5 -1
- data/Gemfile +2 -4
- data/README.md +52 -13
- data/gemfiles/activerecord-3.2.x.gemfile +6 -0
- data/gemfiles/activerecord-4.1.x.gemfile +6 -0
- data/lib/normalizr.rb +2 -3
- data/lib/normalizr/integrations/active_record.rb +1 -0
- data/lib/normalizr/integrations/rspec.rb +5 -0
- data/lib/normalizr/rspec/matcher.rb +10 -4
- data/lib/normalizr/version.rb +1 -1
- data/spec/models/phone_spec.rb +5 -0
- data/spec/spec_helper.rb +1 -4
- data/spec/support/models/phone.rb +10 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40309262aecfd58ad3c5e78f110c0e364e05aca1
|
4
|
+
data.tar.gz: 41c13121f6be1657aec6f7c42261028464701a6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9176eed415951ae139c7292fcecd1d9984c7fa5480c465172e192a72914add830d1de488201b0c7dedabae82098e2093e39a14f0bf7f91971513ca48c5ebd283
|
7
|
+
data.tar.gz: f866ecbde412f110fb642e0ba90616885825fb1b7c2915af282ba02b53afb3167674a48377b20588156a6752837903cc6e7e0b121e27f5b779ce02b51cdc1fb0
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
### 0.0.4 / 2014-08-30
|
2
|
+
|
3
|
+
* Automatically include RSpec matcher
|
4
|
+
|
1
5
|
### 0.0.3 / 2014-08-22
|
2
6
|
|
3
|
-
*
|
7
|
+
* Fix issue when some built-in normalizers modify passed-in parameters
|
4
8
|
|
5
9
|
### 0.0.2 / 2014-08-22
|
6
10
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -6,23 +6,22 @@ The [attribute_normalizer](https://github.com/mdeering/attribute_normalizer) rep
|
|
6
6
|
|
7
7
|
### Synopsis
|
8
8
|
|
9
|
-
Attribute normalizer doesn't normalize overloaded
|
9
|
+
Attribute normalizer doesn't normalize overloaded methods correctly. Example:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
class
|
13
|
-
include
|
12
|
+
class Phone
|
13
|
+
include AttributeNormalizer
|
14
14
|
|
15
|
-
attr_accessor :
|
16
|
-
normalize_attribute :
|
15
|
+
attr_accessor :number
|
16
|
+
normalize_attribute :number
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
super
|
18
|
+
def number=(value)
|
19
|
+
@number = value
|
21
20
|
end
|
22
21
|
end
|
23
22
|
```
|
24
23
|
|
25
|
-
`
|
24
|
+
`number` will never be normalized as expected. Normalizr resolves this problem and doesn't pollute target object namespace.
|
26
25
|
|
27
26
|
Magic based on ruby's `prepend` feature, so it requires 2.0 or higher version.
|
28
27
|
|
@@ -70,8 +69,11 @@ Normalizr.configure do
|
|
70
69
|
end
|
71
70
|
|
72
71
|
add :indent do |value, amount = 2|
|
73
|
-
|
74
|
-
|
72
|
+
if String === value
|
73
|
+
value.indent(amount)
|
74
|
+
end
|
75
|
+
value
|
76
|
+
end
|
75
77
|
end
|
76
78
|
end
|
77
79
|
```
|
@@ -87,10 +89,37 @@ class User < ActiveRecord::Base
|
|
87
89
|
normalize_attribute :skype
|
88
90
|
end
|
89
91
|
|
90
|
-
|
92
|
+
user = User.new(first_name: '', last_name: '')
|
93
|
+
user.email = "ADDRESS@example.com"
|
94
|
+
|
95
|
+
user.first_name
|
96
|
+
#=> nil
|
97
|
+
user.last_name
|
98
|
+
#=> nil
|
99
|
+
user.email
|
100
|
+
#=> "address@example.com"
|
101
|
+
```
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
class SMS
|
91
105
|
include Normalizr::Concern
|
92
|
-
|
106
|
+
|
107
|
+
attr_accessor :phone, :message
|
108
|
+
|
109
|
+
normalize :phone, with: :phone
|
110
|
+
normalize :message
|
111
|
+
|
112
|
+
def initialize(phone, message)
|
113
|
+
self.phone = phone
|
114
|
+
self.message = message
|
115
|
+
end
|
93
116
|
end
|
117
|
+
|
118
|
+
sms = SMS.new("+1 (810) 555-0000", "It works \n")
|
119
|
+
sms.phone
|
120
|
+
#=> "18105550000"
|
121
|
+
sms.message
|
122
|
+
#=> "It works"
|
94
123
|
```
|
95
124
|
|
96
125
|
Normalize values outside of class:
|
@@ -101,6 +130,16 @@ Normalizr.normalize(value, :strip, :blank)
|
|
101
130
|
Normalizr.normalize(value, :strip, truncate: { length: 20 })
|
102
131
|
```
|
103
132
|
|
133
|
+
### RSpec matcher
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
describe User do
|
137
|
+
it { should normalize(:name) }
|
138
|
+
it { should normalize(:phone).from('+1 (810) 555-0000').to('18105550000') }
|
139
|
+
it { should normalize(:email).from('ADDRESS@example.com').to('address@example.com') }
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
104
143
|
### Built-in normalizers
|
105
144
|
|
106
145
|
- blank
|
data/lib/normalizr.rb
CHANGED
@@ -38,6 +38,5 @@ module Normalizr
|
|
38
38
|
end
|
39
39
|
|
40
40
|
require 'normalizr/normalizers'
|
41
|
-
|
42
|
-
|
43
|
-
end
|
41
|
+
require 'normalizr/integrations/active_record' if defined?(ActiveRecord)
|
42
|
+
require 'normalizr/integrations/rspec' if defined?(RSpec)
|
@@ -0,0 +1 @@
|
|
1
|
+
ActiveRecord::Base.send(:include, Normalizr::Concern)
|
@@ -5,7 +5,7 @@ module Normalizr
|
|
5
5
|
Normalization.new(attribute)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
alias normalize_attribute normalize
|
9
9
|
|
10
10
|
class Normalization
|
11
11
|
def initialize(attribute)
|
@@ -14,15 +14,15 @@ module Normalizr
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def description
|
17
|
-
"normalize #{@attribute} from #{@from
|
17
|
+
"normalize #{@attribute} from #{display(@from)} to #{display(@to)}"
|
18
18
|
end
|
19
19
|
|
20
20
|
def failure_message
|
21
|
-
"#{@attribute} did not normalize as expected!
|
21
|
+
"#{@attribute} did not normalize as expected! #{display(@subject.send(@attribute))} != #{display(@to)}"
|
22
22
|
end
|
23
23
|
|
24
24
|
def failure_message_when_negated
|
25
|
-
"expected #{@attribute} to not be normalized from #{@from
|
25
|
+
"expected #{@attribute} to not be normalized from #{display(@from)} to #{display(@to)}"
|
26
26
|
end
|
27
27
|
|
28
28
|
alias negative_failure_message failure_message_when_negated
|
@@ -42,6 +42,12 @@ module Normalizr
|
|
42
42
|
@subject.send("#{@attribute}=", @from)
|
43
43
|
@subject.send(@attribute) == @to
|
44
44
|
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def display(value)
|
49
|
+
value.nil? ? 'nil' : "\"#{value}\""
|
50
|
+
end
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
data/lib/normalizr/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -17,12 +17,9 @@ require 'support/models/journal'
|
|
17
17
|
require 'support/models/magazine'
|
18
18
|
require 'support/models/person'
|
19
19
|
require 'support/models/publisher'
|
20
|
+
require 'support/models/phone'
|
20
21
|
require 'support/models/user'
|
21
22
|
|
22
|
-
RSpec.configure do |config|
|
23
|
-
config.include Normalizr::RSpec::Matcher
|
24
|
-
end
|
25
|
-
|
26
23
|
Normalizr.configure do |config|
|
27
24
|
default :strip, :special_normalizer, :blank
|
28
25
|
|
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.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -137,10 +137,14 @@ files:
|
|
137
137
|
- LICENSE.txt
|
138
138
|
- README.md
|
139
139
|
- Rakefile
|
140
|
+
- gemfiles/activerecord-3.2.x.gemfile
|
141
|
+
- gemfiles/activerecord-4.1.x.gemfile
|
140
142
|
- lib/normalizr.rb
|
141
143
|
- lib/normalizr/concern.rb
|
142
144
|
- lib/normalizr/configuration.rb
|
143
145
|
- lib/normalizr/exceptions.rb
|
146
|
+
- lib/normalizr/integrations/active_record.rb
|
147
|
+
- lib/normalizr/integrations/rspec.rb
|
144
148
|
- lib/normalizr/normalizers.rb
|
145
149
|
- lib/normalizr/options_parser.rb
|
146
150
|
- lib/normalizr/rspec/matcher.rb
|
@@ -154,6 +158,7 @@ files:
|
|
154
158
|
- spec/models/book_spec.rb
|
155
159
|
- spec/models/journal_spec.rb
|
156
160
|
- spec/models/magazine_spec.rb
|
161
|
+
- spec/models/phone_spec.rb
|
157
162
|
- spec/models/publisher_spec.rb
|
158
163
|
- spec/models/user_spec.rb
|
159
164
|
- spec/spec_helper.rb
|
@@ -165,6 +170,7 @@ files:
|
|
165
170
|
- spec/support/models/journal.rb
|
166
171
|
- spec/support/models/magazine.rb
|
167
172
|
- spec/support/models/person.rb
|
173
|
+
- spec/support/models/phone.rb
|
168
174
|
- spec/support/models/publisher.rb
|
169
175
|
- spec/support/models/user.rb
|
170
176
|
- spec/support/schema.rb
|
@@ -201,6 +207,7 @@ test_files:
|
|
201
207
|
- spec/models/book_spec.rb
|
202
208
|
- spec/models/journal_spec.rb
|
203
209
|
- spec/models/magazine_spec.rb
|
210
|
+
- spec/models/phone_spec.rb
|
204
211
|
- spec/models/publisher_spec.rb
|
205
212
|
- spec/models/user_spec.rb
|
206
213
|
- spec/spec_helper.rb
|
@@ -212,6 +219,7 @@ test_files:
|
|
212
219
|
- spec/support/models/journal.rb
|
213
220
|
- spec/support/models/magazine.rb
|
214
221
|
- spec/support/models/person.rb
|
222
|
+
- spec/support/models/phone.rb
|
215
223
|
- spec/support/models/publisher.rb
|
216
224
|
- spec/support/models/user.rb
|
217
225
|
- spec/support/schema.rb
|