dandy 0.8.1 → 0.9.0

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: f2bc21d2fad8ada548b6c04e49a2264e0adc9663
4
- data.tar.gz: cd4f6c6a039cc166ea1eec5807fb18cb8582666d
3
+ metadata.gz: fa54fc46b2be97cb013b2d22afad52bbf4e84f72
4
+ data.tar.gz: 3bb80acca3196d720b3279a5d002d2c5af0ee706
5
5
  SHA512:
6
- metadata.gz: eb439771d5084b8247fad3a3fcc6fe2621c3bf7e5ef4c33c19791fd6ca427043dde7e4d197961f90173aade06604a0e6f662314ccb2c49ed6657c17a063b0b08
7
- data.tar.gz: 68f7adaf28bcdefbb8b8637de7ffd05e7c54399f27aa6469e1e884239d80bdeeca55b9e022146f5d15f5808b103a85e3459eebcce78d5e199e947371d624c2bb
6
+ metadata.gz: 28b1940d80ed6f1326e5d378f4498ddd54d28bcb150abdeaa33b1b1399516a05407c2d53e16c405856211dc1a827b1f6d92219fadf7077e89405e0bd069d7647
7
+ data.tar.gz: 3f343cd6c228a69d0b6d2710a0519e0236d251c85a569ca16a1122f5cd1e35ddda8d7d5bfb142e3d267b9fc03c76c9fbbe5483130c6b137f304040db753040cc
@@ -1,5 +1,12 @@
1
1
  class HandleErrors < Dandy::HandleErrors
2
2
  def call
3
- puts @dandy_error
3
+ # implement your own error handling logic here.
4
+ # by default let's print the error to standard output
5
+ puts @dandy_error.message
6
+ puts @dandy_error.backtrace
7
+
8
+ # use preferred HTTP status code for different cases
9
+ # i.e. set_http_status(403) for authorization issue
10
+ set_http_status(500)
4
11
  end
5
12
  end
data/lib/dandy/request.rb CHANGED
@@ -20,10 +20,17 @@ module Dandy
20
20
  path = rack_env['PATH_INFO']
21
21
  request_method = rack_env['REQUEST_METHOD']
22
22
  match = @route_matcher.match(path, request_method)
23
- content_type = rack_env['CONTENT_TYPE'] || 'application/json'
23
+
24
+ headers = Hash[
25
+ *rack_env.select {|k, v| k.start_with? 'HTTP_'}
26
+ .collect {|k, v| [k.sub(/^HTTP_/, ''), v]}
27
+ .collect {|k, v| [k.split('_').collect(&:capitalize).join('-'), v]}
28
+ .flatten
29
+ ]
30
+ register_params(headers, :dandy_headers)
24
31
 
25
32
  if match.nil?
26
- result = [404, { 'Content-Type' => content_type }, []]
33
+ result = [404, {'Content-Type' => headers['Accept']}, []]
27
34
  else
28
35
  query = Rack::Utils.parse_nested_query(rack_env['QUERY_STRING']).symbolize_keys
29
36
  register_params(query, :dandy_query)
@@ -35,13 +42,13 @@ module Dandy
35
42
  chain_result = chain.execute
36
43
 
37
44
  if match.route.view
38
- body = @view_factory.create(match.route.view, content_type)
45
+ body = @view_factory.create(match.route.view, headers['Accept'])
39
46
  else
40
47
  body = chain_result.is_a?(String) ? chain_result : JSON.generate(chain_result)
41
48
  end
42
49
 
43
50
  status = @container.resolve(:dandy_status)
44
- result = [status, { 'Content-Type' => content_type }, [body]]
51
+ result = [status, {'Content-Type' => headers['Accept']}, [body]]
45
52
  end
46
53
 
47
54
  release
@@ -50,6 +57,7 @@ module Dandy
50
57
  end
51
58
 
52
59
  private
60
+
53
61
  def create_scope
54
62
  @container
55
63
  .register_instance(self, :dandy_request)
data/lib/dandy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dandy
2
- VERSION = '0.8.1'.freeze
2
+ VERSION = '0.9.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dandy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kalinkin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-25 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hypo