tiny_sweeper 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57a9592ee6e0610b57e326c16b4acc66c4e84735
4
- data.tar.gz: 8ac28a68c9d45d9926aeffce712aae4ac03a3f00
3
+ metadata.gz: 7f01b1523f85b42ff7dab6b0a3f5f45f7fc0fef1
4
+ data.tar.gz: 44f3c34cd71b6b9ca16aaa8ff6f972bc49f3d4cf
5
5
  SHA512:
6
- metadata.gz: ab8711abf77ee6cdf3ab60b1cdefc4b1ef918b4632f0ffa165c67236aa2776a029ad095c5ae789f533ec71b06c55074879492befb7fe269905ec27914b2ab9a3
7
- data.tar.gz: 5106e0f3a1107d974f5ab4e240d94e948eccbc6010cebd1764135e22578289598076d1d59d95775f9cfd212850a6e8ed7d1f01713bbbac1537c3de2d7e49ef30
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
@@ -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(writer_method_name) do |value|
10
- super(sweeper.call(value))
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)
@@ -1,3 +1,3 @@
1
1
  module TinySweeper
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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.3
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: