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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 001866efe62b5690380583e71cd63a7db0f8b50e
4
- data.tar.gz: 5569ab0e1c9379bfae5bb5c5a3f085839dffd4dc
3
+ metadata.gz: 40309262aecfd58ad3c5e78f110c0e364e05aca1
4
+ data.tar.gz: 41c13121f6be1657aec6f7c42261028464701a6d
5
5
  SHA512:
6
- metadata.gz: dd87e9aa36aa9da01e264b5097e00fdc6af7f576c116c5d640078eaa40de6e57127e838b0f8bc1e1773fb3dcd5c928c4dc238aa5c4d9627fb117a1a417311168
7
- data.tar.gz: 54a92ab8ec8a31523f8eb8bbf8b3322aefaf58b2d5b999659258dcaf35dbe36bff3bbe7cfe9f5783393f2dda079366a1ead640c6649670bec5edd4f27abd282b
6
+ metadata.gz: 9176eed415951ae139c7292fcecd1d9984c7fa5480c465172e192a72914add830d1de488201b0c7dedabae82098e2093e39a14f0bf7f91971513ca48c5ebd283
7
+ data.tar.gz: f866ecbde412f110fb642e0ba90616885825fb1b7c2915af282ba02b53afb3167674a48377b20588156a6752837903cc6e7e0b121e27f5b779ce02b51cdc1fb0
@@ -2,6 +2,9 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 2.1.0
5
+ gemfile:
6
+ - gemfiles/activerecord-3.2.x.gemfile
7
+ - gemfiles/activerecord-4.1.x.gemfile
5
8
  addons:
6
9
  code_climate:
7
10
  repo_token: 1cac54041089115a5bf218169b62c76c8b87a5896f5aa973f89637a8553c0376
@@ -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
- * Fixed issue when some built-in normalizers modify passed-in parameters
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
@@ -1,7 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gem 'codeclimate-test-reporter', require: false
4
4
 
5
- group :test do
6
- gem 'codeclimate-test-reporter', require: false
7
- end
5
+ gemspec
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 writer methods correctly. Example:
9
+ Attribute normalizer doesn't normalize overloaded methods correctly. Example:
10
10
 
11
11
  ```ruby
12
- class Currency
13
- include Normalizr::Concern
12
+ class Phone
13
+ include AttributeNormalizer
14
14
 
15
- attr_accessor :value
16
- normalize_attribute :value
15
+ attr_accessor :number
16
+ normalize_attribute :number
17
17
 
18
- def value=(*)
19
- # ...
20
- super
18
+ def number=(value)
19
+ @number = value
21
20
  end
22
21
  end
23
22
  ```
24
23
 
25
- `value` will never be normalized as expected. Normalizr resolves this problem and doesn't generate any extra instance methods.
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
- value.indent!(amount) if String === value
74
- value
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
- class Currency
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
- normalize :value
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
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 3.2.0'
4
+ gem 'codeclimate-test-reporter', require: false
5
+
6
+ gemspec path: '../'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 4.1.0'
4
+ gem 'codeclimate-test-reporter', require: false
5
+
6
+ gemspec path: '../'
@@ -38,6 +38,5 @@ module Normalizr
38
38
  end
39
39
 
40
40
  require 'normalizr/normalizers'
41
- ActiveSupport.on_load(:active_record) do
42
- ActiveRecord::Base.send(:include, Normalizr::Concern)
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)
@@ -0,0 +1,5 @@
1
+ if RSpec.respond_to?(:configure)
2
+ RSpec.configure do |config|
3
+ config.include Normalizr::RSpec::Matcher
4
+ end
5
+ end
@@ -5,7 +5,7 @@ module Normalizr
5
5
  Normalization.new(attribute)
6
6
  end
7
7
 
8
- alias_method :normalize_attribute, :normalize
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.nil? ? 'nil' : "\"#{@from}\""} to #{@to.nil? ? 'nil' : "\"#{@to}\""}"
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! \"#{@subject.send(@attribute)}\" != #{@to.nil? ? 'nil' : "\"#{@to}\""}"
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.nil? ? 'nil' : "\"#{@from}\""} to #{@to.nil? ? 'nil' : "\"#{@to}\""}"
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
@@ -1,3 +1,3 @@
1
1
  module Normalizr
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Phone do
4
+ it { should normalize(:number) }
5
+ end
@@ -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
 
@@ -0,0 +1,10 @@
1
+ class Phone
2
+ include Normalizr::Concern
3
+
4
+ attr_accessor :number
5
+ normalize_attribute :number
6
+
7
+ def number=(value)
8
+ @number = value
9
+ end
10
+ end
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.3
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-22 00:00:00.000000000 Z
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