sinatra-rest-base 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b8c04a79fba6e26cc1309e58107b3e06d950364
4
- data.tar.gz: fce5fc71f80bbbbb0a51c3b023fdd1eb220e01a9
3
+ metadata.gz: 5e4c051e044943fb538e806a31e6330b75b89fc8
4
+ data.tar.gz: a6af540e82d2a48a635e4d45c882efd9c33053fe
5
5
  SHA512:
6
- metadata.gz: 0077f646ba6a2b2056b4aa2a34e41c013133d60773b282b9a81e6e83172d71daa7e3c2384615ebf1c17d2d88d07b110966117bef00a3e807a3410cb04c46ac3d
7
- data.tar.gz: 8f78662d0f61227f4265f4cd6747ee76598a3439eae312298b40aa8f565a7aab7a1b7516ab5f965587527e724ba409ed2df2895336b95acbd04d1011e087b92d
6
+ metadata.gz: 838b719f9a9f5d39a07d160249e2207cbe6156f72b5ac03a6a254c197e135e52e2cf207b6b232185fc141e25776ecc90fd876f274f8a3f4468118d47fee4bb3e
7
+ data.tar.gz: e511cf7ac1853a6cc368be5ec05226976f72561ea59933be66a1701c0deccbaf832d3d84e16772a2a9257917eebb89d2c66eea9ce55411f24543a27959ba1277
@@ -24,6 +24,12 @@ module RestBase
24
24
  has_version?("version=#{value}")
25
25
  end
26
26
  end
27
+
28
+ set(:method) do |method|
29
+ condition do
30
+ request.request_method.downcase.to_sym == method.to_s.downcase.to_sym
31
+ end
32
+ end
27
33
 
28
34
  before do
29
35
  status 200
@@ -37,7 +43,6 @@ module RestBase
37
43
  after do
38
44
  response.body = nil if response.body.is_a?(Array) && response.body.length == 1 && response.body[0].empty?
39
45
  response.body = create_response()
40
-
41
46
  response.headers['Content-Type'] += ";version=#{@request_version}"
42
47
  end
43
48
  end
@@ -1,3 +1,3 @@
1
1
  module RestBase
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -6,6 +6,22 @@ module RestBase
6
6
  set :authentication, RestBase::Authentication::BasicAuthentication.new(['key1', 'key2'])
7
7
  enable :header_versioning
8
8
  end
9
+
10
+ before '/method_filter', :method => :get do
11
+ @method_response = []
12
+ @method_response << "Hit Before Filter"
13
+ end
14
+
15
+ get '/method_filter' do
16
+ @method_response << "Response Filtered"
17
+ @method_response
18
+ end
19
+
20
+ put '/method_filter' do
21
+ @method_response = []
22
+ @method_response << "Response Filtered"
23
+ @method_response
24
+ end
9
25
  end
10
26
  end
11
27
  end
@@ -38,6 +38,20 @@ describe RestBase::Application do
38
38
  end
39
39
  end
40
40
 
41
+ describe :method do
42
+ it "should go through the before filter" do
43
+ get '/method_filter', {}, @headers
44
+
45
+ expect(last_response.body).to eq({:result => ["Hit Before Filter", "Response Filtered"]}.to_json)
46
+ end
47
+
48
+ it "should not go through the before filter" do
49
+ put '/method_filter', {}, @headers
50
+
51
+ expect(last_response.body).to eq({:result => ["Response Filtered"]}.to_json)
52
+ end
53
+ end
54
+
41
55
  describe :authorization do
42
56
  it "should try to authorize" do
43
57
  get '/', {}, @headers
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-rest-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bmills