reactive_support 0.3.0.beta → 0.3.0.beta2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e03c0b062f28792315df4ddeb261e6084d93495
4
- data.tar.gz: 022f699675dcb56d66c9f1fd5f1c65b900d1edd2
3
+ metadata.gz: a54091a52002588f7f971f0d2327ff2d5f521675
4
+ data.tar.gz: 3fa7f6ba5efdaa4b4565d25013ff5e43179f6ae0
5
5
  SHA512:
6
- metadata.gz: 00f6717977c36891e7df8f75f3935e9d9c0baf91618dea25415e6f8adf486168fc7ab678527b9cc6137df02358ff919bfbd40167bd2c595a00535611f7174e50
7
- data.tar.gz: e0db1dcf183d452823e6bffb71ab33322f92c42f21882fb3ebd90c3ba9e115d51651ae7d7eb4ebd38deaa9a7447957b2ad5008d4f0f03ada7940302b8b9335ef
6
+ metadata.gz: 1f693c85385f91a5bcd4d5d5eb652b7695c5cdf816c6fbc91c02ed7c05a307e429849e05002d7cdad510fd6d7e87a3e56a8693eeda141ee034342632562cccc0
7
+ data.tar.gz: a3b687c0248b3f58245ec69ae532d4a4ed0d16e382583336e833228ea0f151b1da9f5d8c6f66da2615be8084800286f5c592bf8e6260db43e4c4b42313458118
@@ -1,5 +1,52 @@
1
1
  class Hash
2
2
 
3
+ # The +#clean+ method returns a hash identical to the calling hash but
4
+ # with the given +*keys+, if present, removed. If all the keys in the
5
+ # hash are given as arguments, an empty hash is returned. The +#clean+
6
+ # method is non-destructive; the original hash is still available after
7
+ # it is called. It does have a destructive form, +#clean!+.
8
+ #
9
+ # Examples:
10
+ # hash = {:foo => 'bar'}
11
+ # hash.clean(:baz) # => {:foo => 'bar'}
12
+ # hash.clean(:foo) # => {}
13
+ # hash # => {:foo => 'bar'}
14
+ #
15
+ # Examples with multiple arguments:
16
+ # hash = { 'foo' => 'bar', 'baz' => 'qux', => :norf => 'raboof' }
17
+ # hash.clean('foo', :norf) # => {'baz' => 'qux'}
18
+ # hash # => { 'foo' => 'bar', 'baz' => 'qux', :norf => 'raboof' }
19
+
20
+ def clean(*keys)
21
+ self.reject {|k,v| k.in?(keys) }
22
+ end
23
+
24
+ # The +#clean!+ method returns a hash identical to the calling hash but
25
+ # with the given +*keys+, if present, removed. If all the keys in the
26
+ # hash are given as arguments, an empty hash is returned. The +#clean!+
27
+ # method is non-destructive; the original hash is still available after
28
+ # it is called. It does have a non-destructive form, +#clean+.
29
+ #
30
+ # Examples where hash is not changed:
31
+ # hash = {:foo => 'bar'}
32
+ # hash.clean!(:baz) # => {:foo => 'bar'}
33
+ # hash # => {:foo => 'bar'}
34
+ #
35
+ # Examples where hash is changed:
36
+ # hash = {'foo' => 'bar'}
37
+ # hash.clean!(:foo) # => {}
38
+ # hash # => {}
39
+ #
40
+ # Examples with multiple arguments:
41
+ # hash = { 'foo' => 'bar', 'baz' => 'qux', => :norf => 'raboof' }
42
+ # hash.clean('foo', :norf) # => {'baz' => 'qux'}
43
+ # hash # => {'baz' => 'qux'}
44
+
45
+ def clean!(*keys)
46
+ self.reject! {|k,v| k.in?(keys) }
47
+ self
48
+ end
49
+
3
50
  # The +#symbolize_keys+ method returns a hash identical to the calling
4
51
  # hash but with string keys turned into symbols. It is non-destructive;
5
52
  # the original hash is still available after it is called.
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
 
9
9
  s.name = 'reactive_support'
10
10
  s.version = ReactiveSupport.gem_version
11
- s.date = '2014-11-25'
11
+ s.date = '2014-11-27'
12
12
 
13
13
  s.description = "ActiveSupport methods re-implemented independently of the Rails ecosystem"
14
14
  s.summary = "ReactiveSupport provides useful ActiveSupport methods in a gem that is simple, stable, agnostic, and transparent."
@@ -137,6 +137,84 @@ describe ReactiveExtensions do
137
137
  expect { hash.stringify_keys! }.to change(hash, :keys)
138
138
  end
139
139
  end
140
+
141
+ describe 'clean' do
142
+ context 'when no cleaning is needed' do
143
+ it 'returns the original hash' do
144
+ expect({:foo => 'bar'}.clean(:baz)). to eql({:foo => 'bar'})
145
+ end
146
+
147
+ it 'doesn\'t raise an error' do
148
+ expect{ {:foo => 'bar'}.clean(:baz) }.not_to raise_error
149
+ end
150
+ end
151
+
152
+ context 'when there are some keys to clean' do
153
+ it 'removes specified keys' do
154
+ expect({:foo => 'bar', :baz => 'qux'}.clean(:baz)).to eql({:foo => 'bar'})
155
+ end
156
+
157
+ it 'doesn\'t change the original hash' do
158
+ hash = {:foo => 'bar', :baz => 'qux', 'norf' => 'raboof'}
159
+ expect{ hash.clean(:baz, 'norf') }.not_to change(hash, :keys)
160
+ end
161
+ end
162
+
163
+ context 'when all keys must be cleaned' do
164
+ it 'returns an empty hash' do
165
+ expect({:foo => 'bar'}.clean(:foo)).to eql({})
166
+ end
167
+
168
+ it 'doesn\'t change the original hash' do
169
+ hash = {:foo => 'bar'}
170
+ expect{ hash.clean(:foo) }.not_to change(hash, :keys)
171
+ end
172
+ end
173
+ end
174
+
175
+ describe 'clean!' do
176
+ context 'when no cleaning is needed' do
177
+ it 'returns the original hash' do
178
+ expect({:foo => 'bar'}.clean!(:baz)). to eql({:foo => 'bar'})
179
+ end
180
+
181
+ it 'doesn\'t raise an error' do
182
+ expect{ {:foo => 'bar'}.clean(:baz) }.not_to raise_error
183
+ end
184
+ end
185
+
186
+ context 'when there are some keys to clean' do
187
+ it 'removes specified keys' do
188
+ expect({:foo => 'bar', :baz => 'qux'}.clean!(:baz)).to eql({:foo => 'bar'})
189
+ end
190
+
191
+ it 'changes the original hash' do
192
+ hash = {:foo => 'bar', :baz => 'qux', 'norf' => 'raboof'}
193
+ expect{ hash.clean!(:baz, 'norf') }.to change(hash, :keys)
194
+ end
195
+
196
+ it 'returns the hash' do
197
+ hash = {:foo => 'bar', :baz => 'qux'}
198
+ expect(hash.clean!(:baz)).to eql hash
199
+ end
200
+ end
201
+
202
+ context 'when all keys must be cleaned' do
203
+ it 'returns an empty hash' do
204
+ expect({:foo => 'bar'}.clean!(:foo)).to eql({})
205
+ end
206
+
207
+ it 'changes the original hash' do
208
+ hash = {:foo => 'bar'}
209
+ expect{ hash.clean!(:foo) }.to change(hash, :keys)
210
+ end
211
+
212
+ it 'returns the hash' do
213
+ hash = {:foo => 'bar'}
214
+ expect(hash.clean!(:foo)).to eql hash
215
+ end
216
+ end
217
+ end
140
218
  end
141
219
 
142
220
  describe 'proc methods' do
data/version.rb CHANGED
@@ -7,7 +7,7 @@ module ReactiveSupport
7
7
  MAJOR = '0'
8
8
  MINOR = '3'
9
9
  PATCH = '0'
10
- PRE = 'beta'
10
+ PRE = 'beta2'
11
11
 
12
12
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.').chomp('.')
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.beta
4
+ version: 0.3.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dana Scheider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-25 00:00:00.000000000 Z
11
+ date: 2014-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: 1.3.1
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.4.3
126
+ rubygems_version: 2.2.2
127
127
  signing_key:
128
128
  specification_version: 1
129
129
  summary: ReactiveSupport provides useful ActiveSupport methods in a gem that is simple,