attribute_normalizer 1.2.0.b → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +9 -9
- data/README.textile +5 -5
- data/lib/attribute_normalizer.rb +3 -1
- data/lib/attribute_normalizer/normalizers/boolean_normalizer.rb +18 -0
- data/lib/attribute_normalizer/normalizers/whitespace_normalizer.rb +1 -1
- data/lib/attribute_normalizer/rspec_matcher.rb +2 -1
- data/lib/attribute_normalizer/version.rb +1 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGNlMjVjZmYwYTMwMTA4YTQ5MWNkYzU4NTgwNTRjYzE0MTA1ZGY1ZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
NzVkMGU3YWVjYjQwOTJjOGFjZDk5Zjg5NDAwNmE5NTcyMTU5M2FjOA==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTk5YjhiMTA3YWJlZTg3NmQwNDY5ZjA1NTUzYjU5MWY1ODAyNGNkNjQ3ZjVi
|
10
|
+
N2QzYzVjZmI1NDU2NzljMWEyOTJhZDk0ZmM2MGRhMjA4OTcwMTQwODk3MTFk
|
11
|
+
YmExMjg3ZGZkNjIyZTljZGExYTAwMWRjM2E4MmJkZmM0MDE3ODU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2VhNzFiZjYxMTg4MTk2Y2VkNTU2OGNiNTU0YjA1MmYyMTA4MTc0MzRjYTkw
|
14
|
+
NzM5N2ZiNmQ3ZWEwMWJhZGExM2U4MDM1NWUzZmQ2ZmEwOGYxODQ2MWM1MDcz
|
15
|
+
OWQyNzQ2YjY2ZDZhZmRkNTQ2Y2YzYjJlZjJjZDAyOTQyYmM0Yjc=
|
data/README.textile
CHANGED
@@ -27,7 +27,7 @@ h2. Change History
|
|
27
27
|
** Added out of the box support for CassandraObjects
|
28
28
|
** Included RSpec matcher _normalizer_attribute_
|
29
29
|
** Added the ability to define global normalizers
|
30
|
-
** *Strings
|
30
|
+
** *Strings no longer get 'strip' called on them before getting passed on to your defined normalization blocks*
|
31
31
|
|
32
32
|
h2. Supported ORMs
|
33
33
|
|
@@ -109,7 +109,7 @@ AttributeNormalizer.configure do |config|
|
|
109
109
|
# the default normalizers for each attribute (e.g. config.default_normalizers)
|
110
110
|
# config.default_attributes = :name, :title
|
111
111
|
|
112
|
-
# Also, You can add
|
112
|
+
# Also, You can add a specific attribute to default_attributes using one or more normalizers:
|
113
113
|
# config.add_default_attribute :name, :with => :truncate
|
114
114
|
end
|
115
115
|
</code></pre>
|
@@ -133,7 +133,7 @@ The _normalize_attributes_ method is eager loaded into your ORM. _normalize_att
|
|
133
133
|
value.is_a?(String) ? value.titleize.strip : value
|
134
134
|
end
|
135
135
|
|
136
|
-
# Or use a combination of normalizers plus
|
136
|
+
# Or use a combination of normalizers plus an inline block.
|
137
137
|
# the normalizers in the :with option will each be evalulated
|
138
138
|
# in order and the result will be given to the block.
|
139
139
|
# You could also use option :before in place of :with
|
@@ -141,7 +141,7 @@ The _normalize_attributes_ method is eager loaded into your ORM. _normalize_att
|
|
141
141
|
value.present? && value.is_a?(String) ? value.downcase.gsub(/\s+/, '-') : value
|
142
142
|
end
|
143
143
|
|
144
|
-
# Use
|
144
|
+
# Use builtin normalizers before and after the evaluation of your inline
|
145
145
|
# block
|
146
146
|
normalize_attribute :limited_slug, :before => [ :strip, :blank ], :after => [ { :truncate => { :length => 11, :omission => '' } } ] do |value|
|
147
147
|
value.present? && value.is_a?(String) ? value.downcase.gsub(/\s+/, '-') : value
|
@@ -164,7 +164,7 @@ book.limited_slug # => 'pick-up-chi'
|
|
164
164
|
|
165
165
|
h2. Test Helpers
|
166
166
|
|
167
|
-
p. If you are running RSpec there is matcher available for use. Usage can been seen above. Include it as follows.
|
167
|
+
p. If you are running RSpec there is a matcher available for use. Usage can been seen above. Include it as follows.
|
168
168
|
|
169
169
|
h3. Rails 2
|
170
170
|
|
data/lib/attribute_normalizer.rb
CHANGED
@@ -3,6 +3,7 @@ require 'attribute_normalizer/normalizers/phone_normalizer'
|
|
3
3
|
require 'attribute_normalizer/normalizers/strip_normalizer'
|
4
4
|
require 'attribute_normalizer/normalizers/squish_normalizer'
|
5
5
|
require 'attribute_normalizer/normalizers/whitespace_normalizer'
|
6
|
+
require 'attribute_normalizer/normalizers/boolean_normalizer'
|
6
7
|
|
7
8
|
module AttributeNormalizer
|
8
9
|
|
@@ -35,7 +36,8 @@ module AttributeNormalizer
|
|
35
36
|
:phone => AttributeNormalizer::Normalizers::PhoneNormalizer,
|
36
37
|
:squish => AttributeNormalizer::Normalizers::SquishNormalizer,
|
37
38
|
:strip => AttributeNormalizer::Normalizers::StripNormalizer,
|
38
|
-
:whitespace => AttributeNormalizer::Normalizers::WhitespaceNormalizer
|
39
|
+
:whitespace => AttributeNormalizer::Normalizers::WhitespaceNormalizer,
|
40
|
+
:boolean => AttributeNormalizer::Normalizers::BooleanNormalizer
|
39
41
|
}
|
40
42
|
|
41
43
|
@default_normalizers = [ :strip, :blank ]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Extracted from ActiveRecord::ConnectionAdapters::Column
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
module AttributeNormalizer
|
5
|
+
module Normalizers
|
6
|
+
module BooleanNormalizer
|
7
|
+
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].to_set
|
8
|
+
|
9
|
+
def self.normalize(value, options = {})
|
10
|
+
if value.is_a?(String) && value.blank?
|
11
|
+
nil
|
12
|
+
else
|
13
|
+
TRUE_VALUES.include?(value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -2,7 +2,7 @@ module AttributeNormalizer
|
|
2
2
|
module Normalizers
|
3
3
|
module WhitespaceNormalizer
|
4
4
|
def self.normalize(value, options = {})
|
5
|
-
value.is_a?(String) ? value.gsub(/[^\S\n]+/, ' ').gsub(/\s
|
5
|
+
value.is_a?(String) ? value.gsub(/[^\S\n]+/, ' ').gsub(/\s?\n\s?/, "\n").strip : value
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -21,9 +21,10 @@ module AttributeNormalizer
|
|
21
21
|
"#{@attribute} did not normalize as expected! \"#{@subject.send(@attribute)}\" != #{@to.nil? ? 'nil' : "\"#{@to}\""}"
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def failure_message_when_negated
|
25
25
|
"expected #{@attribute} to not be normalized from #{@from.nil? ? 'nil' : "\"#{@from}\""} to #{@to.nil? ? 'nil' : "\"#{@to}\""}"
|
26
26
|
end
|
27
|
+
alias negative_failure_message failure_message_when_negated
|
27
28
|
|
28
29
|
def from(value)
|
29
30
|
@from = value
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attribute_normalizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Deering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ''
|
14
14
|
email:
|
@@ -17,16 +17,17 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- README.textile
|
21
|
+
- lib/attribute_normalizer.rb
|
20
22
|
- lib/attribute_normalizer/model_inclusions.rb
|
21
|
-
- lib/attribute_normalizer/rspec_matcher.rb
|
22
|
-
- lib/attribute_normalizer/normalizers/whitespace_normalizer.rb
|
23
|
-
- lib/attribute_normalizer/normalizers/strip_normalizer.rb
|
24
|
-
- lib/attribute_normalizer/normalizers/phone_normalizer.rb
|
25
23
|
- lib/attribute_normalizer/normalizers/blank_normalizer.rb
|
24
|
+
- lib/attribute_normalizer/normalizers/boolean_normalizer.rb
|
25
|
+
- lib/attribute_normalizer/normalizers/phone_normalizer.rb
|
26
26
|
- lib/attribute_normalizer/normalizers/squish_normalizer.rb
|
27
|
+
- lib/attribute_normalizer/normalizers/strip_normalizer.rb
|
28
|
+
- lib/attribute_normalizer/normalizers/whitespace_normalizer.rb
|
29
|
+
- lib/attribute_normalizer/rspec_matcher.rb
|
27
30
|
- lib/attribute_normalizer/version.rb
|
28
|
-
- lib/attribute_normalizer.rb
|
29
|
-
- README.textile
|
30
31
|
homepage: https://github.com/mdeering/attribute_normalizer
|
31
32
|
licenses: []
|
32
33
|
metadata: {}
|
@@ -41,12 +42,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
42
|
version: '0'
|
42
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
44
|
requirements:
|
44
|
-
- - ! '
|
45
|
+
- - ! '>='
|
45
46
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
47
|
+
version: '0'
|
47
48
|
requirements: []
|
48
49
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.
|
50
|
+
rubygems_version: 2.2.2
|
50
51
|
signing_key:
|
51
52
|
specification_version: 4
|
52
53
|
summary: ''
|