garage_client 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 648321b65499a513c8305e6aac962afb10bf99f6
4
- data.tar.gz: 17c99e87555fadc63de66ac384d09a354feeb00b
3
+ metadata.gz: 394abb9093e09a4a7d79452fc44c20792d66485b
4
+ data.tar.gz: 6bb87e45add606d55241e3bc90c56cb0ad176800
5
5
  SHA512:
6
- metadata.gz: dc3e8ea2288e52f6ec2e9d9ef1b9f92318478ea543852cf77706ca53665f20d5d63e6445d88496ad0a415733772241addb8a67ffc4529e54415883ccab20e6d4
7
- data.tar.gz: 57c200a989fc68dcd096ced3dc853ca92eb4d03246e2d26afec236c60fd3d06332d284ed642723b8f3e396b3f6fd643f15c0e0c105ba275579009ea347d006a6
6
+ metadata.gz: 7419abf0acb63420fb45c5ac28c10f3161846159889f85568801845c3cfe56002851525f21f3df3d0d1a09355dd8aa2ac9a343f1478f4159be6a82ee7d428595
7
+ data.tar.gz: da747820a31de77ee57195c2bb119e04fe30506a4f906ea05f4858b3c410bd4b08e8b832d174efc439d01139ffa223c8f9321ced332c9b1dd957f9e8e0003b33
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - ruby-head
5
+ - 2.2
6
+ - 2.1
7
+ - 2.0.0
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: "ruby-head"
11
+ fast_finish: true
12
+
13
+ cache: bundler
14
+
15
+ sudo: false
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # GarageClient
1
+ # GarageClient [![Build Status](https://travis-ci.org/cookpad/garage_client.svg?branch=master)](https://travis-ci.org/cookpad/garage_client)
2
2
  GarageClient is a simple Ruby library to provide a primitive client interface to the Garage application API.
3
3
 
4
4
  ## Install
@@ -7,20 +7,27 @@ module GarageClient
7
7
  end
8
8
 
9
9
  def call
10
- response = read_from_cache? && store.read(key, options) || yield
11
- store.write(key, response, options) if written_to_cache?
10
+ response = store.read(key, options) if read_from_cache?
11
+ if response
12
+ # Faraday::Response#marshal_dump is drop request object and url
13
+ # https://github.com/lostisland/faraday/blob/edacd5eb57ea13accab3097649690ae5f48f421a/lib/faraday/response.rb#L74
14
+ response.env.merge!(@env) {|_, self_val, other_val| self_val || other_val }
15
+ else
16
+ response = yield
17
+ store.write(key, response, options) if written_to_cache?
18
+ end
12
19
  response
13
20
  end
14
21
 
15
22
  private
16
23
 
17
24
  # Return boolean to tell if we need to cache the response or not.
18
- def allowed_to_read_cache?
25
+ def read_from_cache?
19
26
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
20
27
  end
21
28
 
22
29
  # Return boolean to tell if we can try to check cache or not.
23
- def allowed_to_write_cache?
30
+ def written_to_cache?
24
31
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
25
32
  end
26
33
 
@@ -4,7 +4,7 @@ module GarageClient
4
4
 
5
5
  def self.property(key)
6
6
  define_method(key) do
7
- options.fetch(key, GarageClient.configuration.send(key))
7
+ options.fetch(key) { GarageClient.configuration.send(key) }
8
8
  end
9
9
 
10
10
  define_method("#{key}=") do |value|
@@ -1,3 +1,3 @@
1
1
  module GarageClient
2
- VERSION = '2.1.1'
2
+ VERSION = '2.1.2'
3
3
  end
@@ -0,0 +1,54 @@
1
+ U:Faraday::Response{: statusi�: bodyI"�{
2
+ "id": 1,
3
+ "created": "2000-01-01T00:00:00+09:00",
4
+ "updated": "2000-01-01T00:00:00+09:00",
5
+ "name": "recipe title",
6
+ "url": "http://example.com/examples/1",
7
+ "user": {
8
+ "id": 2294,
9
+ "url": "http://example.com/kitchen/2294",
10
+ "name": "Fern1",
11
+ "_links": {
12
+ "self": {
13
+ "href": "/v1/users/2294"
14
+ },
15
+ "bookmarks": {
16
+ "href": "/v1/users/2294/bookmarks"
17
+ },
18
+ "bookmark_tags": {
19
+ "href": "/v1/users/2294/bookmark_tags"
20
+ },
21
+ "canonical": {
22
+ "href": "/v1/users/2294"
23
+ },
24
+ "diary_entries": {
25
+ "href": "/v1/users/2294/diary_entries"
26
+ },
27
+ "feedbacks": {
28
+ "href": "/v1/users/2294/feedbacks"
29
+ },
30
+ "recipes": {
31
+ "href": "/v1/users/2294/recipes"
32
+ }
33
+ }
34
+ },
35
+ "description": "this is my favorite recipe.",
36
+ "serving": null,
37
+ "published": "2000-01-01T00:00:00+09:00",
38
+ "edited": null,
39
+ "tier": "example.com:User",
40
+ "ingredients": [],
41
+ "steps": [],
42
+ "_links": {
43
+ "self": {
44
+ "href": "/examples/1"
45
+ },
46
+ "canonical": {
47
+ "href": "/examples/1"
48
+ },
49
+ "nested_examples": {
50
+ "href": "/examples/1/nested_examples"
51
+ }
52
+ }
53
+ }
54
+ :ET:response_headersIC:Faraday::Utils::Headers{I"content-type;TI"$application/json; charset=utf-8;T: @names{I"content-type;T@
@@ -0,0 +1,54 @@
1
+ U:Faraday::Response{: statusi�: bodyI"�{
2
+ "id": 1,
3
+ "created": "2000-01-01T00:00:00+09:00",
4
+ "updated": "2000-01-01T00:00:00+09:00",
5
+ "name": "recipe title",
6
+ "url": "http://example.com/examples/1",
7
+ "user": {
8
+ "id": 2294,
9
+ "url": "http://example.com/kitchen/2294",
10
+ "name": "Fern1",
11
+ "_links": {
12
+ "self": {
13
+ "href": "/v1/users/2294"
14
+ },
15
+ "bookmarks": {
16
+ "href": "/v1/users/2294/bookmarks"
17
+ },
18
+ "bookmark_tags": {
19
+ "href": "/v1/users/2294/bookmark_tags"
20
+ },
21
+ "canonical": {
22
+ "href": "/v1/users/2294"
23
+ },
24
+ "diary_entries": {
25
+ "href": "/v1/users/2294/diary_entries"
26
+ },
27
+ "feedbacks": {
28
+ "href": "/v1/users/2294/feedbacks"
29
+ },
30
+ "recipes": {
31
+ "href": "/v1/users/2294/recipes"
32
+ }
33
+ }
34
+ },
35
+ "description": "this is my favorite recipe.",
36
+ "serving": null,
37
+ "published": "2000-01-01T00:00:00+09:00",
38
+ "edited": null,
39
+ "tier": "example.com:User",
40
+ "ingredients": [],
41
+ "steps": [],
42
+ "_links": {
43
+ "self": {
44
+ "href": "/examples/1"
45
+ },
46
+ "canonical": {
47
+ "href": "/examples/1"
48
+ },
49
+ "nested_examples": {
50
+ "href": "/examples/1/nested_examples"
51
+ }
52
+ }
53
+ }
54
+ :ET:response_headersIC:Faraday::Utils::Headers{I"content-type;TI"$application/json; charset=utf-8;T: @names{I"content-type;T@
@@ -1,13 +1,34 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe GarageClient::Cachers::Base do
4
- let(:client) do
5
- GarageClient::Client.new(cacher: cacher_class)
4
+ let(:store) do
5
+ Class.new do
6
+ def initialize
7
+ @table = {}
8
+ end
9
+
10
+ def read(key, options = {})
11
+ value = @table[key]
12
+ Marshal.load(value) if value
13
+ end
14
+
15
+ def write(key, value, options = {})
16
+ @table[key] = Marshal.dump(value)
17
+ end
18
+ end.new
6
19
  end
7
20
 
8
21
  let(:cacher_class) do
9
- store = store
22
+ cache_store = store
10
23
  Class.new(GarageClient::Cachers::Base) do
24
+ @store = cache_store
25
+
26
+ class << self
27
+ attr_reader :store
28
+ end
29
+
30
+ delegate :store, to: :class
31
+
11
32
  private
12
33
 
13
34
  def key
@@ -21,30 +42,18 @@ describe GarageClient::Cachers::Base do
21
42
  def written_to_cache?
22
43
  true
23
44
  end
24
-
25
- def store
26
- Class.new do
27
- def initialize
28
- @table = {}
29
- end
30
-
31
- def read(key, options = {})
32
- @table[key]
33
- end
34
-
35
- def write(key, value, options = {})
36
- @table[key] = value
37
- end
38
- end.new
39
- end
40
45
  end
41
46
  end
42
47
 
48
+ let(:client) do
49
+ GarageClient::Client.new(cacher: cacher_class)
50
+ end
51
+
43
52
  describe "caching" do
44
53
  context "with cache-enabled GarageClient::Client" do
45
54
  it "caches response along passed cacher class" do
46
- stub_get("/examples").to_return(fixture("examples.yaml")).times(1)
47
- stub_get("/example").to_return(fixture("example.yaml")).times(1)
55
+ stub_get("/examples").to_return(fixture("examples.yaml")).times(1).then.to_raise("Not use Cache.")
56
+ stub_get("/example").to_return(fixture("example.yaml")).times(1).then.to_raise("Not use Cache.")
48
57
  client.get("/examples").body.should be_a Array
49
58
  client.get("/examples").body.should be_a Array
50
59
  client.get("/example").body.should be_a GarageClient::Resource
@@ -52,4 +61,33 @@ describe GarageClient::Cachers::Base do
52
61
  end
53
62
  end
54
63
  end
64
+
65
+ # Check dump data. Because cache data not broken on the version up of faraday.
66
+ describe "check Faraday::Response marshal" do
67
+ specify do
68
+ expect(Faraday::VERSION).to be < "1.0.0", "This spec is no longer needed. Delete this 'describe' section!"
69
+ end
70
+
71
+ context "v0.9.1's marshal data" do
72
+ let(:res) do
73
+ Marshal.load(File.read(File.expand_path('../fixtures/faraday_0.9.1_response.dump', __dir__)))
74
+ end
75
+
76
+ it "load data" do
77
+ expect(res).to be_instance_of Faraday::Response
78
+ expect(res.env[:body]).to eq fixture("example.yaml")[:body]
79
+ end
80
+ end
81
+
82
+ context "v0.8.9's marshal data" do
83
+ let(:res) do
84
+ Marshal.load(File.read(File.expand_path('../fixtures/faraday_0.8.9_response.dump', __dir__)))
85
+ end
86
+
87
+ it "load data" do
88
+ expect(res).to be_instance_of Faraday::Response
89
+ expect(res.env[:body]).to eq fixture("example.yaml")[:body]
90
+ end
91
+ end
92
+ end
55
93
  end
@@ -4,6 +4,24 @@ describe GarageClient::Client do
4
4
  let(:client) { GarageClient::Client.new(options) }
5
5
  let(:options) { {} }
6
6
 
7
+ describe 'laziness of properties' do
8
+ before { allow(GarageClient.configuration).to receive(:endpoint).and_raise('error') }
9
+
10
+ context 'when is specified options' do
11
+ let(:options) { { endpoint: 'http://example.com' } }
12
+
13
+ it 'does not evaluate global configuration' do
14
+ expect { client.endpoint }.not_to raise_error
15
+ end
16
+ end
17
+
18
+ context 'when is not specified options' do
19
+ it 'evaluates global configuration' do
20
+ expect { client.endpoint }.to raise_error('error')
21
+ end
22
+ end
23
+ end
24
+
7
25
  describe "#adapter" do
8
26
  context "without :adapter option value" do
9
27
  it "returns default value" do
@@ -135,8 +153,8 @@ describe GarageClient::Client do
135
153
 
136
154
  describe "#endpoint=" do
137
155
  it "overwrites it" do
138
- client.adapter = "http://example.com"
139
- client.adapter.should == "http://example.com"
156
+ client.endpoint = "http://example.com"
157
+ client.endpoint.should == "http://example.com"
140
158
  end
141
159
  end
142
160
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: garage_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cookpad Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-25 00:00:00.000000000 Z
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -201,6 +201,7 @@ extra_rdoc_files: []
201
201
  files:
202
202
  - ".gitignore"
203
203
  - ".rspec"
204
+ - ".travis.yml"
204
205
  - CHANGELOG.md
205
206
  - Gemfile
206
207
  - Guardfile
@@ -226,6 +227,8 @@ files:
226
227
  - spec/fixtures/examples.yaml
227
228
  - spec/fixtures/examples_dictionary.yaml
228
229
  - spec/fixtures/examples_without_pagination.yaml
230
+ - spec/fixtures/faraday_0.8.9_response.dump
231
+ - spec/fixtures/faraday_0.9.1_response.dump
229
232
  - spec/garage_client/cacher_spec.rb
230
233
  - spec/garage_client/client_spec.rb
231
234
  - spec/garage_client/configuration_spec.rb
@@ -254,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
257
  version: '0'
255
258
  requirements: []
256
259
  rubyforge_project:
257
- rubygems_version: 2.2.2
260
+ rubygems_version: 2.4.5
258
261
  signing_key:
259
262
  specification_version: 4
260
263
  summary: Ruby client library for the Garage API
@@ -264,6 +267,8 @@ test_files:
264
267
  - spec/fixtures/examples.yaml
265
268
  - spec/fixtures/examples_dictionary.yaml
266
269
  - spec/fixtures/examples_without_pagination.yaml
270
+ - spec/fixtures/faraday_0.8.9_response.dump
271
+ - spec/fixtures/faraday_0.9.1_response.dump
267
272
  - spec/garage_client/cacher_spec.rb
268
273
  - spec/garage_client/client_spec.rb
269
274
  - spec/garage_client/configuration_spec.rb