mudbug 0.7.3.1 → 0.8.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +8 -8
  2. data/VERSION +1 -1
  3. data/lib/mudbug.rb +24 -8
  4. data/test/mudbug.rb +30 -4
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzczZGM4MGZkMWIxMjI3NDg5Y2ZiYzVjM2UyNmRlM2FhM2E5OTQxYw==
4
+ MWQ5MTgyMDc4ODAxMzZlNGNjODA3Mzk4NmFjYmJmMzU5YWQ3MzY5ZA==
5
5
  data.tar.gz: !binary |-
6
- MGVjNzE3MTBiMmU3MzA3YTJmOWRkNjJiYTkxYmEwNWE0OTMyMGVkMg==
6
+ NzM5M2RlZTk4OGRhZGJmZTQwOGQ3Njc0MWVjMTAxZDJkNTQ2YTc2MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- N2M2OTBjMDVjODE1OTIwMmQ3ZjcwOGM1YmUxYzlmYzBjOTRhY2I1MWIwZTQ5
10
- MzI5MWY3YWI1ZjRiOTBiNTJmMGE4MDM0NDNhMmRlMjc1MjMzZDMyMzg1ZmM5
11
- MjUyZDIxMzQ2NTk5ZGFmYTkxZjQ3MWU2N2IwOTk0ZDU1YzA3NDU=
9
+ ZjRkYmM5NWExY2IwZjA1YzJiN2Y3ZjFlZTFiOTU2NTY5YzE5ZGU0Y2Q3ODI4
10
+ YzQ0MDExNjZlODExMTAwM2FjOWQyOWU5NDg1YjA0MmYzYTkzYmUxOTQ4MTUw
11
+ NTVlNjhiOWRmZTliYmEwZjk5OTQzYTBiODc0YTk0YzVlMTAxNDU=
12
12
  data.tar.gz: !binary |-
13
- YjcxOWU0OWIyZjZjNzEwN2JiNjhiMDdhZTQ2NThkN2ViOTFlOWIzMjY4ODlj
14
- YzQ0MmU2Yjg1NGYwZDRiNWIwZDQ3NTdmMmQ1M2QzMzNiZWFjMmZkZmYwNmNk
15
- ZjBjYTY5YTRmMjQ0ZDg2YjNiOTc0MmM5MjI4ODIyZjFhYzBmNGM=
13
+ ZmQ0MTVjMTBmMjE0NmMwMjY4OTE2M2MyNzYzZGQ5MzVlZWQ4YWMwOTUwYjY1
14
+ NzNhMTBmY2ZjMTEwOTljNTBiYThkNGU0MTU4MTUxNjBiNjZiZWJjNjgwNjdj
15
+ YmRlYmU1N2Q0NjZlMGMwZmU5YTk4MTBiZDgxYzVmZWYyN2Q1MTc=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.3.1
1
+ 0.8.0.1
data/lib/mudbug.rb CHANGED
@@ -116,15 +116,16 @@ class Mudbug
116
116
  path = "/#{path}" unless path[0,1] == '/'
117
117
  url = "http://#{@host}#{path}"
118
118
  end
119
- RestClient::Resource.new url, @options.merge(options)
119
+ RestClient::Resource.new(url, merge(options))
120
120
  end
121
121
 
122
122
  # no payload
123
123
  #
124
124
  [:get, :delete].each { |meth|
125
- define_method(meth) { |path, options = {}|
126
- res = resource(path, options)
127
- self.class.process(res.send(meth), res.headers[:accept])
125
+ define_method(meth) { |path, params = {}|
126
+ res = resource(path)
127
+ resp = res.send(meth, params: params)
128
+ self.class.process(resp, res.headers[:accept])
128
129
  }
129
130
  }
130
131
 
@@ -133,11 +134,26 @@ class Mudbug
133
134
  # otherwise apply #to_json to payload automatically. Quack.
134
135
  #
135
136
  [:post, :put].each { |meth|
136
- define_method(meth) { |path, payload, options={}|
137
- options[:content_type] ||= CONTENT[:json][:type]
137
+ define_method(meth) { |path, payload, params = {}|
138
138
  payload = payload.to_json unless payload.is_a?(String)
139
- res = resource(path, options)
140
- self.class.process(res.send(meth, payload), res.headers[:accept])
139
+ res = resource(path, content_type: CONTENT[:json][:type])
140
+ resp = res.send(meth, payload, params: params)
141
+ self.class.process(resp, res.headers[:accept])
141
142
  }
142
143
  }
144
+
145
+ # a standard merge would throw away @options[:headers][:accept], if
146
+ # options[:headers] is provided. Handle nested hashes while still allowing
147
+ # @options to be overridden
148
+ #
149
+ def merge(options)
150
+ # gah, let's go ahead and do this for all nested hashes we maintain
151
+ result = options.merge({}) # work on a copy, TODO: better way (not dup)
152
+ @options.each { |key, hsh|
153
+ if result[key] and result[key].is_a?(Hash) and hsh.is_a?(Hash)
154
+ result[key] = hsh.merge(result[key])
155
+ end
156
+ }
157
+ result
158
+ end
143
159
  end
data/test/mudbug.rb CHANGED
@@ -3,9 +3,35 @@ require 'minitest/autorun'
3
3
 
4
4
  require_relative '../lib/mudbug'
5
5
 
6
- describe "Rick" do
7
- it "should be embarassed" do
8
- # flunk
9
- skip # for now, since testing is on the critical path :/
6
+ describe "Mudbug#merge" do
7
+ it "should maintain 2nd-level nested hash keys" do
8
+ m = Mudbug.new
9
+ m.options[:headers].must_be_instance_of Hash
10
+ m.options[:headers][:accept].must_be_instance_of String
11
+ default_accept = m.options[:headers][:accept]
12
+
13
+ options = m.merge(headers: {})
14
+ options[:headers].must_be_instance_of Hash
15
+ options[:headers][:accept].must_equal default_accept
16
+
17
+ options = m.merge(headers: { accept: '12345' })
18
+ options[:headers].must_be_instance_of Hash
19
+ options[:headers][:accept].must_equal '12345'
20
+
21
+ distinct = { headers: { xmadeup: '12345' }, max_redirects: 5 }
22
+ options = m.merge(distinct)
23
+ options[:headers].must_be_instance_of Hash
24
+ options[:headers][:accept].must_equal default_accept
25
+
26
+ # make sure the outside hash takes precedence
27
+ distinct.each { |key, val|
28
+ if val.is_a?(Hash)
29
+ val.each { |key2, val2|
30
+ options[key][key2].must_equal val2
31
+ }
32
+ else
33
+ options[key].must_equal val
34
+ end
35
+ }
10
36
  end
11
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mudbug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3.1
4
+ version: 0.8.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Hull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-09 00:00:00.000000000 Z
11
+ date: 2013-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client