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 CHANGED
@@ -15,4 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- vendor/ruby
18
+ vendor/ruby
19
+ /vendor/
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ *0.1.5* (September 19, 2013)
2
+
3
+ * Added #pop method to Hash
4
+ * Randomize spec runs
5
+ * Cleaned up un-needed development gems
6
+
1
7
  *0.1.4* (August 19, 2013)
2
8
 
3
9
  * Added TimeTool for time string conversions
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Midwire Common Gem
2
2
 
3
- **Version: 0.1.4**
3
+ **Version: 0.1.5**
4
4
 
5
5
  A handy Ruby library for Midwire development
6
6
 
@@ -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}
@@ -1,6 +1,6 @@
1
1
  original_verbosity = $VERBOSE
2
2
  $VERBOSE = nil
3
3
  module MidwireCommon
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
6
6
  $VERBOSE = original_verbosity
@@ -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 = {:a => "this is a test", 'b' => 'this is not the answer'}
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
- {:a => 1, :b => 2, :c => 3}.except(:a).should == {:b => 2, :c => 3}
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
- {:a => 1, :b => 2, :c => 3}.only(:a).should == {:a => 1}
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
- { :a => 1, :b => 2, :c => 3}.to_query_string.should == "a=1&b=2&c=3"
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 == {:a=>1, :b=>2, :c=>3}
31
+ h.symbolize_keys.should == {a: 1, b: 2, c: 3}
26
32
  h.symbolize_keys!
27
- h.should == {:a=>1, :b=>2, :c=>3}
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 == {:a=>1, :b=>{:a=>1, :b=>2, :c=>{:a=>1, :b=>2, :c=>3}}, :c=>3}
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
@@ -15,6 +15,7 @@ PROJECT_ROOT = File.expand_path('..', File.dirname(__FILE__))
15
15
  RSpec.configure do |config|
16
16
  config.mock_with :rspec
17
17
  config.color_enabled = true
18
+ config.order = "random"
18
19
 
19
20
  def capture(stream)
20
21
  begin
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
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-08-19 00:00:00.000000000 Z
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: growl
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: pry
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: rake
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: :development
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: 2378234403548503770
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: 2378234403548503770
209
+ hash: 3286182842310283713
226
210
  requirements: []
227
211
  rubyforge_project:
228
212
  rubygems_version: 1.8.23