autostrip 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -1
- data/README.md +2 -2
- data/autostrip.gemspec +5 -1
- data/lib/autostrip/extension.rb +4 -1
- data/lib/autostrip/version.rb +6 -0
- data/lib/autostrip.rb +5 -11
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 777c56877a373ae779fe58c290d5515b46cd5a73
|
4
|
+
data.tar.gz: 39ec5403948976fa91c7948eb0cfd4a426d00566
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ea3b8cc5fd84b671426209ad364d4ae504c1768a9afd8f45fc913daef3fcb3a1635c2641f2720f67f1298217df008cac55a0e580879734f386474bb0d018b69
|
7
|
+
data.tar.gz: c339be3bfac144451cb44512e9941c1b780f80c68da40b36519b40ddae67707e5e8ed80d1fa3aabfb33d73d5a9a663efa35e66c32e1fac97c3ba81c1753a4b92
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/autostrip.gemspec
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require File.expand_path('../lib/autostrip/version', __FILE__)
|
5
|
+
|
2
6
|
Gem::Specification.new do |s|
|
3
7
|
s.name = 'autostrip'
|
4
|
-
s.version =
|
8
|
+
s.version = Autostrip::VERSION
|
5
9
|
s.authors = ['Yaroslav Konoplov']
|
6
10
|
s.email = ['eahome00@gmail.com']
|
7
11
|
s.summary = 'Automatically strip leading and trailing whitespace'
|
data/lib/autostrip/extension.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
# frozen_string_literal: true
|
3
|
+
|
2
4
|
module Autostrip
|
3
5
|
module Extension
|
4
6
|
def autostrip(*attributes)
|
5
7
|
attributes.each do |attribute|
|
6
|
-
before_validation
|
8
|
+
# Use prepend to be sure this runs before all other "before_validation" callbacks.
|
9
|
+
before_validation prepend: true do |model|
|
7
10
|
value = model.send(attribute)
|
8
11
|
if Autostrip.performable?(value)
|
9
12
|
# http://www.davidverhasselt.com/set-attributes-in-activerecord/
|
data/lib/autostrip.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'active_model'
|
3
5
|
require 'unicode-tools'
|
4
6
|
require 'autostrip/extension'
|
@@ -6,21 +8,13 @@ require 'autostrip/extension'
|
|
6
8
|
module Autostrip
|
7
9
|
class << self
|
8
10
|
def perform(value)
|
9
|
-
value.squish
|
11
|
+
value.squish
|
10
12
|
end
|
11
13
|
|
12
14
|
def performable?(value)
|
13
|
-
value
|
15
|
+
String === value
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
|
-
|
19
|
-
include Autostrip::Extension
|
20
|
-
end
|
21
|
-
|
22
|
-
if defined?(ActiveRecord::Base) && !ActiveRecord::Base.methods.include?(:autostrip)
|
23
|
-
class ActiveRecord::Base
|
24
|
-
extend Autostrip::Extension
|
25
|
-
end
|
26
|
-
end
|
20
|
+
ActiveModel::Validations::HelperMethods.include Autostrip::Extension
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Konoplov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- autostrip.gemspec
|
45
45
|
- lib/autostrip.rb
|
46
46
|
- lib/autostrip/extension.rb
|
47
|
+
- lib/autostrip/version.rb
|
47
48
|
homepage: http://github.com/yivo/autostrip
|
48
49
|
licenses:
|
49
50
|
- MIT
|
@@ -64,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
65
|
version: '0'
|
65
66
|
requirements: []
|
66
67
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
68
|
+
rubygems_version: 2.6.8
|
68
69
|
signing_key:
|
69
70
|
specification_version: 4
|
70
71
|
summary: Automatically strip leading and trailing whitespace
|