trim_spaces_for 0.1.2 → 0.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.
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# TrimSpacesFor
|
2
2
|
|
3
3
|
TrimSpacesFor gem removes leading and trailing white spaces from the AR attribute values.
|
4
|
+
That corresponds to the full-width space.
|
4
5
|
|
5
6
|
## Installing
|
6
7
|
gem install trim_spaces_for
|
@@ -16,5 +17,15 @@ TrimSpacesFor gem removes leading and trailing white spaces from the AR attribut
|
|
16
17
|
> obj.save #=> true
|
17
18
|
> obj.title #=> "Article Title"
|
18
19
|
|
20
|
+
class User < ActiveRecord::Base
|
21
|
+
trim_spaces_for :age
|
22
|
+
validates :age, :numericality => {:only_integer => true}
|
23
|
+
end
|
24
|
+
|
25
|
+
> obj = User.new
|
26
|
+
> obj.age = " 23" # full-width space
|
27
|
+
> obj.save #=> true
|
28
|
+
> obj.age = "23"
|
29
|
+
|
19
30
|
|
20
31
|
This project rocks and uses MIT-LICENSE.
|
@@ -8,7 +8,10 @@ module TrimSpacesFor
|
|
8
8
|
def trim_spaces_for(*target_attributes)
|
9
9
|
before_validation do |model|
|
10
10
|
target_attributes.each do |attribute|
|
11
|
-
|
11
|
+
before_cast = model.__send__("#{attribute}_before_type_cast")
|
12
|
+
if before_cast.respond_to?(:trim_white_spaces)
|
13
|
+
model[attribute] = before_cast.trim_white_spaces
|
14
|
+
end
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
require 'trim_spaces_for/string_extension'
|
4
|
-
require 'trim_spaces_for/active_record_extension'
|
5
4
|
|
6
5
|
module TrimSpacesFor
|
7
6
|
class Hooks
|
@@ -9,6 +8,7 @@ module TrimSpacesFor
|
|
9
8
|
::String.send :include, TrimSpacesFor::StringExtension
|
10
9
|
|
11
10
|
ActiveSupport.on_load(:active_record) do
|
11
|
+
require 'trim_spaces_for/active_record_extension'
|
12
12
|
::ActiveRecord::Base.send :include, TrimSpacesFor::ActiveRecordExtension
|
13
13
|
end
|
14
14
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: trim_spaces_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Takumi Miura
|
@@ -158,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
158
|
requirements:
|
159
159
|
- - ">="
|
160
160
|
- !ruby/object:Gem::Version
|
161
|
-
hash: -
|
161
|
+
hash: -141074561226819087
|
162
162
|
segments:
|
163
163
|
- 0
|
164
164
|
version: "0"
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
requirements:
|
168
168
|
- - ">="
|
169
169
|
- !ruby/object:Gem::Version
|
170
|
-
hash: -
|
170
|
+
hash: -141074561226819087
|
171
171
|
segments:
|
172
172
|
- 0
|
173
173
|
version: "0"
|