autostrip 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 000664f4e079a8e338ba1a9b59d355ed33b217ff
4
+ data.tar.gz: 73faf0e3c9ba12e91f9a998ffa14193f3fe9de31
5
+ SHA512:
6
+ metadata.gz: 8ea4f77bc144cf8468383a9cb4f87088ef34423d0ddb36355a244261f419c1ef6b9e8a2941f6b5ef63d0e2ab9a4fbac358481fb8561b2b702270914f6a695855
7
+ data.tar.gz: a9ad45a19dec60020d1192c698943d760f4899b5b71138e04cf3026b456f0dcaa60b7bfdbdd71d715b6b76ebefaa2ab75ffb16cd6471d7cc945f4ce74c7d5864
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in confo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Yaroslav Konoplov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ ## Gemfile
2
+ ```ruby
3
+ gem 'autostip', github: 'yivo/autostip'
4
+ ```
data/autostrip.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ Gem::Specification.new do |s|
3
+ s.name = 'autostrip'
4
+ s.version = '1.0.1'
5
+ s.authors = ['Yaroslav Konoplov']
6
+ s.email = ['eahome00@gmail.com']
7
+ s.summary = 'Automatically strip leading and trailing whitespace'
8
+ s.description = 'Automatically strip leading and trailing whitespace'
9
+ s.homepage = 'http://github.com/yivo/autostrip'
10
+ s.license = 'MIT'
11
+
12
+ s.executables = `git ls-files -z -- bin/*`.split("\x0").map{ |f| File.basename(f) }
13
+ s.files = `git ls-files -z`.split("\x0")
14
+ s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
15
+ s.require_paths = ['lib']
16
+
17
+ s.add_runtime_dependency 'activemodel', '>= 3.0', '< 6.0'
18
+ end
data/lib/autostrip.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require 'active_model'
3
+ require 'unicode-tools'
4
+ require 'autostrip/extension'
5
+
6
+ module Autostrip
7
+ class << self
8
+ def perform(value)
9
+ value.squish.trim
10
+ end
11
+
12
+ def performable?(value)
13
+ value.kind_of?(String)
14
+ end
15
+ end
16
+ end
17
+
18
+ module ActiveModel::Validations::HelperMethods
19
+ include Autostrip::Extension
20
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ module Autostrip
3
+ module Extension
4
+ def autostrip(*attributes)
5
+ attributes.each do |attribute|
6
+ before_validation do |model|
7
+ value = model.send(attribute)
8
+ if Autostrip.performable?(value)
9
+ # http://www.davidverhasselt.com/set-attributes-in-activerecord/
10
+ model.send("#{attribute}=", Autostrip.perform(value))
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autostrip
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav Konoplov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
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'
33
+ description: Automatically strip leading and trailing whitespace
34
+ email:
35
+ - eahome00@gmail.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - ".gitignore"
41
+ - Gemfile
42
+ - LICENSE.txt
43
+ - README.md
44
+ - autostrip.gemspec
45
+ - lib/autostrip.rb
46
+ - lib/autostrip/extension.rb
47
+ homepage: http://github.com/yivo/autostrip
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.5.1
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Automatically strip leading and trailing whitespace
71
+ test_files: []