attribute_sanitizer 0.0.2 → 0.0.3
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.
- data/Gemfile.lock +1 -1
- data/lib/attribute_sanitizer_helpers.rb +4 -7
- data/test/attribute_sanitizer_test.rb +9 -0
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -45,17 +45,14 @@ class AttributeSanitizer
|
|
45
45
|
# end
|
46
46
|
#
|
47
47
|
# Foo.sanitize_attributes("1,2,3") # => ["1", "2", "3"]
|
48
|
-
def sanitize_attributes(
|
49
|
-
if
|
50
|
-
return attrs unless @_attribute_sanitizer
|
51
|
-
@_attribute_sanitizer.sanitize(attrs)
|
52
|
-
elsif block_given?
|
48
|
+
def sanitize_attributes(*args, &block)
|
49
|
+
if block_given?
|
53
50
|
@_attribute_sanitizer = AttributeSanitizer.new(self)
|
54
51
|
@_attribute_sanitizer.instance_eval(&block)
|
55
52
|
else
|
56
|
-
|
53
|
+
retval = @_attribute_sanitizer ? args.map { |val| @_attribute_sanitizer.sanitize(val) } : args
|
54
|
+
retval.size < 2 ? retval.first : retval
|
57
55
|
end
|
58
56
|
end
|
59
|
-
|
60
57
|
end
|
61
58
|
end
|
@@ -92,6 +92,15 @@ class TestAttributeSanitizer < Test::Unit::TestCase
|
|
92
92
|
end
|
93
93
|
assert_equal({bar: 1}, Bagel.sanitize_attributes(foo: 1))
|
94
94
|
end
|
95
|
+
|
96
|
+
should "let us sanitize nil" do
|
97
|
+
Bagel.sanitize_attributes do
|
98
|
+
add_step do |val|
|
99
|
+
"pass"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
assert_equal "pass", Bagel.sanitize_attributes(nil)
|
103
|
+
end
|
95
104
|
end
|
96
105
|
|
97
106
|
def stringify(val)
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: attribute_sanitizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jim Garvin
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-21 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|