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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4967ef9a4193e2caca1f27035eb81f81e1ed918
4
- data.tar.gz: 61f6a27ec7f13762954656f841666dddc37c9a8c
3
+ metadata.gz: 1e01c987bb7ede49542371cb4d6c68a0ca529f5f
4
+ data.tar.gz: 719112d08117e9af8c03355067bd41b9cae51350
5
5
  SHA512:
6
- metadata.gz: ea757b0f6203e080b27eee87ba0094db03a71bfc517f0c33223d37049bd2972ad2db6cf48601668bb2c20625628194bc5eb2897bfeb95d9df097fd2dae345cc7
7
- data.tar.gz: 141e9a7c5aae36bedd0f1293c4faddae6621f6fa0d8b956ee44309a44628fad1245d012d9d9ad6c52ba233fca74465eb3b47187f479ce0d37583ca8e5b83138c
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 instance_variables.any? { |iv| iv.to_s == '@halt_included' }
23
- @halt_included = proc do |controller_class|
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ApiHammer
2
- VERSION = "0.13.0"
2
+ VERSION = "0.13.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_hammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan