deas 0.41.0 → 0.42.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: 5e46a609344a9bab5fd5dd0aa922a7109258c2fb
4
- data.tar.gz: 6b809e7cc1cc9c9fbfdf17115f88f00e06adbe0a
3
+ metadata.gz: 1105d3943d8f80cbcfd722a4fd5796b015fb7e0c
4
+ data.tar.gz: 4847313602ffd9942d2b287f36052c0946e03c06
5
5
  SHA512:
6
- metadata.gz: 6a4dd5daee23f0ebd8ae06588a15330ffa0fb57ca59fcf8027c7db0b3c3d7f0aba97251ceb6b098c954cb47a56c8c0aaa72b19f612c4ebb6108dac31b4dc6585
7
- data.tar.gz: 53ab6f0f9d22a00248a4c3e195d3e553856d3e4cdd3e44f47d04c8d4c3343b3732761640b7e870f1d9d2d01004b61631e0999d3df02defbdbcf3908ef17e24ec
6
+ metadata.gz: 431fac2fe7deafdf9523882813e5caf34b57035b5077cf8152270503e6a0c914fa501015a47c5ead7d5c221d788e216389449a087c16167915ed82d769f9deab
7
+ data.tar.gz: 45cc5441925322a35fd7ad112ecf5b297113782ff14afb9d621b50735c6ee492ea163ec915e8b8cdef3d0b5da1d9653f0513f35a18aa8564855a6a9cf133b7a7
data/README.md CHANGED
@@ -22,7 +22,7 @@ class HellowWorldHandler
22
22
  include Deas::ViewHandler
23
23
 
24
24
  def run!
25
- "<h1>Hello World</h1>"
25
+ body "<h1>Hello World</h1>"
26
26
  end
27
27
 
28
28
  end
@@ -16,21 +16,28 @@ module Deas
16
16
  end
17
17
 
18
18
  def run(server_data, sinatra_call)
19
- # these are not part of Deas' intended behavior and route matching
20
- # they are side-effects of using Sinatra. remove them so they won't
19
+ # captures are not part of Deas' intended behavior and route matching
20
+ # they are a side-effects of using Sinatra. remove them so they won't
21
21
  # be relied upon in Deas apps.
22
- sinatra_call.params.delete(:splat)
23
- sinatra_call.params.delete('splat')
24
22
  sinatra_call.params.delete(:captures)
25
23
  sinatra_call.params.delete('captures')
26
24
 
25
+ # splat will be provided to the handlers via a special `splat` helper.
26
+ # only single splat values are allowed (see router `url` method). this
27
+ # takes the last splat value from Sinatra and provides it standalone to
28
+ # the runner.
29
+ splat_sym_param = sinatra_call.params.delete(:splat)
30
+ splat_string_param = sinatra_call.params.delete('splat')
31
+ splat_value = (splat_sym_param || splat_string_param || []).last
32
+
27
33
  runner = DeasRunner.new(self.handler_class, {
28
34
  :logger => server_data.logger,
29
35
  :router => server_data.router,
30
36
  :template_source => server_data.template_source,
31
37
  :request => sinatra_call.request,
32
38
  :session => sinatra_call.session,
33
- :params => sinatra_call.params
39
+ :params => sinatra_call.params,
40
+ :splat => splat_value
34
41
  })
35
42
 
36
43
  runner.request.env.tap do |env|
@@ -45,6 +52,7 @@ module Deas
45
52
  # this handles the verbose logging (it is a no-op if summary logging)
46
53
  env['deas.logging'].call " Handler: #{self.handler_class.name}"
47
54
  env['deas.logging'].call " Params: #{runner.params.inspect}"
55
+ env['deas.logging'].call " Splat: #{runner.splat.inspect}" if !runner.splat.nil?
48
56
  end
49
57
 
50
58
  runner.run
data/lib/deas/router.rb CHANGED
@@ -45,7 +45,11 @@ module Deas
45
45
  def url(name, path, options = nil)
46
46
  if !path.kind_of?(::String)
47
47
  raise ArgumentError, "invalid path `#{path.inspect}` - "\
48
- "can only provide a url name with String paths"
48
+ "named urls must be defined with String paths"
49
+ end
50
+ if path =~ /\*(?!$)/ # splat not at end of path
51
+ raise ArgumentError, "invalid path `#{path.inspect}` - "\
52
+ "named urls can only have a single splat at the end of the path"
49
53
  end
50
54
  add_url(name.to_sym, path, options || {})
51
55
  end
data/lib/deas/runner.rb CHANGED
@@ -15,7 +15,7 @@ module Deas
15
15
 
16
16
  attr_reader :handler_class, :handler
17
17
  attr_reader :logger, :router, :template_source
18
- attr_reader :request, :session, :params
18
+ attr_reader :request, :session, :params, :splat
19
19
 
20
20
  def initialize(handler_class, args = nil)
21
21
  @status, @headers, @body = nil, Rack::Utils::HeaderHash.new, nil
@@ -27,6 +27,7 @@ module Deas
27
27
  @request = args[:request]
28
28
  @session = args[:session]
29
29
  @params = args[:params] || {}
30
+ @splat = args[:splat]
30
31
 
31
32
  @handler_class = handler_class
32
33
  @handler = @handler_class.new(self)
@@ -28,7 +28,8 @@ module Deas
28
28
  :template_source => a.delete(:template_source),
29
29
  :request => a.delete(:request),
30
30
  :session => a.delete(:session),
31
- :params => NormalizedParams.new(a.delete(:params) || {}).value
31
+ :params => NormalizedParams.new(a.delete(:params) || {}).value,
32
+ :splat => a.delete(:splat)
32
33
  })
33
34
  a.each{|key, value| self.handler.send("#{key}=", value) }
34
35
 
data/lib/deas/url.rb CHANGED
@@ -23,7 +23,7 @@ module Deas
23
23
 
24
24
  h = params.dup # don't alter the given params
25
25
  c = h.delete(:captures) || h.delete('captures') || []
26
- s = h.delete(:splat) || h.delete('splat') || []
26
+ s = h.delete(:splat) || h.delete('splat') || nil
27
27
  a = h.delete(:'#') || h.delete('#') || nil
28
28
 
29
29
  # ignore captures when setting params
@@ -33,10 +33,8 @@ module Deas
33
33
 
34
34
  private
35
35
 
36
- def set_splat(path, params)
37
- params.inject(path) do |path_string, value|
38
- path_string.sub(/\*+/, value.to_s)
39
- end
36
+ def set_splat(path, value)
37
+ path.sub(/\*+/, value.to_s)
40
38
  end
41
39
 
42
40
  def set_named(path, params)
data/lib/deas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Deas
2
- VERSION = "0.41.0"
2
+ VERSION = "0.42.0"
3
3
  end
@@ -67,6 +67,7 @@ module Deas
67
67
  def request; @deas_runner.request; end
68
68
  def session; @deas_runner.session; end
69
69
  def params; @deas_runner.params; end
70
+ def splat; @deas_runner.splat; end
70
71
 
71
72
  # response
72
73
  def status(*args); @deas_runner.status(*args); end
@@ -38,11 +38,13 @@ class Deas::HandlerProxy
38
38
 
39
39
  Assert.stub(@proxy, :handler_class){ EmptyViewHandler }
40
40
 
41
- @server_data = Factory.server_data
42
- @fake_sinatra_call = Factory.sinatra_call
41
+ @server_data = Factory.server_data
42
+ @fake_sinatra_call = Factory.sinatra_call
43
+ @splat_sym_param = Factory.string
44
+ @splat_string_param = Factory.string
43
45
  @fake_sinatra_call.params = {
44
- :splat => Factory.string,
45
- 'splat' => Factory.string,
46
+ :splat => [@splat_sym_param],
47
+ 'splat' => [@splat_string_param],
46
48
  :captures => [Factory.string],
47
49
  'captures' => [Factory.string]
48
50
  }
@@ -65,13 +67,24 @@ class Deas::HandlerProxy
65
67
  :template_source => @server_data.template_source,
66
68
  :request => @fake_sinatra_call.request,
67
69
  :session => @fake_sinatra_call.session,
68
- :params => @fake_sinatra_call.params
70
+ :params => @fake_sinatra_call.params,
71
+ :splat => @splat_sym_param
69
72
  }
70
73
  assert_equal exp_args, @runner_spy.args
71
74
 
72
75
  assert_true @runner_spy.run_called
73
76
  end
74
77
 
78
+ should "prefer splat sym params over splat string params" do
79
+ assert_equal @splat_sym_param, @runner_spy.args[:splat]
80
+
81
+ @fake_sinatra_call.params['splat'] = [@splat_string_param]
82
+ proxy = Deas::HandlerProxy.new('EmptyViewHandler')
83
+ Assert.stub(proxy, :handler_class){ EmptyViewHandler }
84
+ proxy.run(@server_data, @fake_sinatra_call)
85
+ assert_equal @splat_string_param, @runner_spy.args[:splat]
86
+ end
87
+
75
88
  should "add data to the request env to make it available to Rack" do
76
89
  exp = subject.handler_class
77
90
  assert_equal exp, @fake_sinatra_call.request.env['deas.handler_class']
@@ -86,7 +99,8 @@ class Deas::HandlerProxy
86
99
  should "log the handler class name and the params" do
87
100
  exp_msgs = [
88
101
  " Handler: #{subject.handler_class.name}",
89
- " Params: #{@runner_spy.params.inspect}"
102
+ " Params: #{@runner_spy.params.inspect}",
103
+ " Splat: #{@runner_spy.splat.inspect}"
90
104
  ]
91
105
  assert_equal exp_msgs, @fake_sinatra_call.request.logging_msgs
92
106
  end
@@ -98,7 +112,7 @@ class Deas::HandlerProxy
98
112
  attr_reader :run_called
99
113
  attr_reader :handler_class, :handler, :args
100
114
  attr_reader :logger, :router, :template_source
101
- attr_reader :request, :session, :params
115
+ attr_reader :request, :session, :params, :splat
102
116
 
103
117
  def initialize
104
118
  @run_called = false
@@ -115,6 +129,7 @@ class Deas::HandlerProxy
115
129
  @request = args[:request]
116
130
  @session = args[:session]
117
131
  @params = args[:params]
132
+ @splat = args[:splat]
118
133
  end
119
134
 
120
135
  def run
@@ -402,6 +402,27 @@ class Deas::Router
402
402
  end
403
403
  end
404
404
 
405
+ should "complain if defining a url with invalid splats" do
406
+ assert_raises ArgumentError do
407
+ subject.url(:get_info, "/something/*/other/*")
408
+ end
409
+ assert_raises ArgumentError do
410
+ subject.url(:get_info, "/something/*/other")
411
+ end
412
+ assert_raises ArgumentError do
413
+ subject.url(:get_info, "/something/*/")
414
+ end
415
+ assert_raises ArgumentError do
416
+ subject.url(:get_info, "/*/something")
417
+ end
418
+ assert_nothing_raised do
419
+ subject.url(:get_info, "/something/*")
420
+ end
421
+ assert_nothing_raised do
422
+ subject.url(:get_info, "/*")
423
+ end
424
+ end
425
+
405
426
  should "build a path for a url given params" do
406
427
  exp_path = subject.prepend_base_url("/info/now")
407
428
  assert_equal exp_path, subject.url_for(:get_info, :for => 'now')
@@ -45,7 +45,7 @@ class Deas::Runner
45
45
 
46
46
  should have_readers :handler_class, :handler
47
47
  should have_readers :logger, :router, :template_source
48
- should have_readers :request, :session, :params
48
+ should have_readers :request, :session, :params, :splat
49
49
  should have_imeths :run, :to_rack
50
50
  should have_imeths :status, :headers, :body, :content_type
51
51
  should have_imeths :halt, :redirect, :send_file
@@ -75,7 +75,8 @@ class Deas::Runner
75
75
  :template_source => 'a-source',
76
76
  :request => 'a-request',
77
77
  :session => 'a-session',
78
- :params => {}
78
+ :params => {},
79
+ :splat => 'a-splat'
79
80
  }
80
81
 
81
82
  runner = @runner_class.new(@handler_class, args)
@@ -86,6 +87,7 @@ class Deas::Runner
86
87
  assert_equal args[:request], runner.request
87
88
  assert_equal args[:session], runner.session
88
89
  assert_equal args[:params], runner.params
90
+ assert_equal args[:splat], runner.splat
89
91
  end
90
92
 
91
93
  should "not implement its run method" do
@@ -35,6 +35,7 @@ class Deas::TestRunner
35
35
  :request => @request,
36
36
  :session => Factory.string,
37
37
  :params => @params,
38
+ :splat => Factory.path,
38
39
  :custom_value => Factory.integer
39
40
  }
40
41
 
@@ -63,6 +64,7 @@ class Deas::TestRunner
63
64
  assert_equal @args[:request], subject.request
64
65
  assert_equal @args[:session], subject.session
65
66
  assert_equal @args[:params], subject.params
67
+ assert_equal @args[:splat], subject.splat
66
68
  end
67
69
 
68
70
  should "call to normalize its params" do
@@ -59,31 +59,31 @@ class Deas::Url
59
59
  class PathForTests < InitTests
60
60
  desc "when generating paths"
61
61
  setup do
62
- @url = Deas::Url.new(:some_thing, '/:some/:thing/*/*')
63
- @url_with_escape = Deas::Url.new(:some_thing, '/:some/:thing/*/*', {
62
+ @url = Deas::Url.new(:some_thing, '/:some/:thing/*')
63
+ @url_with_escape = Deas::Url.new(:some_thing, '/:some/:thing/*', {
64
64
  :escape_query_value => proc{ |v| Rack::Utils.escape(v) }
65
65
  })
66
66
  end
67
67
 
68
68
  should "generate given named params only" do
69
- exp_path = "/a/goose/*/*"
69
+ exp_path = '/a/goose/'
70
70
  assert_equal exp_path, subject.path_for({
71
71
  'some' => 'a',
72
72
  :thing => 'goose'
73
73
  })
74
74
 
75
- exp_path = "/a/goose/cooked-well/*"
75
+ exp_path = '/a/goose/cooked'
76
76
  assert_equal exp_path, subject.path_for({
77
77
  'some' => 'a',
78
78
  :thing => 'goose',
79
- :splat => ['cooked-well']
79
+ :splat => 'cooked'
80
80
  })
81
81
 
82
- exp_path = "/a/goose/cooked/well"
82
+ exp_path = '/a/goose/cooked'
83
83
  assert_equal exp_path, subject.path_for({
84
84
  'some' => 'a',
85
85
  :thing => 'goose',
86
- 'splat' => ['cooked', 'well']
86
+ 'splat' => 'cooked'
87
87
  })
88
88
  end
89
89
 
@@ -105,95 +105,86 @@ class Deas::Url
105
105
  end
106
106
 
107
107
  should "not complain if given empty splat param values" do
108
- exp_path = "/a/goose/"
108
+ exp_path = '/a/goose/'
109
109
  assert_equal exp_path, subject.path_for({
110
110
  'some' => 'a',
111
111
  :thing => 'goose',
112
- 'splat' => [nil, '']
112
+ 'splat' => [nil, ''].sample
113
113
  })
114
114
  end
115
115
 
116
116
  should "append other (additional) params as query params" do
117
- exp_path = "/a/goose/cooked/well?aye=a&bee=b"
117
+ exp_path = '/a/goose/cooked?aye=a&bee=b'
118
118
  assert_equal exp_path, subject.path_for({
119
119
  'some' => 'a',
120
120
  :thing => 'goose',
121
- 'splat' => ['cooked', 'well'],
121
+ 'splat' => 'cooked',
122
122
  'bee' => 'b',
123
123
  :aye => 'a'
124
124
  })
125
125
  end
126
126
 
127
127
  should "escape query values when built with an escape query value proc" do
128
- exp_path = "/a/goose/cooked/well?aye=a?a&a"
128
+ exp_path = '/a/goose/cooked?aye=a?a&a'
129
129
  assert_equal exp_path, subject.path_for({
130
130
  'some' => 'a',
131
131
  :thing => 'goose',
132
- 'splat' => ['cooked', 'well'],
132
+ 'splat' => 'cooked',
133
133
  :aye => 'a?a&a'
134
134
  })
135
135
 
136
- exp_path = "/a/goose/cooked/well?aye=a%3Fa%26a"
136
+ exp_path = "/a/goose/cooked?aye=a%3Fa%26a"
137
137
  assert_equal exp_path, @url_with_escape.path_for({
138
138
  'some' => 'a',
139
139
  :thing => 'goose',
140
- 'splat' => ['cooked', 'well'],
140
+ 'splat' => 'cooked',
141
141
  :aye => 'a?a&a'
142
142
  })
143
143
  end
144
144
 
145
145
  should "ignore any 'captures'" do
146
- exp_path = "/a/goose/cooked/well"
146
+ exp_path = '/a/goose/cooked'
147
147
  assert_equal exp_path, subject.path_for({
148
- 'some' => 'a',
149
- :thing => 'goose',
150
- 'splat' => ['cooked', 'well'],
148
+ 'some' => 'a',
149
+ :thing => 'goose',
150
+ 'splat' => 'cooked',
151
151
  'captures' => 'some-captures'
152
152
  })
153
153
  end
154
154
 
155
155
  should "append anchors" do
156
- exp_path = "/a/goose/cooked/well#an-anchor"
156
+ exp_path = '/a/goose/cooked#an-anchor'
157
157
  assert_equal exp_path, subject.path_for({
158
158
  'some' => 'a',
159
159
  :thing => 'goose',
160
- 'splat' => ['cooked', 'well'],
160
+ 'splat' => 'cooked',
161
161
  '#' => 'an-anchor'
162
162
  })
163
163
  end
164
164
 
165
165
  should "ignore empty anchors" do
166
- exp_path = "/a/goose/cooked/well"
167
- assert_equal exp_path, subject.path_for({
168
- 'some' => 'a',
169
- :thing => 'goose',
170
- 'splat' => ['cooked', 'well'],
171
- '#' => nil
172
- })
173
-
174
- exp_path = "/a/goose/cooked/well"
166
+ exp_path = '/a/goose/cooked'
175
167
  assert_equal exp_path, subject.path_for({
176
168
  'some' => 'a',
177
169
  :thing => 'goose',
178
- 'splat' => ['cooked', 'well'],
179
- '#' => ''
170
+ 'splat' => 'cooked',
171
+ '#' => [nil, ''].sample
180
172
  })
181
173
  end
182
174
 
183
175
  should "'squash' duplicate forward-slashes" do
184
- exp_path = "/a/goose/cooked/well/"
176
+ exp_path = '/a/goose/cooked'
185
177
  assert_equal exp_path, subject.path_for({
186
178
  'some' => '/a',
187
179
  :thing => '/goose',
188
- 'splat' => ['///cooked', 'well//']
180
+ 'splat' => '///cooked'
189
181
  })
190
182
  end
191
183
 
192
184
  should "not alter the given params" do
193
185
  params = {
194
186
  'some' => 'thing',
195
- :captures => ['captures'],
196
- :splat => ['splat'],
187
+ :splat => 'splat',
197
188
  '#' => 'anchor'
198
189
  }
199
190
  exp_params = params.dup
@@ -242,6 +242,11 @@ module Deas::ViewHandler
242
242
  assert_equal @runner.params, subject.instance_eval{ params }
243
243
  end
244
244
 
245
+ should "call to the runner for its splat" do
246
+ stub_runner_with_something_for(:splat)
247
+ assert_equal @runner.splat, subject.instance_eval{ splat }
248
+ end
249
+
245
250
  should "call to the runner for its status helper" do
246
251
  capture_runner_meth_args_for(:status)
247
252
  exp_args = @args
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.41.0
4
+ version: 0.42.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2016-06-15 00:00:00 Z
13
+ date: 2016-09-01 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: assert