acfs 0.30.0.1.b261 → 0.30.0.1.b262

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDBhNGMzOTliN2YzYWNiZjZiMmM5ZjZhODMxYzk5NmU4MDU2ODA2Mg==
4
+ M2U0MmM3NmE4NTkzZjliOTE3NjViZjgzNTYyNWE0ZGRkNDAxNTJjMw==
5
5
  data.tar.gz: !binary |-
6
- NTAyZDVkZDEzOWFhY2I1OTM0OTQwMjk5MmE4YzIyZTQ4ZmJhNmY2MA==
6
+ NTA4MDJjYWJmMTYwNjVjNmZiMDU1NmY3MjRhMjY5YjY5MjIxYTdkNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2M4YTAwOTZmMWNkY2E1NWVjYzcxNjFlY2QwN2MwMGU5YmM5ZWEwNjA0MTEy
10
- OTY4OWZhZjliZjI1ZGM3ZWY2OGE1ZjUwNjc5NjUyMTI1OWI2NDUyODgyNDg1
11
- MmU3ODYxMmZhNTAyMWUxOGFiZjA2YzRjMWNkNjgxNmU2YWIxNjY=
9
+ YjBiMmMzM2FjODhlZDRmM2VjZWQ0M2Y5NjAyYzRmNGZhNzA3ZDc5Y2NhOWNi
10
+ ZjIyNjlhNzYzN2UzMjllZDNjZDg1YzUyYzVkMmUzMDcyNmNhOGRmYzNkZWE3
11
+ NjQzZThiN2UwMGY0MWM2NDcyMGIzMDdlOTYzOTZlNDRhZGZmZWE=
12
12
  data.tar.gz: !binary |-
13
- MmEyYWRlODQyODNlNWNkNTQ2NmFjZjhiNDliNTc1ZTA5M2QwMWRiNTljOTUz
14
- YjBmYmQzMGQ1M2Q3ZjYyZWUxM2U5OTAwMDIwZDZhMWU3Y2QyMmRmYzMxMmJl
15
- MDdmOTRjMmJmYjRiMjUxYmY4YzI1YmZmNDhhMjRhNmNkMTczN2M=
13
+ NjUwZGViMmE3YjY4MWM1NGM0Mjk4Zjk0MTM0MjJhMDBhMjE4YzBkNGIzM2Y3
14
+ ZGU2YjBiNmZkZmNjMGE0ZmYxM2FkZGJkNjAxMGFiODhjOTk5YTRhOWY0MDA4
15
+ OTBkYjMwZGRhNDEzZDA1ZmUzNTZlMzdlNDA3MDVhYTQ4ZGM5YWQ=
@@ -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 to_s
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)
@@ -83,14 +83,15 @@ module Acfs::Model
83
83
  end
84
84
 
85
85
  # @api private
86
- def path_defaults
87
- {
88
- list: '/:path',
89
- create: '/:path',
90
- read: '/:path/:id',
91
- update: '/:path/:id',
92
- delete: '/:path/:id'
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
 
@@ -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 location.str, method: method, params: params, data: data
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
@@ -37,13 +37,25 @@ module Acfs
37
37
  def location(resource_class, opts = {})
38
38
  opts.reverse_merge! self.options
39
39
 
40
- url = self.class.base_url.to_s
41
- url += resource_class.path_defaults[opts[:action] || :list] || '/:path'
40
+ action = opts[:action] || :list
42
41
 
43
- path = opts[:path]
44
- path ||= (resource_class.name || 'class').pluralize.underscore
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
- Location.new Location.new(url).build(raise: false, path: path).str
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 path_defaults
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
@@ -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(:path_defaults).and_return({}) }
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')
@@ -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
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.30.0.1.b261
4
+ version: 0.30.0.1.b262
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen