strip_attributes 1.9.2 → 1.10.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/README.md +8 -0
- data/lib/strip_attributes.rb +7 -16
- data/lib/strip_attributes/matchers.rb +16 -7
- data/lib/strip_attributes/version.rb +1 -1
- data/test/matchers_test.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a302a928491058ebb14ecdb965d4afe5a1d56b9dd4306cb25a2bc1a8857dbed1
|
4
|
+
data.tar.gz: 8b93e69476d0976effd53ae0c4904e9f522def8b6ad7526fcf2699b5d94dcf80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4de02ed6d9ea918c62704cf9a486d98912f5806bb06d817023667d60a56e3c12b634b2f22b9d6e39913188152ec3983986072a4a95b6daa4152b5191641c9ae8
|
7
|
+
data.tar.gz: 2d757d642d005cf16fc25d49156d84e88401e4c0d72463703e79632c440a7a7f5f440b63e3c430e8349cda72ce0dfdbe432e94877a7ffe29ab7fadb5e8d41a12
|
data/README.md
CHANGED
@@ -234,7 +234,9 @@ end
|
|
234
234
|
describe User do
|
235
235
|
it { is_expected.to strip_attribute(:name).collapse_spaces }
|
236
236
|
it { is_expected.to strip_attribute :email }
|
237
|
+
it { is_expected.to strip_attributes(:name, :email) }
|
237
238
|
it { is_expected.not_to strip_attribute :password }
|
239
|
+
it { is_expected.not_to strip_attributes(:password, :encrypted_password) }
|
238
240
|
end
|
239
241
|
```
|
240
242
|
|
@@ -244,7 +246,9 @@ end
|
|
244
246
|
class UserTest < ActiveSupport::TestCase
|
245
247
|
should strip_attribute(:name).collapse_spaces
|
246
248
|
should strip_attribute :email
|
249
|
+
should strip_attributes(:name, :email)
|
247
250
|
should_not strip_attribute :password
|
251
|
+
should_not strip_attributes(:password, :encrypted_password)
|
248
252
|
end
|
249
253
|
```
|
250
254
|
|
@@ -257,7 +261,9 @@ describe User do
|
|
257
261
|
it "should strip attributes" do
|
258
262
|
must strip_attribute(:name).collapse_spaces
|
259
263
|
must strip_attribute :email
|
264
|
+
must strip_attributes(:name, :email)
|
260
265
|
wont strip_attribute :password
|
266
|
+
wont strip_attributes(:password, :encrypted_password)
|
261
267
|
end
|
262
268
|
end
|
263
269
|
```
|
@@ -270,7 +276,9 @@ describe User do
|
|
270
276
|
|
271
277
|
must { strip_attribute(:name).collapse_spaces }
|
272
278
|
must { strip_attribute :email }
|
279
|
+
must { strip_attributes(:name, :email) }
|
273
280
|
wont { strip_attribute :password }
|
281
|
+
wont { strip_attributes(:password, :encrypted_password) }
|
274
282
|
end
|
275
283
|
```
|
276
284
|
|
data/lib/strip_attributes.rb
CHANGED
@@ -9,19 +9,12 @@ module ActiveModel::Validations::HelperMethods
|
|
9
9
|
StripAttributes.strip(record, options)
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
13
|
-
# <b>DEPRECATED:</b> Please use <tt>strip_attributes</tt> (non-bang method)
|
14
|
-
# instead.
|
15
|
-
def strip_attributes!(options = {})
|
16
|
-
warn "[DEPRECATION] `strip_attributes!` is deprecated. Please use `strip_attributes` (non-bang method) instead."
|
17
|
-
strip_attributes(options)
|
18
|
-
end
|
19
12
|
end
|
20
13
|
|
21
14
|
module StripAttributes
|
22
15
|
VALID_OPTIONS = [:only, :except, :allow_empty, :collapse_spaces, :replace_newlines, :regex, :if, :unless].freeze
|
23
16
|
|
24
|
-
# Unicode invisible and whitespace characters.
|
17
|
+
# Unicode invisible and whitespace characters. The POSIX character class
|
25
18
|
# [:space:] corresponds to the Unicode class Z ("separator"). We also
|
26
19
|
# include the following characters from Unicode class C ("control"), which
|
27
20
|
# are spaces or invisible characters that make no sense at the start or end
|
@@ -65,22 +58,20 @@ module StripAttributes
|
|
65
58
|
replace_newlines = options[:replace_newlines]
|
66
59
|
regex = options[:regex]
|
67
60
|
|
68
|
-
value
|
61
|
+
value.gsub!(regex, "") if regex
|
69
62
|
|
70
|
-
|
71
|
-
|
72
|
-
if MULTIBYTE_SUPPORTED && value.respond_to?(:gsub!) && Encoding.compatible?(value, MULTIBYTE_SPACE)
|
63
|
+
if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_SPACE)
|
73
64
|
value.gsub!(/\A#{MULTIBYTE_SPACE}+|#{MULTIBYTE_SPACE}+\z/, "")
|
74
|
-
|
65
|
+
else
|
75
66
|
value.strip!
|
76
67
|
end
|
77
68
|
|
78
|
-
value.gsub!(/[\r\n]+/, " ") if replace_newlines
|
69
|
+
value.gsub!(/[\r\n]+/, " ") if replace_newlines
|
79
70
|
|
80
71
|
if collapse_spaces
|
81
|
-
if MULTIBYTE_SUPPORTED &&
|
72
|
+
if MULTIBYTE_SUPPORTED && Encoding.compatible?(value, MULTIBYTE_BLANK)
|
82
73
|
value.gsub!(/#{MULTIBYTE_BLANK}+/, " ")
|
83
|
-
|
74
|
+
else
|
84
75
|
value.squeeze!(" ")
|
85
76
|
end
|
86
77
|
end
|
@@ -6,26 +6,35 @@ module StripAttributes
|
|
6
6
|
# RSpec Examples:
|
7
7
|
#
|
8
8
|
# it { is_expected.to strip_attribute(:first_name) }
|
9
|
+
# it { is_expected.to strip_attributes(:first_name, :last_name) }
|
9
10
|
# it { is_expected.not_to strip_attribute(:password) }
|
11
|
+
# it { is_expected.not_to strip_attributes(:password, :encrypted_password) }
|
10
12
|
#
|
11
13
|
# Minitest Matchers Examples:
|
12
14
|
#
|
13
15
|
# must { strip_attribute :first_name }
|
16
|
+
# must { strip_attributes(:first_name, :last_name) }
|
14
17
|
# wont { strip_attribute :password }
|
15
|
-
|
16
|
-
|
18
|
+
# wont { strip_attributes(:password, :encrypted_password) }
|
19
|
+
def strip_attribute(*attributes)
|
20
|
+
StripAttributeMatcher.new(attributes)
|
17
21
|
end
|
18
22
|
|
23
|
+
alias_method :strip_attributes, :strip_attribute
|
24
|
+
|
19
25
|
class StripAttributeMatcher
|
20
|
-
def initialize(
|
21
|
-
@
|
26
|
+
def initialize(attributes)
|
27
|
+
@attributes = attributes
|
22
28
|
@options = {}
|
23
29
|
end
|
24
30
|
|
25
31
|
def matches?(subject)
|
26
|
-
|
27
|
-
|
28
|
-
|
32
|
+
@attributes.all? do |attribute|
|
33
|
+
@attribute = attribute
|
34
|
+
subject.send("#{@attribute}=", " string ")
|
35
|
+
subject.valid?
|
36
|
+
subject.send(@attribute) == "string" and collapse_spaces?(subject)
|
37
|
+
end
|
29
38
|
end
|
30
39
|
|
31
40
|
def collapse_spaces
|
data/test/matchers_test.rb
CHANGED
@@ -92,4 +92,14 @@ describe SampleMockRecord do
|
|
92
92
|
assert true
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
it "should take a list of arguments" do
|
97
|
+
must strip_attribute(:stripped1, :stripped2, :stripped3)
|
98
|
+
wont strip_attribute(:unstripped1, :unstripped2, :unstripped3)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should alias strip_attribute to strip_attributes" do
|
102
|
+
must strip_attributes(:stripped1, :stripped2, :stripped3)
|
103
|
+
wont strip_attributes(:unstripped1, :unstripped2, :unstripped3)
|
104
|
+
end
|
95
105
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strip_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan McGeary
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|