dandy 0.9.1 → 0.10.0

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: c2fd9c19d371ae8e4a1a1f1bc226cc1129378b4a
4
- data.tar.gz: b80c233a419271a93c8f7fd4e012c0bfc73b48ef
3
+ metadata.gz: f200ac79d319f41022b6dbc1bbcaa1657a96a092
4
+ data.tar.gz: 1eee9c46e08a02edea020dd83e34634363cdd6ed
5
5
  SHA512:
6
- metadata.gz: cbae69a185816a195b1f9c62aa3586ebea47ee9135d5c4abef5626dd40c914610fa68d301e8c56805aad7572712365e5c01420900cee1d9793d173fc22f8e660
7
- data.tar.gz: 13b588f96bbc72e5f6a6457a57bfd1fa54baa2d1a45ff88b507b11fb1b2f0cc1ff614d06244db27c36df9d16f01e1039ad1542233383ba2e8232540c07742ece
6
+ metadata.gz: 3d9081931b3bd4ae5e1efa3e7a3474d7e07d6055077f4e5785775fb2773c3377485c6d42f989c206da698cc2779d08689baf12171f0090d77bfc102471603ea8
7
+ data.tar.gz: e4e59de3570dfceba866f133a62eb195e537612650599dcc916e02e4a9f21ab0b9aa4837f0962682c697f56e78e8f3df75843ae1192caf81d87cae8d67020eec
data/dandy.gemspec CHANGED
@@ -37,6 +37,8 @@ Gem::Specification.new do |spec|
37
37
  spec.add_dependency 'jbuilder', '~> 2.7.0'
38
38
  spec.add_dependency 'rack-parser', '~> 0.7.0'
39
39
  spec.add_dependency 'terminal-table', '~> 1.8.0'
40
+ spec.add_dependency 'awrence', '~> 1.0.0'
41
+ spec.add_dependency 'plissken', '~> 1.2.0'
40
42
 
41
43
  spec.add_development_dependency 'bundler', '~> 1.15'
42
44
  spec.add_development_dependency 'rake', '~> 10.0'
data/lib/dandy/request.rb CHANGED
@@ -2,6 +2,8 @@ require 'json'
2
2
  require 'dandy/extensions/hash'
3
3
  require 'dandy/chain_factory'
4
4
  require 'dandy/view_factory'
5
+ require 'awrence'
6
+ require 'plissken'
5
7
 
6
8
  module Dandy
7
9
  class Request
@@ -32,19 +34,27 @@ module Dandy
32
34
  if match.nil?
33
35
  result = [404, {'Content-Type' => headers['Accept']}, []]
34
36
  else
35
- query = Rack::Utils.parse_nested_query(rack_env['QUERY_STRING']).symbolize_keys
37
+ query = Rack::Utils.parse_nested_query(rack_env['QUERY_STRING']).to_snake_keys.symbolize_keys
36
38
  register_params(query, :dandy_query)
37
39
 
38
- data = rack_env['rack.parser.result'] ? rack_env['rack.parser.result'].deep_symbolize_keys! : nil
40
+ data = rack_env['rack.parser.result'] ? rack_env['rack.parser.result'].to_snake_keys.deep_symbolize_keys! : nil
39
41
  register_params(data, :dandy_data)
40
42
 
41
43
  chain = @chain_factory.create(match)
42
44
  chain_result = chain.execute
43
45
 
44
46
  if match.route.view
45
- body = @view_factory.create(match.route.view, headers['Accept'])
47
+ body = @view_factory.create(match.route.view, headers['Accept'], {keys_format: headers['Keys-Format'] || 'snake'})
46
48
  else
47
- body = chain_result.is_a?(String) ? chain_result : JSON.generate(chain_result)
49
+ if chain_result.is_a?(String)
50
+ body = chain_result
51
+ else # generate JSON when nothing other is requested
52
+ if headers['Keys-Format'] == 'camel'
53
+ chain_result = chain_result.to_camelback_keys
54
+ end
55
+
56
+ body = JSON.generate(chain_result)
57
+ end
48
58
  end
49
59
 
50
60
  status = @container.resolve(:dandy_status)
data/lib/dandy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dandy
2
- VERSION = '0.9.1'.freeze
2
+ VERSION = '0.10.0'.freeze
3
3
  end
@@ -1,9 +1,10 @@
1
1
  module Dandy
2
2
  class ViewBuilder
3
- def initialize(template, container)
3
+ def initialize(template, container, options)
4
4
  @template = template
5
5
  @container = container
6
6
  @variables = template.scan(/@[a-z_][a-zA-Z_0-9]*/).uniq
7
+ @options = options
7
8
  end
8
9
 
9
10
  def process
@@ -6,6 +6,10 @@ module Dandy
6
6
  class Json < Dandy::ViewBuilder
7
7
  def build
8
8
  result = Jbuilder.new do |json|
9
+ if @options[:keys_format] == 'camel'
10
+ json.key_format! camelize: :lower
11
+ end
12
+
9
13
  eval(@template)
10
14
  end
11
15
 
@@ -10,11 +10,11 @@ module Dandy
10
10
  @view_builder_registry = view_builder_registry
11
11
  end
12
12
 
13
- def create(name, content_type)
13
+ def create(name, content_type, options = {})
14
14
  type = content_type.split('/')[1]
15
15
  template = @template_registry.get(name, type)
16
16
  builder = @view_builder_registry.get(type)
17
- view = builder.new(template, @container)
17
+ view = builder.new(template, @container, options)
18
18
  view.process
19
19
  end
20
20
  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.9.1
4
+ version: 0.10.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-29 00:00:00.000000000 Z
11
+ date: 2018-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hypo
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.8.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: awrence
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.0.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: plissken
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.2.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.2.0
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: bundler
113
141
  requirement: !ruby/object:Gem::Requirement