rest-in-peace 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -9,6 +9,7 @@ module RESTinPeace
9
9
  end
10
10
 
11
11
  def get(method_name, url_template, default_params = {})
12
+ @target.rip_registry[:collection] << { method: :get, name: method_name, url: url_template }
12
13
  @target.send(:define_singleton_method, method_name) do |*args|
13
14
  if args.last.is_a?(Hash)
14
15
  params = default_params.merge(args.pop)
@@ -6,6 +6,7 @@ module RESTinPeace
6
6
  end
7
7
 
8
8
  def get(method_name, url_template, default_params = {})
9
+ @target.rip_registry[:resource] << { method: :get, name: method_name, url: url_template }
9
10
  @target.send(:define_method, method_name) do
10
11
  call = RESTinPeace::ApiCall.new(api, url_template, self, to_h)
11
12
  call.get
@@ -13,6 +14,7 @@ module RESTinPeace
13
14
  end
14
15
 
15
16
  def patch(method_name, url_template)
17
+ @target.rip_registry[:resource] << { method: :patch, name: method_name, url: url_template }
16
18
  @target.send(:define_method, method_name) do
17
19
  call = RESTinPeace::ApiCall.new(api, url_template, self, to_h)
18
20
  call.patch
@@ -20,6 +22,7 @@ module RESTinPeace
20
22
  end
21
23
 
22
24
  def post(method_name, url_template)
25
+ @target.rip_registry[:resource] << { method: :post, name: method_name, url: url_template }
23
26
  @target.send(:define_method, method_name) do
24
27
  call = RESTinPeace::ApiCall.new(api, url_template, self, to_h)
25
28
  call.post
@@ -27,6 +30,7 @@ module RESTinPeace
27
30
  end
28
31
 
29
32
  def delete(method_name, url_template, default_params = {})
33
+ @target.rip_registry[:resource] << { method: :delete, name: method_name, url: url_template }
30
34
  @target.send(:define_method, method_name) do |params = {}|
31
35
  merged_params = default_params.merge(to_h).merge(params)
32
36
  call = RESTinPeace::ApiCall.new(api, url_template, self, merged_params)
data/lib/rest_in_peace.rb CHANGED
@@ -34,5 +34,12 @@ module RESTinPeace
34
34
  definition_proxy = RESTinPeace::DefinitionProxy.new(self)
35
35
  definition_proxy.instance_eval(&block)
36
36
  end
37
+
38
+ def rip_registry
39
+ @rip_registry ||= {
40
+ resource: [],
41
+ collection: [],
42
+ }
43
+ end
37
44
  end
38
45
  end
@@ -26,6 +26,11 @@ describe RESTinPeace::DefinitionProxy::CollectionMethodDefinitions do
26
26
  to change { target.respond_to?(:find) }.from(false).to(true)
27
27
  end
28
28
 
29
+ it 'adds the method to the registry' do
30
+ subject.get(:all, '/a')
31
+ expect(target.rip_registry[:collection]).to eq([method: :get, name: :all, url: '/a'])
32
+ end
33
+
29
34
  describe 'the created method' do
30
35
  before do
31
36
  allow(api_call_double).to receive(:get)
@@ -24,6 +24,11 @@ describe RESTinPeace::DefinitionProxy::ResourceMethodDefinitions do
24
24
  to change { instance.respond_to?(method_name) }.from(false).to(true)
25
25
  end
26
26
 
27
+ it 'adds the method to the registry' do
28
+ subject.send(http_verb, method_name, url_template)
29
+ expect(target.rip_registry[:resource]).to eq([method: http_verb, name: method_name, url: url_template])
30
+ end
31
+
27
32
  describe 'the created method' do
28
33
  before do
29
34
  allow(api_call_double).to receive(http_verb)
@@ -31,6 +31,12 @@ describe RESTinPeace do
31
31
  end
32
32
  end
33
33
 
34
+ describe '::rip_registry' do
35
+ subject { extended_class }
36
+ specify { expect(extended_class).to respond_to(:rip_registry) }
37
+ specify { expect(extended_class.rip_registry).to eq(collection: [], resource: []) }
38
+ end
39
+
34
40
  describe '#api' do
35
41
  subject { instance }
36
42
  specify { expect(subject).to respond_to(:api).with(0).arguments }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-in-peace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-17 00:00:00.000000000 Z
12
+ date: 2014-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake