acfs 0.50.0 → 1.0.0.dev.1.b297
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/CHANGELOG.md +0 -80
- data/README.md +9 -8
- data/acfs.gemspec +7 -7
- data/lib/acfs.rb +5 -7
- data/lib/acfs/adapter/base.rb +2 -0
- data/lib/acfs/adapter/typhoeus.rb +13 -17
- data/lib/acfs/collections/paginatable.rb +10 -10
- data/lib/acfs/configuration.rb +5 -4
- data/lib/acfs/errors.rb +9 -10
- data/lib/acfs/global.rb +7 -16
- data/lib/acfs/location.rb +11 -11
- data/lib/acfs/middleware/base.rb +2 -1
- data/lib/acfs/middleware/json_decoder.rb +16 -0
- data/lib/acfs/middleware/json_encoder.rb +20 -0
- data/lib/acfs/middleware/logger.rb +2 -0
- data/lib/acfs/middleware/msgpack_decoder.rb +26 -0
- data/lib/acfs/middleware/msgpack_encoder.rb +19 -0
- data/lib/acfs/middleware/print.rb +2 -0
- data/lib/acfs/operation.rb +5 -5
- data/lib/acfs/request.rb +4 -4
- data/lib/acfs/request/callbacks.rb +3 -2
- data/lib/acfs/resource.rb +2 -2
- data/lib/acfs/resource/attributes.rb +38 -11
- data/lib/acfs/resource/attributes/base.rb +19 -10
- data/lib/acfs/resource/attributes/boolean.rb +8 -10
- data/lib/acfs/resource/attributes/date_time.rb +9 -6
- data/lib/acfs/resource/attributes/float.rb +5 -11
- data/lib/acfs/resource/attributes/integer.rb +5 -7
- data/lib/acfs/resource/attributes/list.rb +6 -13
- data/lib/acfs/resource/attributes/string.rb +5 -3
- data/lib/acfs/resource/attributes/uuid.rb +17 -8
- data/lib/acfs/resource/dirty.rb +15 -3
- data/lib/acfs/resource/loadable.rb +1 -0
- data/lib/acfs/resource/locatable.rb +4 -0
- data/lib/acfs/resource/operational.rb +2 -0
- data/lib/acfs/resource/persistence.rb +17 -17
- data/lib/acfs/resource/query_methods.rb +7 -8
- data/lib/acfs/resource/service.rb +2 -0
- data/lib/acfs/resource/validation.rb +4 -4
- data/lib/acfs/response.rb +2 -1
- data/lib/acfs/response/formats.rb +3 -2
- data/lib/acfs/response/status.rb +5 -3
- data/lib/acfs/runner.rb +11 -21
- data/lib/acfs/service.rb +6 -4
- data/lib/acfs/service/middleware.rb +30 -20
- data/lib/acfs/singleton_resource.rb +2 -0
- data/lib/acfs/stub.rb +21 -30
- data/lib/acfs/util.rb +1 -1
- data/lib/acfs/version.rb +4 -6
- data/spec/acfs/adapter/typhoeus_spec.rb +4 -12
- data/spec/acfs/collection_spec.rb +33 -45
- data/spec/acfs/configuration_spec.rb +1 -9
- data/spec/acfs/global_spec.rb +3 -21
- data/spec/acfs/middleware/json_decoder_spec.rb +45 -0
- data/spec/acfs/middleware/msgpack_decoder_spec.rb +36 -0
- data/spec/acfs/request/callbacks_spec.rb +8 -8
- data/spec/acfs/request_spec.rb +5 -5
- data/spec/acfs/resource/attributes/boolean_spec.rb +9 -40
- data/spec/acfs/resource/attributes/date_time_spec.rb +35 -29
- data/spec/acfs/resource/attributes/float_spec.rb +9 -48
- data/spec/acfs/resource/attributes/list_spec.rb +19 -43
- data/spec/acfs/resource/attributes/uuid_spec.rb +54 -31
- data/spec/acfs/resource/attributes_spec.rb +31 -17
- data/spec/acfs/resource/locatable_spec.rb +2 -2
- data/spec/acfs/resource/persistance_spec.rb +34 -65
- data/spec/acfs/resource/query_methods_spec.rb +90 -97
- data/spec/acfs/resource/validation_spec.rb +5 -4
- data/spec/acfs/response/formats_spec.rb +4 -4
- data/spec/acfs/response/status_spec.rb +1 -1
- data/spec/acfs/runner_spec.rb +3 -28
- data/spec/acfs/service/middleware_spec.rb +20 -4
- data/spec/acfs/service_spec.rb +5 -3
- data/spec/acfs/singleton_resource_spec.rb +2 -1
- data/spec/acfs/stub_spec.rb +22 -137
- data/spec/acfs_spec.rb +19 -22
- data/spec/spec_helper.rb +2 -3
- data/spec/support/service.rb +6 -10
- data/spec/support/shared/find_callbacks.rb +7 -7
- metadata +36 -43
- data/lib/acfs/middleware/json.rb +0 -27
- data/lib/acfs/middleware/msgpack.rb +0 -30
- data/lib/acfs/middleware/serializer.rb +0 -39
- data/lib/acfs/resource/attributes/dict.rb +0 -37
- data/lib/acfs/service/middleware/stack.rb +0 -63
- data/spec/acfs/middleware/json_spec.rb +0 -63
- data/spec/acfs/middleware/msgpack_spec.rb +0 -60
- data/spec/acfs/operation_spec.rb +0 -10
- data/spec/acfs/resource/attributes/dict_spec.rb +0 -75
- data/spec/acfs/resource/attributes/integer_spec.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OTZhZGMyZGMzM2UzYjJmODU1MDU3NGU1MmVkYTQ5MTQxZDUwYTI5ZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NGZhODhiOTY5MTc5M2QxNDMxYjFmYjA3MjVmMTA4ZGM0OGZjZWJkYw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Y2JkMDFjOTE0NDhjOGJkNDY1ZjIwMjgwMDg1ZmY2ZDRmNzc5NTk2MDhlZDA0
|
10
|
+
MDU5OWJhY2I1MDUyNmQ0MjBjYWZmZjcwZDEwNTIwNWJlMmI2YjZjOWU1YTJk
|
11
|
+
ODU3YzQ3NjFkZjlkZDA3YTlhOWE1MmZlYjk4M2U3MTM3ZjBjZmI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjY3YWI3MGYzMGQxNTljZTNkYWQzMjYxMjcxYTlhNTcyODFmNDJhZjg5Yzk2
|
14
|
+
NjIxZmQyM2MwYTZkNTdmYWM1NTdiN2JkZjYwMzg5ZTYwMzIyODk3MzdiYzli
|
15
|
+
MzI0MDJjMDgzMDcwOWJjZTI2YWIyOGFhMWQ3ZTIxNTU3M2QyZWU=
|
data/CHANGELOG.md
CHANGED
@@ -1,85 +1,5 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 1.2.0
|
4
|
-
|
5
|
-
* Add Rails 5.2 compatibility
|
6
|
-
|
7
|
-
## 1.1.1
|
8
|
-
|
9
|
-
* `each_item`: Pass collection to provided block (#40)
|
10
|
-
|
11
|
-
## 1.1.0
|
12
|
-
|
13
|
-
* Add support for Rails 5.1
|
14
|
-
|
15
|
-
## 1.0.1
|
16
|
-
|
17
|
-
* Fix deprecation warnings when using ::Mime
|
18
|
-
|
19
|
-
## 1.0.0
|
20
|
-
|
21
|
-
* Switch to first non-development major as it's long time used in production.
|
22
|
-
* Fix NewRelic RPM inference with middleware stack inherited from `ActionDispatch::MiddlewareStack`.
|
23
|
-
|
24
|
-
## 0.48.0
|
25
|
-
|
26
|
-
* Remove #attribute_types broke since f7e4109 (Sep 2013, v0.23)
|
27
|
-
* Fix attribute inheritance on subclassing broken since commit 7cf1d11 (Apr 2014, v0.43)
|
28
|
-
|
29
|
-
## 0.47.0
|
30
|
-
|
31
|
-
* Change blank value handling of dict and list type (0a12ef1)
|
32
|
-
|
33
|
-
## 0.46.0
|
34
|
-
|
35
|
-
* Rework types system (#39)
|
36
|
-
|
37
|
-
## 0.45.0
|
38
|
-
|
39
|
-
* Fetching multiple records (`find(ary)`) is stable now, but untested (#38)
|
40
|
-
* Middleware stack is build on ActionDispatch::MiddlewareStack now
|
41
|
-
* Deprecate legacy middleware names (xyEncoder, xyDecoder)
|
42
|
-
|
43
|
-
## 0.44.0
|
44
|
-
|
45
|
-
* Add option to configure adapter creation and pass option to typhoeus adapter e.g.
|
46
|
-
limiting concurrency.
|
47
|
-
|
48
|
-
## 0.43.2
|
49
|
-
|
50
|
-
* add `total_count` for paginated collections
|
51
|
-
|
52
|
-
## 0.43.1
|
53
|
-
|
54
|
-
* Fix `:with` condition matching on stubs
|
55
|
-
|
56
|
-
## 0.43.0
|
57
|
-
|
58
|
-
* Remove `Acfs::Model` (inherit from `Acfs::Resource`)
|
59
|
-
* Stub does only a partial match of `:with` attributes now
|
60
|
-
* Allow blocks as stub `:return`s
|
61
|
-
|
62
|
-
## 0.42.0
|
63
|
-
|
64
|
-
* Add simple dict attribute type
|
65
|
-
|
66
|
-
## 0.40.0
|
67
|
-
|
68
|
-
* Change `Resource#persisted?` to return true if it is not new
|
69
|
-
|
70
|
-
## 0.39.1
|
71
|
-
|
72
|
-
* Fix automatic path parameter handling for #destroy
|
73
|
-
|
74
|
-
## 0.39.0
|
75
|
-
|
76
|
-
* Add new event acfs.operation.before_process
|
77
|
-
|
78
|
-
## 0.38.0
|
79
|
-
|
80
|
-
* Allow middlewares to abort request processing
|
81
|
-
* Allow middlewares to receive the request operation object (via the request)
|
82
|
-
|
83
3
|
## 0.37.0
|
84
4
|
|
85
5
|
* Add Acfs.on
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Acfs - *API client for services*
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/acfs.
|
4
|
-
[![Build Status](
|
5
|
-
[![Coverage Status](
|
6
|
-
[![Code Climate](
|
7
|
-
[![Dependency Status](
|
8
|
-
[![RubyDoc Documentation](http://
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/acfs.png)](http://badge.fury.io/rb/acfs)
|
4
|
+
[![Build Status](https://travis-ci.org/jgraichen/acfs.png?branch=master)](https://travis-ci.org/jgraichen/acfs)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/jgraichen/acfs/badge.png?branch=master)](https://coveralls.io/r/jgraichen/acfs)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/jgraichen/acfs.png)](https://codeclimate.com/github/jgraichen/acfs)
|
7
|
+
[![Dependency Status](https://gemnasium.com/jgraichen/acfs.png)](https://gemnasium.com/jgraichen/acfs)
|
8
|
+
[![RubyDoc Documentation](http://b.repl.ca/v1/rubydoc-here-blue.png)](http://rubydoc.info/github/jgraichen/acfs/master/frames)
|
9
9
|
|
10
10
|
Acfs is a library to develop API client libraries for single services within a larger service oriented application.
|
11
11
|
|
@@ -250,8 +250,8 @@ it 'should find user number one' do
|
|
250
250
|
expect(user.name).to be == 'John Smith'
|
251
251
|
expect(user.age).to be == 32
|
252
252
|
|
253
|
-
expect(@stub).to
|
254
|
-
expect(@stub).to_not
|
253
|
+
expect(@stub).to has_called
|
254
|
+
expect(@stub).to_not have_called 5.times
|
255
255
|
end
|
256
256
|
|
257
257
|
it 'should not find user number two' do
|
@@ -313,6 +313,7 @@ Read [official guide][2] to see to to subscribe.
|
|
313
313
|
* Reusing model definitions for generating responses?
|
314
314
|
* Rails responders providing REST operations with integrated ETag,
|
315
315
|
Modified Headers, conflict detection, ...
|
316
|
+
* Pagination? Filtering? (If service API provides such features.)
|
316
317
|
* Documentation
|
317
318
|
|
318
319
|
## Contributing
|
data/acfs.gemspec
CHANGED
@@ -8,23 +8,23 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Acfs::VERSION
|
9
9
|
spec.authors = ['Jan Graichen']
|
10
10
|
spec.email = %w(jg@altimos.de)
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
11
|
+
spec.description = %q{API Client For Services}
|
12
|
+
spec.summary = %q{An abstract API base client for service oriented application.}
|
13
13
|
spec.homepage = 'https://github.com/jgraichen/acfs'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = Dir['**/*'].grep(%r{^((bin|lib|test|spec|features)/|.*\.gemspec|.*LICENSE.*|.*README.*|.*CHANGELOG.*)})
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = %w(lib)
|
20
20
|
|
21
|
-
spec.add_runtime_dependency 'activesupport', '>=
|
22
|
-
spec.add_runtime_dependency 'activemodel', '>=
|
23
|
-
spec.add_runtime_dependency 'actionpack', '>=
|
21
|
+
spec.add_runtime_dependency 'activesupport', '>= 3.1'
|
22
|
+
spec.add_runtime_dependency 'activemodel', '>= 3.1'
|
23
|
+
spec.add_runtime_dependency 'actionpack', '>= 3.1'
|
24
24
|
spec.add_runtime_dependency 'multi_json'
|
25
25
|
|
26
26
|
# Bundle update w/o version resolves to 0.3.3 ...
|
27
|
-
spec.add_runtime_dependency 'typhoeus', '
|
27
|
+
spec.add_runtime_dependency 'typhoeus', '>= 0.6.5'
|
28
28
|
|
29
29
|
spec.add_runtime_dependency 'rack'
|
30
30
|
|
data/lib/acfs.rb
CHANGED
@@ -30,16 +30,13 @@ module Acfs
|
|
30
30
|
module Middleware
|
31
31
|
extend ActiveSupport::Autoload
|
32
32
|
require 'acfs/middleware/base'
|
33
|
-
require 'acfs/middleware/serializer'
|
34
33
|
|
35
34
|
autoload :Print
|
36
35
|
autoload :Logger
|
37
|
-
autoload :
|
38
|
-
autoload :
|
39
|
-
autoload :JsonEncoder
|
40
|
-
autoload :
|
41
|
-
autoload :MessagePackDecoder, 'acfs/middleware/msgpack'
|
42
|
-
autoload :MessagePackEncoder, 'acfs/middleware/msgpack'
|
36
|
+
autoload :JsonDecoder
|
37
|
+
autoload :MessagePackDecoder, 'acfs/middleware/msgpack_decoder'
|
38
|
+
autoload :JsonEncoder
|
39
|
+
autoload :MessagePackEncoder, 'acfs/middleware/msgpack_encoder'
|
43
40
|
end
|
44
41
|
|
45
42
|
module Adapter
|
@@ -47,3 +44,4 @@ module Acfs
|
|
47
44
|
require 'acfs/adapter/typhoeus'
|
48
45
|
end
|
49
46
|
end
|
47
|
+
|
data/lib/acfs/adapter/base.rb
CHANGED
@@ -2,12 +2,10 @@ require 'typhoeus'
|
|
2
2
|
|
3
3
|
module Acfs
|
4
4
|
module Adapter
|
5
|
+
|
5
6
|
# Adapter for Typhoeus.
|
6
7
|
#
|
7
8
|
class Typhoeus < Base
|
8
|
-
def initialize(**kwargs)
|
9
|
-
@options = kwargs
|
10
|
-
end
|
11
9
|
|
12
10
|
def start
|
13
11
|
hydra.run
|
@@ -16,7 +14,9 @@ module Acfs
|
|
16
14
|
raise
|
17
15
|
end
|
18
16
|
|
19
|
-
|
17
|
+
def abort
|
18
|
+
hydra.abort
|
19
|
+
end
|
20
20
|
|
21
21
|
def run(request)
|
22
22
|
convert_request(request).run
|
@@ -26,21 +26,17 @@ module Acfs
|
|
26
26
|
hydra.queue convert_request request
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
protected
|
31
30
|
def hydra
|
32
|
-
@hydra ||= ::Typhoeus::Hydra.new
|
31
|
+
@hydra ||= ::Typhoeus::Hydra.new
|
33
32
|
end
|
34
33
|
|
35
34
|
def convert_request(req)
|
36
35
|
request = ::Typhoeus::Request.new req.url,
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
'Transfer-Encoding' => ''
|
42
|
-
),
|
43
|
-
body: req.body
|
36
|
+
method: req.method,
|
37
|
+
params: req.params,
|
38
|
+
headers: req.headers,
|
39
|
+
body: req.body
|
44
40
|
|
45
41
|
request.on_complete do |response|
|
46
42
|
req.complete! convert_response(req, response)
|
@@ -51,9 +47,9 @@ module Acfs
|
|
51
47
|
|
52
48
|
def convert_response(request, response)
|
53
49
|
Acfs::Response.new request,
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
status: response.code,
|
51
|
+
headers: response.headers,
|
52
|
+
body: response.body
|
57
53
|
end
|
58
54
|
end
|
59
55
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module Acfs::Collections
|
2
|
+
|
2
3
|
#
|
3
4
|
module Paginatable
|
4
5
|
extend ActiveSupport::Concern
|
5
6
|
|
6
7
|
included do
|
7
|
-
def self.operation(
|
8
|
+
def self.operation(action, opts = {}, &block)
|
8
9
|
opts[:url]
|
9
10
|
end
|
10
11
|
|
11
|
-
attr_reader :total_pages, :current_page
|
12
|
+
attr_reader :total_pages, :current_page
|
12
13
|
end
|
13
14
|
|
14
15
|
def process_response(response)
|
@@ -33,9 +34,12 @@ module Acfs::Collections
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def page(rel, &block)
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
if relations[rel]
|
38
|
+
@resource_class.all nil, url: relations[rel], &block
|
39
|
+
else
|
40
|
+
# raise ArgumentError.new "No relative page `#{rel}'."
|
41
|
+
nil
|
42
|
+
end
|
39
43
|
end
|
40
44
|
|
41
45
|
private
|
@@ -49,17 +53,13 @@ module Acfs::Collections
|
|
49
53
|
@total_pages = Integer(headers['X-Total-Pages'])
|
50
54
|
end
|
51
55
|
|
52
|
-
if headers['X-Total-Count']
|
53
|
-
@total_count = Integer(headers['X-Total-Count'])
|
54
|
-
end
|
55
|
-
|
56
56
|
setup_links headers['Link'] if headers['Link']
|
57
57
|
end
|
58
58
|
|
59
59
|
def setup_links(links)
|
60
60
|
links.split(/,\s+/).each do |link|
|
61
61
|
if link =~ /^\s*<([^>]+)>.*\s+rel="([\w_-]+)".*$/
|
62
|
-
relations[
|
62
|
+
relations[$2] = $1
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
data/lib/acfs/configuration.rb
CHANGED
@@ -2,11 +2,11 @@ require 'uri'
|
|
2
2
|
require 'yaml'
|
3
3
|
|
4
4
|
module Acfs
|
5
|
+
|
5
6
|
# Acfs configuration is used to locate services and get their base URLs.
|
6
7
|
#
|
7
8
|
class Configuration
|
8
9
|
attr_reader :locations
|
9
|
-
attr_accessor :adapter
|
10
10
|
|
11
11
|
# @api private
|
12
12
|
def initialize
|
@@ -28,7 +28,7 @@ module Acfs
|
|
28
28
|
if block.arity > 0
|
29
29
|
block.call self
|
30
30
|
else
|
31
|
-
instance_eval
|
31
|
+
instance_eval &block
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -64,10 +64,10 @@ module Acfs
|
|
64
64
|
# @return [undefined]
|
65
65
|
#
|
66
66
|
def load(filename)
|
67
|
-
config = YAML
|
67
|
+
config = YAML::load File.read filename
|
68
68
|
env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
|
69
69
|
|
70
|
-
config = config[env] if config.
|
70
|
+
config = config[env] if config.has_key? env
|
71
71
|
config.each do |key, value|
|
72
72
|
case key
|
73
73
|
when 'services' then load_services value
|
@@ -88,6 +88,7 @@ module Acfs
|
|
88
88
|
end
|
89
89
|
|
90
90
|
class << self
|
91
|
+
|
91
92
|
# @api private
|
92
93
|
#
|
93
94
|
# Return current configuration object.
|
data/lib/acfs/errors.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module Acfs
|
2
|
+
|
2
3
|
# Acfs base error.
|
3
4
|
#
|
4
5
|
class Error < StandardError
|
@@ -22,20 +23,20 @@ module Acfs
|
|
22
23
|
message << ": #{response.code}"
|
23
24
|
if response.data
|
24
25
|
message << "\n with content:\n "
|
25
|
-
message << response.data.map
|
26
|
+
message << response.data.map{|k,v| "#{k.inspect}: #{v.inspect}"}.join("\n ")
|
26
27
|
end
|
27
28
|
if response.headers.any?
|
28
29
|
message << "\n with headers:\n "
|
29
|
-
message << response.headers.map
|
30
|
+
message << response.headers.map{|k,v| "#{k}: #{v}"}.join("\n ")
|
30
31
|
end
|
31
32
|
message << "\nbased on request: #{response.request.method.upcase} #{response.request.url} #{response.request.format}"
|
32
33
|
if response.request.data
|
33
34
|
message << "\n with content:\n "
|
34
|
-
message << response.request.data.map
|
35
|
+
message << response.request.data.map{|k,v| "#{k.inspect}: #{v.inspect}"}.join("\n ")
|
35
36
|
end
|
36
37
|
if response.request.headers.any?
|
37
38
|
message << "\n with headers:\n "
|
38
|
-
message << response.request.headers.map
|
39
|
+
message << response.request.headers.map{|k,v| "#{k}: #{v}"}.join("\n ")
|
39
40
|
end
|
40
41
|
end
|
41
42
|
super opts, message
|
@@ -46,14 +47,12 @@ module Acfs
|
|
46
47
|
attr_reader :stubs, :operation
|
47
48
|
|
48
49
|
def initialize(opts = {})
|
49
|
-
require 'pp'
|
50
|
-
|
51
50
|
@stubs = opts.delete :stubs
|
52
51
|
@operation = opts.delete :operation
|
53
52
|
|
54
|
-
super opts,
|
55
|
-
stubs.map {|s| " #{s.opts.pretty_inspect}" }.join
|
53
|
+
super opts, 'Ambiguous stubs.'
|
56
54
|
end
|
55
|
+
|
57
56
|
end
|
58
57
|
|
59
58
|
# Resource not found error raised on a 404 response
|
@@ -68,7 +67,7 @@ module Acfs
|
|
68
67
|
def initialize(opts = {})
|
69
68
|
@errors = opts.delete :errors
|
70
69
|
@resource = opts.delete :resource
|
71
|
-
opts[:message] ||= @errors.map
|
70
|
+
opts[:message] ||= @errors.map{ |k,v| "#{k}: #{v.join ', '}" }.join ', ' if @errors.is_a? Hash
|
72
71
|
opts[:message] ||= @errors.join ', ' if @errors.is_a? Array
|
73
72
|
super
|
74
73
|
end
|
@@ -100,7 +99,7 @@ module Acfs
|
|
100
99
|
def initialize(opts = {})
|
101
100
|
@base_class = opts.delete :base_class
|
102
101
|
@type_name = opts.delete :type_name
|
103
|
-
opts[:message] = "
|
102
|
+
opts[:message] = "Recieved ressource type `#{type_name}` is no subclass of #{base_class}"
|
104
103
|
super
|
105
104
|
end
|
106
105
|
end
|
data/lib/acfs/global.rb
CHANGED
@@ -1,22 +1,14 @@
|
|
1
1
|
module Acfs
|
2
|
-
|
2
|
+
|
3
3
|
# Global Acfs module methods.
|
4
4
|
#
|
5
5
|
module Global
|
6
|
-
|
6
|
+
|
7
7
|
# @api private
|
8
8
|
# @return [Runner]
|
9
9
|
#
|
10
10
|
def runner
|
11
|
-
|
12
|
-
adapter = Configuration.current.adapter
|
13
|
-
|
14
|
-
if adapter
|
15
|
-
Runner.new adapter.call
|
16
|
-
else
|
17
|
-
Runner.new Adapter::Typhoeus.new
|
18
|
-
end
|
19
|
-
end
|
11
|
+
@runner ||= Runner.new Adapter::Typhoeus.new
|
20
12
|
end
|
21
13
|
|
22
14
|
# @api public
|
@@ -67,10 +59,9 @@ module Acfs
|
|
67
59
|
# Acfs.add_callback(user, &callback_two)
|
68
60
|
#
|
69
61
|
def add_callback(resource, &block)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
62
|
+
raise ArgumentError.new "Given resource is not an Acfs resource but "\
|
63
|
+
"a: #{resource.class.name}" \
|
64
|
+
unless resource.respond_to?(:__callbacks__)
|
74
65
|
return false if block.nil?
|
75
66
|
|
76
67
|
if resource.loaded?
|
@@ -82,7 +73,7 @@ module Acfs
|
|
82
73
|
|
83
74
|
def on(*resources)
|
84
75
|
resources.each do |resource|
|
85
|
-
add_callback resource do |
|
76
|
+
add_callback resource do |ret|
|
86
77
|
yield(*resources) unless resources.any? {|res| !res.loaded? }
|
87
78
|
end
|
88
79
|
end
|