tiny_sweeper 0.0.3 → 0.0.4
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 +6 -0
- data/lib/tiny_sweeper.rb +6 -8
- data/lib/tiny_sweeper/version.rb +1 -1
- data/spec/tiny_sweeper_spec.rb +10 -0
- metadata +1 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f01b1523f85b42ff7dab6b0a3f5f45f7fc0fef1
|
4
|
+
data.tar.gz: 44f3c34cd71b6b9ca16aaa8ff6f972bc49f3d4cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f69edb529e29a9496b7d72bb5fa91fe9932ddd7600e337b1056798625633313a9af87cc4eef7abe20a6eafd8e267f12c360572bb807850a779f4ccf77f7e6507
|
7
|
+
data.tar.gz: 7fa70945f24ed1f00d7365efaf7f2e1aef4eeacbc7c16ec0e3ff64916876beae8f5a62d9735f95428f787ff3efd3d32fe90d5d0fcf5f0702f6f671fa7b8ad6ac
|
data/README.md
CHANGED
@@ -26,6 +26,12 @@ dessert.topping = ' ButTTERscotCH '
|
|
26
26
|
dessert.topping #=> 'butterscotch'. Tidy!
|
27
27
|
```
|
28
28
|
|
29
|
+
TinySweeper will not bother you about your nil values; they're your job to handle.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Sundae.new.topping = nil # No topping? TinySweeper won't sweep it.
|
33
|
+
```
|
34
|
+
|
29
35
|
If you have an object with lots of attributes that need cleaning, you can do that, too:
|
30
36
|
|
31
37
|
```ruby
|
data/lib/tiny_sweeper.rb
CHANGED
@@ -3,11 +3,13 @@ module TinySweeper
|
|
3
3
|
def sweep(field_name, &sweeper)
|
4
4
|
stop_if_we_have_seen_this_before!(field_name)
|
5
5
|
|
6
|
-
writer_method_name = writer_method_name(field_name)
|
7
|
-
|
8
6
|
overrides_module.module_eval do
|
9
|
-
define_method(
|
10
|
-
|
7
|
+
define_method("#{field_name}=") do |value|
|
8
|
+
if value
|
9
|
+
super(sweeper.call(value))
|
10
|
+
else
|
11
|
+
super(value)
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -37,10 +39,6 @@ module TinySweeper
|
|
37
39
|
|
38
40
|
@swept_fields << field_name
|
39
41
|
end
|
40
|
-
|
41
|
-
def writer_method_name(field_name)
|
42
|
-
"#{field_name}=".to_sym
|
43
|
-
end
|
44
42
|
end
|
45
43
|
|
46
44
|
def self.included(base)
|
data/lib/tiny_sweeper/version.rb
CHANGED
data/spec/tiny_sweeper_spec.rb
CHANGED
@@ -22,6 +22,16 @@ describe 'cleaning fields' do
|
|
22
22
|
expect(contract.name).to eq('GONNA SHOUT IT')
|
23
23
|
end
|
24
24
|
|
25
|
+
it "lets nils through without complaint. nil is YOUR job to handle." do
|
26
|
+
contract = Contract.new
|
27
|
+
expect {
|
28
|
+
contract.name = nil
|
29
|
+
contract.notes = nil
|
30
|
+
}.to_not raise_error
|
31
|
+
expect(contract.name).to be_nil
|
32
|
+
expect(contract.notes).to be_nil
|
33
|
+
end
|
34
|
+
|
25
35
|
describe 'sweeping up ALL the fields at once' do
|
26
36
|
let(:the_contract) {
|
27
37
|
Contract.new.tap do |c|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_sweeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Bernier
|
@@ -76,4 +76,3 @@ summary: A tiny helper to clean your inputs
|
|
76
76
|
test_files:
|
77
77
|
- spec/spec_helper.rb
|
78
78
|
- spec/tiny_sweeper_spec.rb
|
79
|
-
has_rdoc:
|