midwire_common 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/CHANGELOG +6 -0
- data/README.md +1 -1
- data/lib/midwire_common/hash.rb +16 -2
- data/lib/midwire_common/version.rb +1 -1
- data/midwire_common.gemspec +2 -2
- data/spec/lib/midwire_common/hash_spec.rb +13 -7
- data/spec/spec_helper.rb +1 -0
- metadata +8 -24
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
data/README.md
CHANGED
data/lib/midwire_common/hash.rb
CHANGED
@@ -9,17 +9,29 @@ class Hash
|
|
9
9
|
# Usage { :a => 1, :b => 2, :c => 3}.except(:a) -> { :b => 2, :c => 3}
|
10
10
|
def except(*keys)
|
11
11
|
self.reject { |k,v|
|
12
|
-
keys.include? k.to_sym
|
12
|
+
keys.flatten.include? k.to_sym
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
16
16
|
# Usage { :a => 1, :b => 2, :c => 3}.only(:a) -> {:a => 1}
|
17
17
|
def only(*keys)
|
18
18
|
self.dup.reject { |k,v|
|
19
|
-
!keys.include? k.to_sym
|
19
|
+
!keys.flatten.include? k.to_sym
|
20
20
|
}
|
21
21
|
end
|
22
22
|
|
23
|
+
# Usage h = { :a => 1, :b => 2, :c => 3}.pop(:a) -> {:a => 1}
|
24
|
+
# ... and now h == { :b => 2, :c => 3}
|
25
|
+
def pop(*keys)
|
26
|
+
r = self.reject { |k,v|
|
27
|
+
!keys.flatten.include? k.to_sym
|
28
|
+
}
|
29
|
+
self.reject! { |k,v|
|
30
|
+
keys.flatten.include? k.to_sym
|
31
|
+
}
|
32
|
+
r
|
33
|
+
end
|
34
|
+
|
23
35
|
# Usage { :a => 1, :b => 2, :c => 3}.to_query_string #= a=1&b=2&c=3
|
24
36
|
def to_query_string
|
25
37
|
require 'uri'
|
@@ -49,3 +61,5 @@ class Hash
|
|
49
61
|
self
|
50
62
|
end
|
51
63
|
end
|
64
|
+
|
65
|
+
# h = { :a => 1, :b => 2, :c => 3}
|
data/midwire_common.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_development_dependency "guard"
|
21
21
|
gem.add_development_dependency "guard-bundler"
|
22
22
|
gem.add_development_dependency "guard-rspec"
|
23
|
-
gem.add_development_dependency "growl"
|
24
|
-
gem.add_development_dependency "rb-fsevent"
|
25
23
|
gem.add_development_dependency "pry"
|
26
24
|
gem.add_development_dependency "rake"
|
25
|
+
|
26
|
+
gem.add_runtime_dependency "ruby-prof"
|
27
27
|
end
|
@@ -2,33 +2,39 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Hash do
|
4
4
|
it "greps key/value pairs using a regular expression" do
|
5
|
-
h = {:
|
5
|
+
h = {a: "this is a test", 'b' => 'this is not the answer'}
|
6
6
|
h.grep(/a test/).should == [[:a, "this is a test"]]
|
7
7
|
h.grep(/b/).should == [['b', "this is not the answer"]]
|
8
8
|
h.grep(/^this/).should == [[:a, "this is a test"], ["b", "this is not the answer"]]
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns elements with certain keys filtered out" do
|
12
|
-
{:
|
12
|
+
{a: 1, b: 2, c: 3}.except(:a).should == {b: 2, c: 3}
|
13
13
|
end
|
14
14
|
|
15
15
|
it "returns elements for discretely passed keys" do
|
16
|
-
{:
|
16
|
+
{a: 1, b: 2, c: 3}.only(:a).should == {a: 1}
|
17
|
+
end
|
18
|
+
|
19
|
+
it "pops an element off of the stack" do
|
20
|
+
h = {a: 1, b: 2, c: 3}
|
21
|
+
h.pop(:a).should == {a: 1}
|
22
|
+
h.should == {b: 2, c: 3}
|
17
23
|
end
|
18
24
|
|
19
25
|
it "returns a query string" do
|
20
|
-
{ :
|
26
|
+
{ a: 1, b: 2, c: 3}.to_query_string.should == "a=1&b=2&c=3"
|
21
27
|
end
|
22
28
|
|
23
29
|
it "symbolizes its keys" do
|
24
30
|
h = {'a'=>1, 'b'=>2, 'c'=>3}
|
25
|
-
h.symbolize_keys.should == {:
|
31
|
+
h.symbolize_keys.should == {a: 1, b: 2, c: 3}
|
26
32
|
h.symbolize_keys!
|
27
|
-
h.should == {:
|
33
|
+
h.should == {a: 1, b: 2, c: 3}
|
28
34
|
end
|
29
35
|
|
30
36
|
it "recursively symbolizes its keys" do
|
31
37
|
h = {'a'=>1, 'b'=>{'a'=>1, 'b'=>2, 'c'=>{'a'=>1, 'b'=>2, 'c'=>3}}, 'c'=>3}
|
32
|
-
h.recursively_symbolize_keys!.should == {:
|
38
|
+
h.recursively_symbolize_keys!.should == {a: 1, b: {a: 1, b: 2, c: {a: 1, b: 2, c: 3}}, c: 3}
|
33
39
|
end
|
34
40
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midwire_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -92,23 +92,7 @@ dependencies:
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ! '>='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: rb-fsevent
|
95
|
+
name: pry
|
112
96
|
requirement: !ruby/object:Gem::Requirement
|
113
97
|
none: false
|
114
98
|
requirements:
|
@@ -124,7 +108,7 @@ dependencies:
|
|
124
108
|
- !ruby/object:Gem::Version
|
125
109
|
version: '0'
|
126
110
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
111
|
+
name: rake
|
128
112
|
requirement: !ruby/object:Gem::Requirement
|
129
113
|
none: false
|
130
114
|
requirements:
|
@@ -140,14 +124,14 @@ dependencies:
|
|
140
124
|
- !ruby/object:Gem::Version
|
141
125
|
version: '0'
|
142
126
|
- !ruby/object:Gem::Dependency
|
143
|
-
name:
|
127
|
+
name: ruby-prof
|
144
128
|
requirement: !ruby/object:Gem::Requirement
|
145
129
|
none: false
|
146
130
|
requirements:
|
147
131
|
- - ! '>='
|
148
132
|
- !ruby/object:Gem::Version
|
149
133
|
version: '0'
|
150
|
-
type: :
|
134
|
+
type: :runtime
|
151
135
|
prerelease: false
|
152
136
|
version_requirements: !ruby/object:Gem::Requirement
|
153
137
|
none: false
|
@@ -213,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
213
197
|
version: '0'
|
214
198
|
segments:
|
215
199
|
- 0
|
216
|
-
hash:
|
200
|
+
hash: 3286182842310283713
|
217
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
202
|
none: false
|
219
203
|
requirements:
|
@@ -222,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
206
|
version: '0'
|
223
207
|
segments:
|
224
208
|
- 0
|
225
|
-
hash:
|
209
|
+
hash: 3286182842310283713
|
226
210
|
requirements: []
|
227
211
|
rubyforge_project:
|
228
212
|
rubygems_version: 1.8.23
|