acfs 0.30.0.1.b261 → 0.30.0.1.b262
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 +8 -8
- data/lib/acfs/location.rb +5 -2
- data/lib/acfs/model/locatable.rb +9 -8
- data/lib/acfs/operation.rb +3 -2
- data/lib/acfs/service.rb +17 -5
- data/lib/acfs/singleton_resource.rb +2 -8
- data/spec/acfs/model/locatable_spec.rb +31 -0
- data/spec/acfs/service_spec.rb +1 -1
- data/spec/support/service.rb +5 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2U0MmM3NmE4NTkzZjliOTE3NjViZjgzNTYyNWE0ZGRkNDAxNTJjMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTA4MDJjYWJmMTYwNjVjNmZiMDU1NmY3MjRhMjY5YjY5MjIxYTdkNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjBiMmMzM2FjODhlZDRmM2VjZWQ0M2Y5NjAyYzRmNGZhNzA3ZDc5Y2NhOWNi
|
10
|
+
ZjIyNjlhNzYzN2UzMjllZDNjZDg1YzUyYzVkMmUzMDcyNmNhOGRmYzNkZWE3
|
11
|
+
NjQzZThiN2UwMGY0MWM2NDcyMGIzMDdlOTYzOTZlNDRhZGZmZWE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjUwZGViMmE3YjY4MWM1NGM0Mjk4Zjk0MTM0MjJhMDBhMjE4YzBkNGIzM2Y3
|
14
|
+
ZGU2YjBiNmZkZmNjMGE0ZmYxM2FkZGJkNjAxMGFiODhjOTk5YTRhOWY0MDA4
|
15
|
+
OTBkYjMwZGRhNDEzZDA1ZmUzNTZlMzdlNDA3MDVhYTQ4ZGM5YWQ=
|
data/lib/acfs/location.rb
CHANGED
@@ -34,19 +34,22 @@ module Acfs
|
|
34
34
|
|
35
35
|
def str
|
36
36
|
uri = raw.dup
|
37
|
-
uri.path = '/' + struct.map{|s| lookup_arg(s, args) }.join('/')
|
37
|
+
uri.path = URI.escape '/' + struct.map{|s| lookup_arg(s, args) }.join('/')
|
38
38
|
uri.to_s
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def raw_uri
|
42
42
|
raw.to_s
|
43
43
|
end
|
44
|
+
alias_method :to_s, :raw_uri
|
44
45
|
|
45
46
|
private
|
46
47
|
def extract_arg(key, hashes)
|
47
48
|
hashes.each_with_index do |hash, index|
|
48
49
|
return (index == 0 ? hash.delete(key) : hash.fetch(key)) if hash.has_key?(key)
|
49
50
|
end
|
51
|
+
|
52
|
+
nil
|
50
53
|
end
|
51
54
|
|
52
55
|
def lookup_arg(arg, args)
|
data/lib/acfs/model/locatable.rb
CHANGED
@@ -83,14 +83,15 @@ module Acfs::Model
|
|
83
83
|
end
|
84
84
|
|
85
85
|
# @api private
|
86
|
-
def
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
86
|
+
def location_default_path(action, path)
|
87
|
+
case action
|
88
|
+
when :list, :create
|
89
|
+
return path
|
90
|
+
when :read, :update, :delete
|
91
|
+
return "#{path}/:id"
|
92
|
+
else
|
93
|
+
nil
|
94
|
+
end
|
94
95
|
end
|
95
96
|
end
|
96
97
|
|
data/lib/acfs/operation.rb
CHANGED
@@ -6,7 +6,7 @@ module Acfs
|
|
6
6
|
# processing as well as error handling and stubbing.
|
7
7
|
#
|
8
8
|
class Operation
|
9
|
-
attr_reader :action, :params, :resource, :data, :callback, :location
|
9
|
+
attr_reader :action, :params, :resource, :data, :callback, :location, :url
|
10
10
|
delegate :service, to: :resource
|
11
11
|
delegate :call, to: :callback
|
12
12
|
|
@@ -20,6 +20,7 @@ module Acfs
|
|
20
20
|
@data = (opts[:data] || {}).dup
|
21
21
|
|
22
22
|
@location = resource.location(action: @action).extract_from(@params, @data)
|
23
|
+
@url = location.str
|
23
24
|
|
24
25
|
@callback = block
|
25
26
|
end
|
@@ -46,7 +47,7 @@ module Acfs
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def request
|
49
|
-
request = ::Acfs::Request.new
|
50
|
+
request = ::Acfs::Request.new url, method: method, params: params, data: data
|
50
51
|
request.on_complete do |response|
|
51
52
|
handle_failure response unless response.success?
|
52
53
|
callback.call response.data
|
data/lib/acfs/service.rb
CHANGED
@@ -37,13 +37,25 @@ module Acfs
|
|
37
37
|
def location(resource_class, opts = {})
|
38
38
|
opts.reverse_merge! self.options
|
39
39
|
|
40
|
-
|
41
|
-
url += resource_class.path_defaults[opts[:action] || :list] || '/:path'
|
40
|
+
action = opts[:action] || :list
|
42
41
|
|
43
|
-
path = opts[:path]
|
44
|
-
|
42
|
+
path = if Hash === opts[:path] && opts[:path].has_key?(action)
|
43
|
+
opts[:path].fetch(action)
|
44
|
+
else
|
45
|
+
path = if Hash === opts[:path]
|
46
|
+
opts[:path][:all].to_s
|
47
|
+
else
|
48
|
+
opts[:path].to_s
|
49
|
+
end
|
45
50
|
|
46
|
-
|
51
|
+
path = (resource_class.name || 'class').pluralize.underscore if path.blank?
|
52
|
+
|
53
|
+
resource_class.location_default_path(action, path.strip)
|
54
|
+
end
|
55
|
+
|
56
|
+
raise ArgumentError.new "Location for `#{action}' explicit disabled by set to nil." if path.nil?
|
57
|
+
|
58
|
+
Location.new [self.class.base_url.to_s, path.to_s].join('/')
|
47
59
|
end
|
48
60
|
|
49
61
|
class << self
|
@@ -97,14 +97,8 @@ module Acfs
|
|
97
97
|
undef_method :find_by!
|
98
98
|
|
99
99
|
# @api private
|
100
|
-
def
|
101
|
-
|
102
|
-
list: '/:path',
|
103
|
-
create: '/:path',
|
104
|
-
read: '/:path',
|
105
|
-
update: '/:path',
|
106
|
-
delete: '/:path'
|
107
|
-
}
|
100
|
+
def location_default_path(_, path)
|
101
|
+
path
|
108
102
|
end
|
109
103
|
end
|
110
104
|
end
|
@@ -29,6 +29,37 @@ describe Acfs::Model::Locatable do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
describe 'custom paths' do
|
34
|
+
let(:model) { Session }
|
35
|
+
let(:location) { Session.location action: action }
|
36
|
+
subject { location }
|
37
|
+
|
38
|
+
context ':list location' do
|
39
|
+
let(:action) { :list }
|
40
|
+
its(:raw_uri) { should eq 'http://users.example.org/users/:user_id/sessions' }
|
41
|
+
end
|
42
|
+
|
43
|
+
context ':create location' do
|
44
|
+
let(:action) { :create }
|
45
|
+
its(:raw_uri) { should eq 'http://users.example.org/sessions' }
|
46
|
+
end
|
47
|
+
|
48
|
+
context ':read location' do
|
49
|
+
let(:action) { :read }
|
50
|
+
its(:raw_uri) { should eq 'http://users.example.org/sessions/:id' }
|
51
|
+
end
|
52
|
+
|
53
|
+
context ':update location' do
|
54
|
+
let(:action) { :update }
|
55
|
+
its(:raw_uri) { expect{ subject }.to raise_error(ArgumentError, /update.*disabled/)}
|
56
|
+
end
|
57
|
+
|
58
|
+
context ':delete location' do
|
59
|
+
let(:action) { :delete }
|
60
|
+
its(:raw_uri) { should eq 'http://users.example.org/users/:user_id/sessions/del/:id' }
|
61
|
+
end
|
62
|
+
end
|
32
63
|
end
|
33
64
|
|
34
65
|
describe '#url' do
|
data/spec/acfs/service_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe Acfs::Service do
|
|
19
19
|
|
20
20
|
describe '#location' do
|
21
21
|
let(:resource) { Class.new }
|
22
|
-
before { allow(resource).to receive(:
|
22
|
+
before { allow(resource).to receive(:location_default_path, &proc{|a, p| p}) }
|
23
23
|
|
24
24
|
it 'should extract resource path name from given class' do
|
25
25
|
expect(service.location(resource).to_s).to eq('/classes')
|
data/spec/support/service.rb
CHANGED
@@ -42,7 +42,11 @@ class MyUserWithValidations < MyUser
|
|
42
42
|
end
|
43
43
|
|
44
44
|
class Session < Acfs::Resource
|
45
|
-
service UserService
|
45
|
+
service UserService, path: {
|
46
|
+
list: 'users/:user_id/sessions',
|
47
|
+
delete: 'users/:user_id/sessions/del/:id',
|
48
|
+
update: nil
|
49
|
+
}
|
46
50
|
|
47
51
|
attribute :id, :string
|
48
52
|
attribute :user, :integer
|