acfs 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -2
- data/lib/acfs/model/persistence.rb +18 -0
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs_spec.rb +11 -0
- data/spec/support/service.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1bfc6cac043fef9d28d10c28ed7c4ad25e8ed22
|
4
|
+
data.tar.gz: 2c5a99cfc3a1d02bfc5ea0012f71b8d5a904ff17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a142008f5361b14a32070cd42d63353ef31f63a75b78101b0584f67f9f903a2aeeb8cf9886ae215e9831fe36e0e322ebb71e9a555a832bcf65184c1751685d0
|
7
|
+
data.tar.gz: 193516f56822194e967ac7048e04c85c311a8e5ebc7aaf9074ee853392b98dd3237d2b0444b786a91c3cfb35343fc7a15b2e4054b37761cc655801ea793a0496
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ level and automatic request queuing and parallel processing. See Usage for more.
|
|
13
13
|
|
14
14
|
Add this line to your application's Gemfile:
|
15
15
|
|
16
|
-
gem 'acfs', '0.
|
16
|
+
gem 'acfs', '~> 0.9.0'
|
17
17
|
|
18
18
|
**Note:** Acfs is under development. I'll try to avoid changes to the public
|
19
19
|
API but internal APIs may change quite often.
|
@@ -143,15 +143,21 @@ Acfs has basic update support using `PUT` requests:
|
|
143
143
|
|
144
144
|
## Roadmap
|
145
145
|
|
146
|
-
* Create operations
|
147
146
|
* Update
|
148
147
|
* Better new? detection eg. storing ETag from request resources.
|
149
148
|
* Use PATCH for with only changed attributes and `If-Unmodifed-Since`
|
150
149
|
and `If-Match` header fields if resource was surly loaded from service
|
151
150
|
and not created with an id (e.g `User.new id: 5, name: "john"`).
|
151
|
+
* Conflict detection (ETag / If-Unmodified-Since)
|
152
152
|
* High level features
|
153
|
+
* Support for custom mime types on client and server side. (`application/vnd.myservice.user.v2+msgpack`)
|
154
|
+
* Server side components
|
155
|
+
* Reusing model definitions for generating responses?
|
156
|
+
* Rails responders providing REST operations with integrated ETag,
|
157
|
+
Modified Headers, conflict detection, ...
|
153
158
|
* Pagination? Filtering? (If service API provides such features.)
|
154
159
|
* Messaging Queue support for services and models
|
160
|
+
* Allow stubbing of resources as objects for testing services.
|
155
161
|
* Documentation
|
156
162
|
|
157
163
|
## Contributing
|
@@ -4,6 +4,7 @@ module Acfs
|
|
4
4
|
# Allow to track the persistence state of a model.
|
5
5
|
#
|
6
6
|
module Persistence
|
7
|
+
extend ActiveSupport::Concern
|
7
8
|
|
8
9
|
# Check if the model is persisted. A model is persisted if
|
9
10
|
# it is saved after beeing created or when it was not changed
|
@@ -55,6 +56,23 @@ module Acfs
|
|
55
56
|
self.class.service.run request
|
56
57
|
end
|
57
58
|
|
59
|
+
module ClassMethods
|
60
|
+
|
61
|
+
# Create a new resource sending given data.
|
62
|
+
#
|
63
|
+
def create(data, opts = {})
|
64
|
+
model = new
|
65
|
+
request = Acfs::Request.new url, method: :post, data: data
|
66
|
+
request.on_complete do |response|
|
67
|
+
model.attributes = response.data
|
68
|
+
model.loaded!
|
69
|
+
end
|
70
|
+
|
71
|
+
service.run request
|
72
|
+
model
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
58
76
|
private
|
59
77
|
def update_with(data)
|
60
78
|
self.attributes = data
|
data/lib/acfs/version.rb
CHANGED
data/spec/acfs_spec.rb
CHANGED
@@ -46,6 +46,17 @@ describe "Acfs" do
|
|
46
46
|
expect(@user).to be_persisted
|
47
47
|
end
|
48
48
|
|
49
|
+
it 'should create a single resource synchronously' do
|
50
|
+
stub = stub_request(:post, "http://users.example.org/sessions")
|
51
|
+
.to_return body: '{"id":"sessionhash","user":1}', headers: {'Content-Type' => 'application/json'}
|
52
|
+
|
53
|
+
session = Session.create ident: 'Anon'
|
54
|
+
|
55
|
+
expect(stub).to have_been_requested
|
56
|
+
expect(session.id).to be == 'sessionhash'
|
57
|
+
expect(session.user).to be == 1
|
58
|
+
end
|
59
|
+
|
49
60
|
it 'should load single resource' do
|
50
61
|
@user = MyUser.find(2)
|
51
62
|
|
data/spec/support/service.rb
CHANGED
@@ -20,6 +20,14 @@ class MyUser
|
|
20
20
|
attribute :age, :integer
|
21
21
|
end
|
22
22
|
|
23
|
+
class Session
|
24
|
+
include Acfs::Model
|
25
|
+
service UserService
|
26
|
+
|
27
|
+
attribute :id, :string
|
28
|
+
attribute :user, :integer
|
29
|
+
end
|
30
|
+
|
23
31
|
class Comment
|
24
32
|
include Acfs::Model
|
25
33
|
service CommentService
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|