acfs 0.25.0.1.b232 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CHANGELOG.md +4 -0
- data/lib/acfs.rb +1 -0
- data/lib/acfs/operation.rb +0 -2
- data/lib/acfs/singleton_resource.rb +92 -0
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs_spec.rb +66 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/service.rb +7 -0
- metadata +18 -17
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NzFiNjNhNDQ5NjIyNmVlODI0YzEwZTljYTBjNTU4Y2E0YjFmMTdkMw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef03d133e909f75c3e309db36a37b2ebebb5f5c0
|
4
|
+
data.tar.gz: db0c0ef2f2d97301ceb1b66ebdc3e7262d282b4b
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YTQzMjcxNGFkN2UxODc3ZGIwY2E0MTdkMGI5YTNmZGRkYTVjMDg2ODEwMzA0
|
11
|
-
NmVhZWI5NzMyOWM4OWJmYjQ5NWU4ZGJhOThlMDZlYzUzNjMxMTc=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YWVhNzAzY2FkYzY0ZjlmYzhlOTg3OWZkNzNmNDFhMmY1ZTM0NDZjYjkyOWUx
|
14
|
-
YjYwM2JjYTg1ZjhkOGY1YWY1NjdlMzcyYTI0ZGQzYjc4ZTJhNzljOGIwYzY1
|
15
|
-
YTk0Y2ZiYjRkYTQ0MGQ2NTk0MjhkYWFiZmMwNGNjODk3NDczOWY=
|
6
|
+
metadata.gz: 9633fb9b9f3ac0357f03cb64c37f48066e28d6ba7238292fcaac8b448e297ad1b6c1f4c42a66f09e3be9e33423e215977f6ce2f573d611d8b5a30df48eb5809d
|
7
|
+
data.tar.gz: 52dcbf542450575eb7525e03e4a96e0bff46995cd756125be96ebee6f7386be53691b32859684e0543d34eee0b289f99ab838123f3f8a7d67d6f7994f53abadb
|
data/CHANGELOG.md
CHANGED
data/lib/acfs.rb
CHANGED
data/lib/acfs/operation.rb
CHANGED
@@ -0,0 +1,92 @@
|
|
1
|
+
module Acfs
|
2
|
+
|
3
|
+
# Acfs SingletonResources
|
4
|
+
#
|
5
|
+
# Usage explanation:
|
6
|
+
# Single.find => sends GET request to http://service:port/single
|
7
|
+
# my_single.save => sends POST request to http://service:port/single if my_single is a new object
|
8
|
+
# or sends PUT request to http://service:port/single if my_single has been requested before
|
9
|
+
# my_single.delete => sends DELETE request to http://service:port/single
|
10
|
+
#
|
11
|
+
# SingletonResources do not support the Resource method :all, since
|
12
|
+
# always only a single instance of the resource is being returned
|
13
|
+
#
|
14
|
+
class SingletonResource < Acfs::Resource
|
15
|
+
|
16
|
+
# @api public
|
17
|
+
#
|
18
|
+
# Return true if model is a new record and was not saved yet.
|
19
|
+
#
|
20
|
+
# Checks weather object is loaded via delegator or not, since
|
21
|
+
# the id-attribute is not required for singletons this check
|
22
|
+
# cannot check for existence of value in id-attribute
|
23
|
+
#
|
24
|
+
# @return [Boolean] True if resource is newly created, false otherwise.
|
25
|
+
#
|
26
|
+
def new?
|
27
|
+
!loaded?
|
28
|
+
end
|
29
|
+
alias :new_record? :new?
|
30
|
+
|
31
|
+
# @api public
|
32
|
+
#
|
33
|
+
# Destroy resource by sending a DELETE request.
|
34
|
+
# Will raise an error in case something goes wrong.
|
35
|
+
#
|
36
|
+
# Deleting a resource is a synchronous operation.
|
37
|
+
#
|
38
|
+
# @raise [Acfs::ErroneousResponse]
|
39
|
+
# If remote service respond with not successful response.
|
40
|
+
# @return [undefined]
|
41
|
+
# @see #delete
|
42
|
+
#
|
43
|
+
def delete!(opts = {})
|
44
|
+
opts[:params] ||= {}
|
45
|
+
|
46
|
+
operation :delete, opts do |data|
|
47
|
+
update_with data
|
48
|
+
freeze
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class << self
|
53
|
+
# @api public
|
54
|
+
#
|
55
|
+
# @overload find(id, opts = {})
|
56
|
+
# Find a singleton resource, optionally with params.
|
57
|
+
#
|
58
|
+
# @example
|
59
|
+
# single = Singleton.find # Will query `http://base.url/singletons/`
|
60
|
+
#
|
61
|
+
# @param [ Hash ] opts Additional options.
|
62
|
+
# @option opts [ Hash ] :params Additional parameters added to request.
|
63
|
+
#
|
64
|
+
# @yield [ resource ] Callback block to be executed after resource was fetched successfully.
|
65
|
+
# @yieldparam resource [ self ] Fetched resources.
|
66
|
+
#
|
67
|
+
# @return [ self ] Resource object.
|
68
|
+
#
|
69
|
+
def find(*attrs, &block)
|
70
|
+
opts = { params: attrs.extract_options! }
|
71
|
+
|
72
|
+
model = ResourceDelegator.new self.new
|
73
|
+
|
74
|
+
operation :read, opts do |data|
|
75
|
+
model.__setobj__ create_resource data, origin: model.__getobj__
|
76
|
+
block.call model unless block.nil?
|
77
|
+
end
|
78
|
+
|
79
|
+
model
|
80
|
+
end
|
81
|
+
|
82
|
+
# @api public
|
83
|
+
#
|
84
|
+
# Undefined, raises NoMethodError.
|
85
|
+
# A singleton always only returns one object, therefore the
|
86
|
+
# methods :all and :where are not defined.
|
87
|
+
#
|
88
|
+
undef_method :all
|
89
|
+
undef_method :where
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/acfs/version.rb
CHANGED
data/spec/acfs_spec.rb
CHANGED
@@ -56,6 +56,72 @@ describe 'Acfs' do
|
|
56
56
|
expect(@user.age).to be == 26
|
57
57
|
end
|
58
58
|
|
59
|
+
describe 'singleton' do
|
60
|
+
before do
|
61
|
+
stub_request(:get, 'http://users.example.org/singles?user_id=5').to_return response({ score: 250, user_id: 5 })
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should create a singleton resource' do
|
65
|
+
stub = stub_request(:post, 'http://users.example.org/singles').to_return response({ score: 250, user_id: 5 })
|
66
|
+
|
67
|
+
@single = Single.new user_id: 5, score: 250
|
68
|
+
expect(@single.new?).to eq true
|
69
|
+
|
70
|
+
@single.save
|
71
|
+
expect(stub).to have_been_requested
|
72
|
+
|
73
|
+
expect(@single.new?).to eq false
|
74
|
+
expect(@single.user_id).to eq 5
|
75
|
+
expect(@single.score).to eq 250
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should load singleton resource' do
|
79
|
+
@single = Single.find user_id: 5
|
80
|
+
Acfs.run
|
81
|
+
|
82
|
+
expect(@single.score).to eq 250
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should update singleton resource' do
|
86
|
+
stub = stub_request(:put, 'http://users.example.org/singles').to_return { |request| {
|
87
|
+
body: request.body,
|
88
|
+
headers: { 'Content-Type' => request.headers['Content-Type'] }
|
89
|
+
} }
|
90
|
+
|
91
|
+
@single = Single.find user_id: 5
|
92
|
+
Acfs.run
|
93
|
+
|
94
|
+
expect(@single.score).to eq 250
|
95
|
+
|
96
|
+
@single.score = 300
|
97
|
+
@single.save
|
98
|
+
|
99
|
+
expect(stub).to have_been_requested
|
100
|
+
|
101
|
+
expect(@single.score).to eq 300
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should delete singleton resource' do
|
105
|
+
stub = stub_request(:delete, 'http://users.example.org/singles').to_return { |request| {
|
106
|
+
body: request.body,
|
107
|
+
headers: { 'Content-Type' => request.headers['Content-Type'] }
|
108
|
+
} }
|
109
|
+
|
110
|
+
@single = Single.find user_id: 5
|
111
|
+
Acfs.run
|
112
|
+
|
113
|
+
expect(@single.new?).to eq false
|
114
|
+
|
115
|
+
@single.delete
|
116
|
+
|
117
|
+
expect(stub).to have_been_requested
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should raise error when calling `all\'' do
|
121
|
+
expect {Single.all}.to raise_error(NoMethodError)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
59
125
|
it 'should load multiple single resources' do
|
60
126
|
@users = MyUser.find(2, 3, 100) do |users|
|
61
127
|
# This block should be called only after *all* resources are loaded.
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/service.rb
CHANGED
@@ -68,6 +68,13 @@ class Mac < Computer
|
|
68
68
|
|
69
69
|
end
|
70
70
|
|
71
|
+
class Single < Acfs::SingletonResource
|
72
|
+
service UserService
|
73
|
+
|
74
|
+
attribute :score, :integer
|
75
|
+
attribute :user_id, :integer
|
76
|
+
end
|
77
|
+
|
71
78
|
# DRAFT: Singular resource
|
72
79
|
#class Singular < Acfs::Resource
|
73
80
|
# service UserService, singular: true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.26.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
@@ -14,84 +14,84 @@ dependencies:
|
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: actionpack
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.1'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: multi_json
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: typhoeus
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.6.5
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.6.5
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rack
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
@@ -172,6 +172,7 @@ files:
|
|
172
172
|
- lib/acfs/runner.rb
|
173
173
|
- lib/acfs/service.rb
|
174
174
|
- lib/acfs/service/middleware.rb
|
175
|
+
- lib/acfs/singleton_resource.rb
|
175
176
|
- lib/acfs/stub.rb
|
176
177
|
- lib/acfs/version.rb
|
177
178
|
- lib/acfs/yard.rb
|
@@ -213,17 +214,17 @@ require_paths:
|
|
213
214
|
- lib
|
214
215
|
required_ruby_version: !ruby/object:Gem::Requirement
|
215
216
|
requirements:
|
216
|
-
- -
|
217
|
+
- - '>='
|
217
218
|
- !ruby/object:Gem::Version
|
218
219
|
version: '0'
|
219
220
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
221
|
requirements:
|
221
|
-
- -
|
222
|
+
- - '>='
|
222
223
|
- !ruby/object:Gem::Version
|
223
|
-
version:
|
224
|
+
version: '0'
|
224
225
|
requirements: []
|
225
226
|
rubyforge_project:
|
226
|
-
rubygems_version: 2.
|
227
|
+
rubygems_version: 2.1.11
|
227
228
|
signing_key:
|
228
229
|
specification_version: 4
|
229
230
|
summary: An abstract API base client for service oriented application.
|