auto_strip_attributes 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,7 +14,7 @@ Gem has option to set empty strings to nil or to remove extra spaces inside the
14
14
  Include gem in your Gemfile:
15
15
 
16
16
  ```ruby
17
- gem "auto_strip_attributes", "~> 1.0"
17
+ gem "auto_strip_attributes", "~> 2.0"
18
18
  ```
19
19
 
20
20
  ```ruby
@@ -39,10 +39,11 @@ By default the following filters are defined (listed in the order of processing)
39
39
  - :strip (enabled by default) - removes whitespaces from the beginning and the end of string
40
40
  - :nullify (enabled by default) - replaces empty strings with nil
41
41
  - :squish (disabled by default) - replaces extra whitespaces (including tabs) with one space
42
+ - :delete_whitespaces (disabled by default) - delete all whitespaces (including tabs)
42
43
 
43
44
  ### Custom Filters
44
45
 
45
- New version of this gem supports custom filtering methods. Custom methods can be set by calling to set_filter method
46
+ Gem supports custom filtering methods. Custom methods can be set by calling to set_filter method
46
47
  inside a block passed to AutoStripAttributes::Config.setup. set_filter method accepts either Symbol or Hash as a
47
48
  parameter. If parameter is a Hash, the key should be filter name and the value is boolean whether filter is enabled by
48
49
  default or not. Block should return processed value.
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = "https://github.com/holli/auto_strip_attributes"
11
11
  s.summary = "Removes unnecessary whitespaces in attributes. Extension to ActiveRecord or ActiveModel."
12
12
  s.description = "AutoStripAttributes helps to remove unnecessary whitespaces from ActiveRecord or ActiveModel attributes. It's good for removing accidental spaces from user inputs. It works by adding a before_validation hook to the record. It has option to set empty strings to nil or to remove extra spaces inside the string."
13
+ s.license = "MIT"
13
14
 
14
15
  s.rubyforge_project = "auto_strip_attributes"
15
16
 
@@ -54,6 +54,9 @@ class AutoStripAttributes::Config
54
54
  set_filter :squish => false do |value|
55
55
  value.respond_to?(:gsub) ? value.gsub(/\s+/, ' ') : value
56
56
  end
57
+ set_filter :delete_whitespaces => false do |value|
58
+ value.respond_to?(:delete) ? value.delete(" \t") : value
59
+ end
57
60
  end
58
61
 
59
62
  instance_eval &block if block_given?
@@ -1,3 +1,3 @@
1
1
  module AutoStripAttributes
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
@@ -133,6 +133,21 @@ describe AutoStripAttributes do
133
133
  end
134
134
  end
135
135
 
136
+ describe "Attribute with delete_whitespaces option" do
137
+ class MockRecordWithDelete < MockRecordParent
138
+ #column :foo, :string
139
+ attr_accessor :foo
140
+ auto_strip_attributes :foo, :delete_whitespaces => true
141
+ end
142
+
143
+ it "should delete all spaces and tabs" do
144
+ @record = MockRecordWithDelete.new
145
+ @record.foo = " a \t bbb"
146
+ @record.valid?
147
+ @record.foo.must_equal "abbb"
148
+ end
149
+ end
150
+
136
151
  describe "Multible attributes with multiple options" do
137
152
  class MockRecordWithMultipleAttributes < MockRecordParent #< ActiveRecord::Base
138
153
  #column :foo, :string
@@ -184,7 +199,7 @@ describe AutoStripAttributes do
184
199
  it "should have default filters set in right order" do
185
200
  AutoStripAttributes::Config.setup :clear => true
186
201
  filters_order = AutoStripAttributes::Config.filters_order
187
- filters_order.must_equal [:strip, :nullify, :squish]
202
+ filters_order.must_equal [:strip, :nullify, :squish, :delete_whitespaces]
188
203
  end
189
204
 
190
205
  it "should reset filters to defaults when :clear is true" do
@@ -195,7 +210,7 @@ describe AutoStripAttributes do
195
210
  end
196
211
  AutoStripAttributes::Config.setup :clear => true
197
212
  filters_order = AutoStripAttributes::Config.filters_order
198
- filters_order.must_equal [:strip, :nullify, :squish]
213
+ filters_order.must_equal [:strip, :nullify, :squish, :delete_whitespaces]
199
214
  end
200
215
 
201
216
  it "should remove all filters when :clear is true and :defaults is false" do
@@ -228,7 +243,7 @@ describe AutoStripAttributes do
228
243
  filters_order = AutoStripAttributes::Config.filters_order
229
244
  filters_enabled = AutoStripAttributes::Config.filters_enabled
230
245
 
231
- filters_order.must_equal [:strip, :nullify, :squish, :test]
246
+ filters_order.must_equal [:strip, :nullify, :squish, :delete_whitespaces, :test]
232
247
  assert Proc === filters_block[:test]
233
248
  filters_enabled[:test].must_equal true
234
249
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_strip_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-24 00:00:00.000000000Z
12
+ date: 2013-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &9037140 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9037140
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activerecord
27
- requirement: &9036640 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '3.0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *9036640
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: minitest
38
- requirement: &9085720 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 2.8.1
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *9085720
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.8.1
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: mocha
49
- requirement: &9085260 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 0.9.12
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *9085260
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.9.12
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: rake
60
- requirement: &9084880 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,7 +85,12 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *9084880
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  description: AutoStripAttributes helps to remove unnecessary whitespaces from ActiveRecord
70
95
  or ActiveModel attributes. It's good for removing accidental spaces from user inputs.
71
96
  It works by adding a before_validation hook to the record. It has option to set
@@ -88,7 +113,8 @@ files:
88
113
  - lib/auto_strip_attributes/version.rb
89
114
  - test/auto_strip_attributes_test.rb
90
115
  homepage: https://github.com/holli/auto_strip_attributes
91
- licenses: []
116
+ licenses:
117
+ - MIT
92
118
  post_install_message:
93
119
  rdoc_options: []
94
120
  require_paths:
@@ -107,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
133
  version: '0'
108
134
  requirements: []
109
135
  rubyforge_project: auto_strip_attributes
110
- rubygems_version: 1.8.6
136
+ rubygems_version: 1.8.25
111
137
  signing_key:
112
138
  specification_version: 3
113
139
  summary: Removes unnecessary whitespaces in attributes. Extension to ActiveRecord