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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70989ae37ee48f0891f3b0f5e7901e2fc2dd4698
4
- data.tar.gz: c1a3401e126a12a3e78aa7943aa9af5986655849
3
+ metadata.gz: 777c56877a373ae779fe58c290d5515b46cd5a73
4
+ data.tar.gz: 39ec5403948976fa91c7948eb0cfd4a426d00566
5
5
  SHA512:
6
- metadata.gz: 2760c4e74cf8406fdb110bb2ae976fa03376955ba2895e5bab3e1e12ac34e93b5f6081126055b838c4baeae0413a5cdbcbc9fee321ca97ce27154cb24648ead2
7
- data.tar.gz: 940e18551e1018e008b66b7a21cb3f8240ee1c846442d80404d948d7d2ae264cdc098fc882997a2abf3a03cbc3ba4b7c4ffb2a20c51ca5967009aa0e24a2da92
6
+ metadata.gz: 3ea3b8cc5fd84b671426209ad364d4ae504c1768a9afd8f45fc913daef3fcb3a1635c2641f2720f67f1298217df008cac55a0e580879734f386474bb0d018b69
7
+ data.tar.gz: c339be3bfac144451cb44512e9941c1b780f80c68da40b36519b40ddae67707e5e8ed80d1fa3aabfb33d73d5a9a663efa35e66c32e1fac97c3ba81c1753a4b92
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  source 'https://rubygems.org'
2
5
 
3
6
  # Specify your gem's dependencies in confo.gemspec
4
- gemspec
7
+ gemspec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
1
  ## Gemfile
2
2
  ```ruby
3
- gem 'autostip', github: 'yivo/autostip'
4
- ```
3
+ gem 'autostip', '~> 1.0.3'
4
+ ```
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 = '1.0.2'
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'
@@ -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 do |model|
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/
@@ -0,0 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ module Autostrip
5
+ VERSION = '1.0.3'
6
+ end
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.trim
11
+ value.squish
10
12
  end
11
13
 
12
14
  def performable?(value)
13
- value.kind_of?(String)
15
+ String === value
14
16
  end
15
17
  end
16
18
  end
17
19
 
18
- module ActiveModel::Validations::HelperMethods
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.2
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: 2016-10-21 00:00:00.000000000 Z
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.5.1
68
+ rubygems_version: 2.6.8
68
69
  signing_key:
69
70
  specification_version: 4
70
71
  summary: Automatically strip leading and trailing whitespace