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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 777c56877a373ae779fe58c290d5515b46cd5a73
4
- data.tar.gz: 39ec5403948976fa91c7948eb0cfd4a426d00566
3
+ metadata.gz: 36bf7c05ac081a3b6a9991725b9d19f4975df4eb
4
+ data.tar.gz: 7283b1942fcf3279a507ce5d1110a745a4fb2056
5
5
  SHA512:
6
- metadata.gz: 3ea3b8cc5fd84b671426209ad364d4ae504c1768a9afd8f45fc913daef3fcb3a1635c2641f2720f67f1298217df008cac55a0e580879734f386474bb0d018b69
7
- data.tar.gz: c339be3bfac144451cb44512e9941c1b780f80c68da40b36519b40ddae67707e5e8ed80d1fa3aabfb33d73d5a9a663efa35e66c32e1fac97c3ba81c1753a4b92
6
+ metadata.gz: 52552246a76e383fe5dfe9d58c16fe03e25deb6778046b7c4022804a73b3f69dba14695bbcef424c0e2d62be7f02fc5f097fcba831b6718052865504c12e1e00
7
+ data.tar.gz: 149b989e48c22fe9f7f492cae7f0cdd362da30a0ae7619dde7f1f7e218c3fea98a01d823fb15c2bd6f4509ff02ad02805320a0f61b8b8c4f707524dba24dc5b6
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
1
  ## Gemfile
2
2
  ```ruby
3
- gem 'autostip', '~> 1.0.3'
3
+ gem 'autostip', '~> 1.0.4'
4
4
  ```
@@ -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.add_runtime_dependency 'activemodel', '>= 3.0', '< 6.0'
21
+ s.add_dependency 'activesupport', '>= 3.0', '< 6.0'
22
+ s.add_dependency 'activemodel', '>= 3.0', '< 6.0'
22
23
  end
@@ -17,4 +17,5 @@ module Autostrip
17
17
  end
18
18
  end
19
19
 
20
- ActiveModel::Validations::HelperMethods.include Autostrip::Extension
20
+ ActiveModel.include Autostrip::Extension
21
+ ActiveSupport.on_load(:active_record) { ActiveRecord::Base.include Autostrip::Extension }
@@ -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
- def autostrip(*attributes)
7
- attributes.each do |attribute|
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 |model|
10
- value = model.send(attribute)
11
- if Autostrip.performable?(value)
12
- # http://www.davidverhasselt.com/set-attributes-in-activerecord/
13
- model.send("#{attribute}=", Autostrip.perform(value))
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
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Autostrip
5
- VERSION = '1.0.3'
5
+ VERSION = '1.0.4'
6
6
  end
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.3
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