stretchr 1.3.1 → 1.3.2

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: 8e5b8e89dbf9d5bf8df7927c8f871b03af916b64
4
- data.tar.gz: cf85a4a1530398710152a48e13b209b5bc6423bb
3
+ metadata.gz: f5ed062936791748c65cef6341361551120e5083
4
+ data.tar.gz: af8ed81ecfcb1bcb2e49ee4e598a6160969c8cd2
5
5
  SHA512:
6
- metadata.gz: e16c6f1fe0b43049f6c0b0bfb0bb7152fb63fc6bd5951c5ec004132f00151bb085b36b28450980835bf29f85dc0557a93cbc1163deb48d01b7b90bb41dfd383b
7
- data.tar.gz: b497813de26adfe3fc462d6786f6ab72b50ac3e746fa1097adfd520d5ea61ce4309a3a249b104c0ea360946433795f889838d88c6cd76ed71177954d11640808
6
+ metadata.gz: 1ced73ec60a5bdee90662048481b12510fd753091efeeaee796c6ea5a45cc829c3b9987200e5d055d122b9f4d5043f89669569c8437b4dc474632ba4f700ba8c
7
+ data.tar.gz: 38eba9401d33aad6937994d3f0f09c3df00696d720dd1d8aa0a9cec33bc77660056317b8ded71eb4b7b5e671e2aa953c94b2eda40b39bfc7ea7138a3bc61bce3
data/lib/stretchr/bag.rb CHANGED
@@ -19,9 +19,15 @@ module Stretchr
19
19
  # s = Stretchr::Bag.new
20
20
  # s.set("key", "value")
21
21
  # s.get("key") #=> "value"
22
- def set(param, value)
23
- param = "#{@prefix}#{param}" if @prefix
24
- @params[param] = value
22
+ def set(param, value = nil)
23
+ if param.is_a?(Hash)
24
+ param.each_pair do |k, v|
25
+ set(k, v)
26
+ end
27
+ else
28
+ param = "#{@prefix}#{param}" if @prefix
29
+ @params[param.to_s] = value unless value == nil
30
+ end
25
31
  end
26
32
 
27
33
  # Get will retrieve a stored value
@@ -34,7 +40,7 @@ module Stretchr
34
40
  # s.get("key") #=> "value"
35
41
  def get(param)
36
42
  param = "#{@prefix}#{param}" if @prefix
37
- @params[param]
43
+ @params[param.to_s]
38
44
  end
39
45
 
40
46
  # Returns a url encoded query string of the current stored
@@ -40,7 +40,7 @@ module Stretchr
40
40
  # ==== Examples
41
41
  # r = Stretchr::Request.new
42
42
  # r.param("key", "value")
43
- def param(key, value)
43
+ def param(key, value = nil)
44
44
  @params.set(key, value)
45
45
  return self
46
46
  end
@@ -50,7 +50,7 @@ module Stretchr
50
50
  # ==== Examples
51
51
  # r = Stretchr::Request.new
52
52
  # r.where("key", "value")
53
- def where(key, value)
53
+ def where(key, value = nil)
54
54
  @filters.set(key, value)
55
55
  return self
56
56
  end
data/test/test_bag.rb CHANGED
@@ -20,4 +20,19 @@ describe "Param Bag" do
20
20
  assert_equal "21", b.get("age"), "Should have set the age"
21
21
  assert_equal ":age=21", URI.decode(b.query_string), "Should have added a prefix to the bag"
22
22
  end
23
+
24
+ it "Should let me pass in a hash of parameters" do
25
+ b = Stretchr::Bag.new
26
+ b.set({name: "ryan", age: 26})
27
+ assert_equal "ryan", b.get("name"), "should have set the name"
28
+ assert_equal 26, b.get("age"), "should have set the age"
29
+ end
30
+
31
+ it "Shouldn't care about symbols and strings" do
32
+ b = Stretchr::Bag.new
33
+ b.set("name", "ryan")
34
+ b.set(:age, 21)
35
+ assert_equal "ryan", b.get(:name), "Shouldn't have cared"
36
+ assert_equal 21, b.get("age"), "shouldn't have cared"
37
+ end
23
38
  end
data/test/test_request.rb CHANGED
@@ -29,6 +29,15 @@ describe "Request Object" do
29
29
  assert_equal "asdf2", uri.get_param("key2").first, "Should have set key2"
30
30
  end
31
31
 
32
+ it "should let you pass in a hash of params" do
33
+ c = Stretchr::Client.new({project: "project", api_version: "v1.1"})
34
+ r = Stretchr::Request.new({client: c})
35
+ r.param({"key1" => "asdf", "key2" => "asdf2"})
36
+ uri = r.to_uri
37
+ assert_equal "asdf", uri.get_param("key1").first, "should have set key"
38
+ assert_equal "asdf2", uri.get_param("key2").first, "Should have set key2"
39
+ end
40
+
32
41
  it "should let you add filters" do
33
42
  c = Stretchr::Client.new({project: "project", api_version: "v1.1"})
34
43
  r = Stretchr::Request.new({client: c})
@@ -44,6 +53,14 @@ describe "Request Object" do
44
53
  assert_equal [">21", "<40"], r.to_uri.get_param(":age"), "Should have added multiple ages"
45
54
  end
46
55
 
56
+ it "Should let you add hash of filters" do
57
+ c = Stretchr::Client.new({project: "project", api_version: "v1.1"})
58
+ r = Stretchr::Request.new({client: c})
59
+ r.where({name: "ryan", age: 26})
60
+ assert_equal ["ryan"], r.to_uri.get_param(":name"), "Should have saved both params"
61
+ assert_equal ["26"], r.to_uri.get_param(":age"), "Should have saved both params"
62
+ end
63
+
47
64
  it "Should let you get objects" do
48
65
  t = Stretchr::TestTransporter.new
49
66
  c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stretchr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Quinn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-22 00:00:00.000000000 Z
11
+ date: 2014-02-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A gem for interacting with your stretchr data
14
14
  email: ryan@mazondo.com