autostrip 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/autostrip.gemspec +2 -1
- data/lib/autostrip.rb +2 -1
- data/lib/autostrip/extension.rb +25 -7
- data/lib/autostrip/version.rb +1 -1
- metadata +21 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36bf7c05ac081a3b6a9991725b9d19f4975df4eb
|
4
|
+
data.tar.gz: 7283b1942fcf3279a507ce5d1110a745a4fb2056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52552246a76e383fe5dfe9d58c16fe03e25deb6778046b7c4022804a73b3f69dba14695bbcef424c0e2d62be7f02fc5f097fcba831b6718052865504c12e1e00
|
7
|
+
data.tar.gz: 149b989e48c22fe9f7f492cae7f0cdd362da30a0ae7619dde7f1f7e218c3fea98a01d823fb15c2bd6f4509ff02ad02805320a0f61b8b8c4f707524dba24dc5b6
|
data/README.md
CHANGED
data/autostrip.gemspec
CHANGED
@@ -18,5 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
|
19
19
|
s.require_paths = ['lib']
|
20
20
|
|
21
|
-
s.
|
21
|
+
s.add_dependency 'activesupport', '>= 3.0', '< 6.0'
|
22
|
+
s.add_dependency 'activemodel', '>= 3.0', '< 6.0'
|
22
23
|
end
|
data/lib/autostrip.rb
CHANGED
data/lib/autostrip/extension.rb
CHANGED
@@ -1,18 +1,36 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'active_support/concern'
|
5
|
+
|
4
6
|
module Autostrip
|
5
7
|
module Extension
|
6
|
-
|
7
|
-
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
def attributes_for_autostrip(attrs)
|
11
|
+
attrs.each_with_object([]) do |attr, memo|
|
12
|
+
case attr
|
13
|
+
when Regexp
|
14
|
+
self.class.columns_hash.values.each { |col| memo << col.name if col.name =~ attr }
|
15
|
+
else
|
16
|
+
memo << attr
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
def autostrip(*attributes)
|
8
23
|
# Use prepend to be sure this runs before all other "before_validation" callbacks.
|
9
|
-
before_validation prepend: true do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
24
|
+
before_validation prepend: true do
|
25
|
+
attributes_for_autostrip(attributes).each do |attribute|
|
26
|
+
value = send(attribute)
|
27
|
+
if Autostrip.performable?(value)
|
28
|
+
# http://www.davidverhasselt.com/set-attributes-in-activerecord/
|
29
|
+
send("#{attribute}=", Autostrip.perform(value))
|
30
|
+
end
|
14
31
|
end
|
15
32
|
end
|
33
|
+
nil
|
16
34
|
end
|
17
35
|
end
|
18
36
|
end
|
data/lib/autostrip/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autostrip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Konoplov
|
@@ -10,6 +10,26 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.0'
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: activemodel
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|