api_hammer 0.13.0 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/api_hammer/rails/halt.rb +3 -3
- data/lib/api_hammer/sinatra.rb +26 -12
- data/lib/api_hammer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e01c987bb7ede49542371cb4d6c68a0ca529f5f
|
4
|
+
data.tar.gz: 719112d08117e9af8c03355067bd41b9cae51350
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 786a19ca358815f579ed7755c88df46bb272f9d37ed4e48b97eb9d2641fffdc7f35fcd09724ab8275b0b6986711fb455f17aa6b02cfb362fbed42288c5426342
|
7
|
+
data.tar.gz: 0f810365af6dc3d0f538963b3d5d7ba05b9eecce309d7ceb3e4e83dd329886c35cf2dbf6faa028eb6937985d3dd24ef6b7399ec2ec7ed5772f068e38bb3a437a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# v0.13.1
|
2
|
+
- ApiHammer::Sinatra class method use_with_lint
|
3
|
+
- set up Rack::Accept middleware in sinatra as api hammer methods rely on that
|
4
|
+
|
1
5
|
# v0.13.0
|
2
6
|
- ApiHammer::Sinatra, with some useful sinatra methods
|
3
7
|
- #halt, #halt_error, #halt_unprocessable_entity and friends
|
@@ -19,11 +19,11 @@ module ApiHammer::Rails
|
|
19
19
|
attr_reader :body, :render_options
|
20
20
|
end
|
21
21
|
|
22
|
-
unless
|
23
|
-
@
|
22
|
+
unless @rails_halt_included_defined
|
23
|
+
@rails_halt_included_defined = true
|
24
|
+
(@on_included ||= Set.new) << proc do |controller_class|
|
24
25
|
controller_class.send(:rescue_from, ApiHammer::Rails::Halt, :with => :handle_halt)
|
25
26
|
end
|
26
|
-
(@on_included ||= Set.new) << @halt_included
|
27
27
|
end
|
28
28
|
|
29
29
|
# handle a raised ApiHammer::Halt or subclass and render it
|
data/lib/api_hammer/sinatra.rb
CHANGED
@@ -8,6 +8,32 @@ module ApiHammer
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
unless @sinatra_included_defined
|
12
|
+
@sinatra_included_defined = true
|
13
|
+
(@on_included ||= Set.new) << proc do |klass|
|
14
|
+
# set up self.supported_media_types
|
15
|
+
klass.define_singleton_method(:supported_media_types=) do |supported_media_types|
|
16
|
+
@supported_media_types = supported_media_types
|
17
|
+
end
|
18
|
+
klass.define_singleton_method(:supported_media_types) do
|
19
|
+
@supported_media_types
|
20
|
+
end
|
21
|
+
|
22
|
+
# causes a Rack::Lint middleware to be inserted before and after the given middleware to be used
|
23
|
+
klass.define_singleton_method(:use_with_lint) do |middleware, *args, &block|
|
24
|
+
if (development? || test?) && (@middleware.empty? || @middleware.last.first != Rack::Lint)
|
25
|
+
use Rack::Lint
|
26
|
+
end
|
27
|
+
use middleware, *args, &block
|
28
|
+
use Rack::Lint if development? || test?
|
29
|
+
end
|
30
|
+
|
31
|
+
# ApiHammer::Sinatra's methods use Rack::Accept so we will go ahead and put this middleware
|
32
|
+
# in the stack
|
33
|
+
klass.use_with_lint Rack::Accept
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
11
37
|
# override Sinatra::Base#route_missing
|
12
38
|
def route_missing
|
13
39
|
message = I18n.t('app.errors.request.route_404',
|
@@ -19,18 +45,6 @@ module ApiHammer
|
|
19
45
|
|
20
46
|
include ApiHammer::Sinatra::Halt
|
21
47
|
|
22
|
-
unless instance_variables.any? { |iv| iv.to_s == '@supported_media_types_included' }
|
23
|
-
@supported_media_types_included = proc do |klass|
|
24
|
-
klass.define_singleton_method(:supported_media_types=) do |supported_media_types|
|
25
|
-
@supported_media_types = supported_media_types
|
26
|
-
end
|
27
|
-
klass.define_singleton_method(:supported_media_types) do
|
28
|
-
@supported_media_types
|
29
|
-
end
|
30
|
-
end
|
31
|
-
(@on_included ||= Set.new) << @supported_media_types_included
|
32
|
-
end
|
33
|
-
|
34
48
|
def supported_media_types
|
35
49
|
self.class.supported_media_types
|
36
50
|
end
|
data/lib/api_hammer/version.rb
CHANGED