awesome_scrub 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/README.md +75 -5
- data/Rakefile +8 -0
- data/awesome_scrub.gemspec +4 -5
- data/lib/awesome_scrub.rb +6 -0
- data/lib/awesome_scrub/version.rb +1 -1
- data/test/awesome_scrub_test.rb +49 -0
- metadata +27 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbe558801a238b16bb144989824ee1933cd95ab6
|
4
|
+
data.tar.gz: 520e73654086d8c5ecfa42e85e123a6baba95db2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71ea054936dcd9de2b03fc2c7843745b41694bcc12733a148648fbce99e63b8839ee5f1d128bdf8c21d80d854769baa106eda48e381ca688087152d206021d6d
|
7
|
+
data.tar.gz: de5a6b377bbf73dbffe129dcc5b287146f8d51f5903c3d8774f80124486936bccf790c6d387f7c57b9f3ee23e0059e6c61fc83a6d2bffc22b1573110010177fa
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,80 @@
|
|
1
1
|
# AwesomeScrub
|
2
2
|
|
3
|
-
|
3
|
+
Easy to use `String#scrub`. Prevent Invalid byte sequence in UTF-8.
|
4
|
+
Wrap `params[:name].respond_to?(:scrub) ? params[:name].scrub : params[:name]` to `params[:name].awesome_scrub`.
|
5
|
+
|
6
|
+
[](http://badge.fury.io/rb/awesome_scrub)
|
7
|
+
[](https://travis-ci.org/sanemat/awesome_scrub)
|
8
|
+
[](https://codeclimate.com/github/sanemat/awesome_scrub)
|
9
|
+
|
10
|
+
## Use case
|
11
|
+
|
12
|
+
### Before:
|
13
|
+
```ruby
|
14
|
+
@name = params[:name].presence || 'nobody'
|
15
|
+
```
|
16
|
+
|
17
|
+
### After:
|
18
|
+
```ruby
|
19
|
+
@name = awesome_scrub(params[:name]).presence || 'noby'
|
20
|
+
```
|
21
|
+
|
22
|
+
## Point
|
23
|
+
|
24
|
+
Almost time this is no problem, but params[:name] include `invalid byte sequence in UTF-8`, like `invalid_byte_sequence.presence` (`invalid_byte_sequence.present?`) raises `ArgumentError: invalid byte sequence in UTF-8`.
|
25
|
+
|
26
|
+
This problem's solution is `String#scrub`(Feature of Ruby2.1, and `string-scrub` gem which backport for Ruby2.0), this replaces invalid characters. [Feature #6752: Replacing ill-formed subsequencce - ruby-trunk - Ruby Issue Tracking System](http://bugs.ruby-lang.org/issues/6752)
|
27
|
+
|
28
|
+
This stil has problem for writing code, `params[:name]` is `String` or `nil`, and some case `Array`, `Fixnum`, and other object does not have `#scrub` method.
|
29
|
+
|
30
|
+
### Work around
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
name = params[:name].respond_to?(:scrub) ? params[:name].scrub : params[:name]
|
34
|
+
@name = name.presence || 'nobody'
|
35
|
+
```
|
36
|
+
|
37
|
+
### Solution
|
38
|
+
```ruby
|
39
|
+
@name = awesome_scrub(params[:name]).presence || 'noby'
|
40
|
+
```
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
### Methods
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
# call scrub
|
48
|
+
awesome_scrub(args) #=> args.scrub
|
49
|
+
|
50
|
+
# call scrub!
|
51
|
+
awesome_scrub!(args) #=> args.scrub!
|
52
|
+
```
|
53
|
+
|
54
|
+
### Examples
|
55
|
+
```ruby
|
56
|
+
class Foo
|
57
|
+
include AwesomeScrub
|
58
|
+
|
59
|
+
def bar
|
60
|
+
awesome_scrub(any)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
64
|
+
OR
|
65
|
+
```ruby
|
66
|
+
class Foo
|
67
|
+
extend AwesomeScrub
|
68
|
+
|
69
|
+
def bar
|
70
|
+
awesome_scrub(any)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
OR
|
75
|
+
```ruby
|
76
|
+
AwesomeScrub::awesome_scrub(any)
|
77
|
+
```
|
4
78
|
|
5
79
|
## Installation
|
6
80
|
|
@@ -16,10 +90,6 @@ Or install it yourself as:
|
|
16
90
|
|
17
91
|
$ gem install awesome_scrub
|
18
92
|
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
93
|
## Contributing
|
24
94
|
|
25
95
|
1. Fork it ( http://github.com/sanemat/awesome_scrub/fork )
|
data/Rakefile
CHANGED
data/awesome_scrub.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = AwesomeScrub::VERSION
|
9
9
|
spec.authors = ['sanemat']
|
10
10
|
spec.email = ['o.gata.ken@gmail.com']
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{Easy to use String#scrub.}
|
12
|
+
spec.description = %q{Wrap String#scrub preventing Invalid byte sequence in UTF-8.}
|
13
13
|
spec.homepage = 'https://github.com/sanemat/awesome_scrub'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -18,10 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
|
23
|
-
spec.add_development_dependency 'bundler', '~> 1.5.0.rc'
|
21
|
+
spec.add_development_dependency 'bundler'
|
24
22
|
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'minitest', '> 4'
|
25
24
|
# NOTE: Recommend, but if you implement `#scrub` yourself, no problem.
|
26
25
|
#spec.add_dependency 'string-scrub' if RUBY_VERSION < '2.1'
|
27
26
|
end
|
data/lib/awesome_scrub.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require_relative '../lib/awesome_scrub'
|
3
|
+
|
4
|
+
module AwesomeScrub
|
5
|
+
class AwesomeScrubTest < Minitest::Test
|
6
|
+
|
7
|
+
class TestClassWithInstanceAwesomeScrubs
|
8
|
+
include AwesomeScrub
|
9
|
+
end
|
10
|
+
|
11
|
+
class TestClassWithClassAwesomeScrubs
|
12
|
+
extend AwesomeScrub
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@instance_with_modules = TestClassWithInstanceAwesomeScrubs.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_normal_string
|
20
|
+
[@instance_with_modules, TestClassWithClassAwesomeScrubs, AwesomeScrub].each do |awesome_scrub|
|
21
|
+
assert_equal('foo', awesome_scrub.awesome_scrub('foo'))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_bang_normal_string
|
26
|
+
[@instance_with_modules, TestClassWithClassAwesomeScrubs, AwesomeScrub].each do |awesome_scrub|
|
27
|
+
assert_equal('foo', awesome_scrub.awesome_scrub!('foo'))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_call_scrub
|
32
|
+
[@instance_with_modules, TestClassWithClassAwesomeScrubs, AwesomeScrub].each do |awesome_scrub|
|
33
|
+
mock = MiniTest::Mock.new
|
34
|
+
mock.expect(:scrub, 'woot')
|
35
|
+
awesome_scrub.awesome_scrub(mock)
|
36
|
+
assert mock.verify
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_bang_call_scrub
|
41
|
+
[@instance_with_modules, TestClassWithClassAwesomeScrubs, AwesomeScrub].each do |awesome_scrub|
|
42
|
+
mock = MiniTest::Mock.new
|
43
|
+
mock.expect(:scrub!, 'woot')
|
44
|
+
awesome_scrub.awesome_scrub!(mock)
|
45
|
+
assert mock.verify
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awesome_scrub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sanemat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,7 +38,21 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>'
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>'
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4'
|
55
|
+
description: Wrap String#scrub preventing Invalid byte sequence in UTF-8.
|
42
56
|
email:
|
43
57
|
- o.gata.ken@gmail.com
|
44
58
|
executables: []
|
@@ -46,6 +60,7 @@ extensions: []
|
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
48
62
|
- .gitignore
|
63
|
+
- .travis.yml
|
49
64
|
- Gemfile
|
50
65
|
- LICENSE.txt
|
51
66
|
- README.md
|
@@ -53,6 +68,7 @@ files:
|
|
53
68
|
- awesome_scrub.gemspec
|
54
69
|
- lib/awesome_scrub.rb
|
55
70
|
- lib/awesome_scrub/version.rb
|
71
|
+
- test/awesome_scrub_test.rb
|
56
72
|
homepage: https://github.com/sanemat/awesome_scrub
|
57
73
|
licenses:
|
58
74
|
- MIT
|
@@ -65,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
81
|
requirements:
|
66
82
|
- - '>='
|
67
83
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
84
|
+
version: '0'
|
69
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
86
|
requirements:
|
71
87
|
- - '>='
|
@@ -76,5 +92,6 @@ rubyforge_project:
|
|
76
92
|
rubygems_version: 2.0.14
|
77
93
|
signing_key:
|
78
94
|
specification_version: 4
|
79
|
-
summary:
|
80
|
-
test_files:
|
95
|
+
summary: Easy to use String#scrub.
|
96
|
+
test_files:
|
97
|
+
- test/awesome_scrub_test.rb
|