roda 2.9.0 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +10 -0
  3. data/MIT-LICENSE +1 -1
  4. data/doc/release_notes/2.10.0.txt +27 -0
  5. data/lib/roda.rb +2 -0
  6. data/lib/roda/plugins/_erubis_escaping.rb +2 -0
  7. data/lib/roda/plugins/all_verbs.rb +2 -0
  8. data/lib/roda/plugins/assets.rb +3 -1
  9. data/lib/roda/plugins/backtracking_array.rb +2 -0
  10. data/lib/roda/plugins/caching.rb +2 -0
  11. data/lib/roda/plugins/chunked.rb +3 -1
  12. data/lib/roda/plugins/class_level_routing.rb +2 -0
  13. data/lib/roda/plugins/content_for.rb +3 -1
  14. data/lib/roda/plugins/cookies.rb +2 -0
  15. data/lib/roda/plugins/csrf.rb +2 -0
  16. data/lib/roda/plugins/default_headers.rb +2 -0
  17. data/lib/roda/plugins/default_status.rb +2 -0
  18. data/lib/roda/plugins/delay_build.rb +2 -0
  19. data/lib/roda/plugins/delegate.rb +2 -0
  20. data/lib/roda/plugins/delete_empty_headers.rb +2 -0
  21. data/lib/roda/plugins/drop_body.rb +2 -0
  22. data/lib/roda/plugins/empty_root.rb +2 -0
  23. data/lib/roda/plugins/environments.rb +2 -0
  24. data/lib/roda/plugins/error_email.rb +4 -1
  25. data/lib/roda/plugins/error_handler.rb +2 -0
  26. data/lib/roda/plugins/flash.rb +2 -0
  27. data/lib/roda/plugins/h.rb +2 -0
  28. data/lib/roda/plugins/halt.rb +2 -0
  29. data/lib/roda/plugins/hash_matcher.rb +2 -0
  30. data/lib/roda/plugins/head.rb +2 -0
  31. data/lib/roda/plugins/header_matchers.rb +2 -0
  32. data/lib/roda/plugins/heartbeat.rb +2 -0
  33. data/lib/roda/plugins/hooks.rb +2 -0
  34. data/lib/roda/plugins/indifferent_params.rb +2 -0
  35. data/lib/roda/plugins/json.rb +12 -3
  36. data/lib/roda/plugins/json_parser.rb +2 -0
  37. data/lib/roda/plugins/mailer.rb +2 -0
  38. data/lib/roda/plugins/match_affix.rb +2 -0
  39. data/lib/roda/plugins/middleware.rb +2 -0
  40. data/lib/roda/plugins/module_include.rb +2 -0
  41. data/lib/roda/plugins/multi_route.rb +2 -0
  42. data/lib/roda/plugins/multi_run.rb +2 -0
  43. data/lib/roda/plugins/multi_view.rb +2 -0
  44. data/lib/roda/plugins/named_templates.rb +2 -0
  45. data/lib/roda/plugins/not_allowed.rb +2 -0
  46. data/lib/roda/plugins/not_found.rb +2 -0
  47. data/lib/roda/plugins/padrino_render.rb +2 -0
  48. data/lib/roda/plugins/param_matchers.rb +2 -0
  49. data/lib/roda/plugins/partials.rb +2 -0
  50. data/lib/roda/plugins/pass.rb +2 -0
  51. data/lib/roda/plugins/path.rb +2 -0
  52. data/lib/roda/plugins/path_matchers.rb +2 -0
  53. data/lib/roda/plugins/path_rewriter.rb +2 -0
  54. data/lib/roda/plugins/per_thread_caching.rb +2 -0
  55. data/lib/roda/plugins/precompile_templates.rb +2 -0
  56. data/lib/roda/plugins/render.rb +2 -0
  57. data/lib/roda/plugins/render_each.rb +2 -0
  58. data/lib/roda/plugins/response_request.rb +2 -0
  59. data/lib/roda/plugins/run_handler.rb +2 -0
  60. data/lib/roda/plugins/shared_vars.rb +2 -0
  61. data/lib/roda/plugins/sinatra_helpers.rb +2 -0
  62. data/lib/roda/plugins/slash_path_empty.rb +2 -0
  63. data/lib/roda/plugins/static.rb +2 -0
  64. data/lib/roda/plugins/status_handler.rb +2 -0
  65. data/lib/roda/plugins/streaming.rb +8 -1
  66. data/lib/roda/plugins/symbol_matchers.rb +2 -0
  67. data/lib/roda/plugins/symbol_views.rb +2 -0
  68. data/lib/roda/plugins/view_options.rb +2 -0
  69. data/lib/roda/plugins/websockets.rb +2 -0
  70. data/lib/roda/version.rb +1 -1
  71. data/spec/opts_spec.rb +1 -1
  72. data/spec/plugin/chunked_spec.rb +1 -1
  73. data/spec/plugin/json_spec.rb +14 -0
  74. data/spec/plugin/sinatra_helpers_spec.rb +2 -3
  75. data/spec/plugin/streaming_spec.rb +2 -2
  76. data/spec/plugin/websockets_spec.rb +3 -0
  77. data/spec/session_spec.rb +1 -1
  78. data/spec/spec_helper.rb +2 -2
  79. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db1595b9c872a259412f3038f5a0fb2840eeb3cf
4
- data.tar.gz: f2b1ccafbdbbe5555ba7267aaa51711be0ea0f4e
3
+ metadata.gz: f294c5f09434c3db4c5c1e8f883071a1381b398c
4
+ data.tar.gz: bfa22f2e6fdb5bf030dd9bcdb74cc130ac42e005
5
5
  SHA512:
6
- metadata.gz: 584b93e1c7fad7764b37835c5a902ae0fa6549eadd180792db2cdb8bcd6ddcccf6e1c0292e3962e0960e5f491dae6807308f76534a9e51f66698b62e3d794def
7
- data.tar.gz: 47869cb66d33806d615dae3046dd0b372532811c00456c839e781d5e57912dcec6c09161f8802a66a37d401fa4dd685dc00327ce1389555ce20dee84419d406b
6
+ metadata.gz: 62058ce501a97f2f4ce334d8a00b24a922f19545f414978b986e840a8b722bff80878c7998fe3c6403f326183341dffca76b894c598dbfd1c5024e02844aed76
7
+ data.tar.gz: 87256dacdf54f10450ed05a2e750e6c312b224f53039175faf34a7084539097d916cd91785abd71be678db96f63c489c6b6d2f1ebca40a1299627cf9f5a9a77b
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ = 2.10.0 (2016-01-15)
2
+
3
+ * Do not override existing Content-Type header in json plugin (jeremyevans)
4
+
5
+ * Add :content_type option to json plugin to override Content-Type header used (Kyrremann) (#58)
6
+
7
+ * Add support for running with --enable-frozen-string-literal on ruby 2.3 (jeremyevans)
8
+
9
+ * Add Streaming::Stream#write method so that IO.copy_stream will work (janko-m) (#56)
10
+
1
11
  = 2.9.0 (2015-12-15)
2
12
 
3
13
  * Support passing the content as a string argument instead of a block in the content_for plugin (badosu) (#52)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2015 Jeremy Evans
1
+ Copyright (c) 2014-2016 Jeremy Evans
2
2
  Copyright (c) 2010-2014 Michel Martens, Damian Janowski and Cyril David
3
3
  Copyright (c) 2008-2009 Christian Neukirchen
4
4
 
@@ -0,0 +1,27 @@
1
+ = New Features
2
+
3
+ * The json plugin now accepts a :content_type option, which will
4
+ override the default Content-Type response header used for
5
+ responses.
6
+
7
+ * Stream#write has been added to the streaming plugin, allowing
8
+ the following type of code to work:
9
+
10
+ stream do |out|
11
+ IO.copy_stream(StringIO.new(content), out)
12
+ end
13
+
14
+ = Other Improvements
15
+
16
+ * Roda now works with ruby 2.3's --enable-frozen-string-literal,
17
+ and all of the library files are set to use frozen string
18
+ literals by default.
19
+
20
+ Most of roda's plugin-specific dependencies were found to have
21
+ issues with frozen string literals, and while pull requests have
22
+ been sent to fix the issues, it's unlikely that you would
23
+ currently be able to use --enable-frozen-string-literal in
24
+ production.
25
+
26
+ * The json plugin will no longer override a Content-Type header if
27
+ one is already set.
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  require "rack"
2
4
  require "thread"
3
5
  require "roda/version"
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  require 'erubis'
2
4
 
3
5
  class Roda
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The all_verbs plugin adds methods for http verbs other than
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The assets plugin adds support for rendering your CSS and javascript
@@ -614,7 +616,7 @@ class Roda
614
616
 
615
617
  if o[:gzip] && env[HTTP_ACCEPT_ENCODING] =~ /\bgzip\b/
616
618
  @_response[CONTENT_ENCODING] = GZIP
617
- file << DOTGZ
619
+ file += DOTGZ
618
620
  end
619
621
 
620
622
  check_asset_request(file, type, ::File.stat(file).mtime)
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The backtracking_array plugin changes the handling of array
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The caching plugin adds methods related to HTTP caching.
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The chunked plugin allows you to stream responses to clients using
@@ -265,7 +267,7 @@ class Roda
265
267
  # of the response.
266
268
  @_flusher = lambda do
267
269
  yield @_out_buf
268
- @_out_buf = ''
270
+ @_out_buf = String.new
269
271
  end
270
272
 
271
273
  if layout_opts = view_layout_opts(opts)
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The class_level_routing plugin adds routing methods at the class level, which can
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The content_for plugin is designed to be used with the
@@ -40,7 +42,7 @@ class Roda
40
42
  outvar = render_opts[:template_opts][:outvar]
41
43
  buf_was = instance_variable_get(outvar)
42
44
  # clean the output buffer for ERB-based rendering systems
43
- instance_variable_set(outvar, '')
45
+ instance_variable_set(outvar, String.new)
44
46
 
45
47
  @_content_for ||= {}
46
48
  @_content_for[key] = Tilt[render_opts[:engine]].new(&block).render
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The cookies plugin adds response methods for handling cookies.
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  require 'rack/csrf'
2
4
 
3
5
  class Roda
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The default_headers plugin accepts a hash of headers,
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The default_status plugin accepts a block which should
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The delay_build plugin does not build the rack app until
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The delegate plugin allows you to easily setup instance methods in
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The delete_empty_headers plugin deletes any headers whose
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The drop_body plugin automatically drops the body and
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The empty_root plugin makes +r.root+ match both on +/+ and
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The environments plugin adds a environment class accessor to get
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  require 'net/smtp'
2
4
 
3
5
  class Roda
@@ -41,7 +43,8 @@ class Roda
41
43
  :body=>lambda do |s, e|
42
44
  format = lambda{|h| h.map{|k, v| "#{k.inspect} => #{v.inspect}"}.sort.join("\n")}
43
45
 
44
- message = <<END
46
+ message = String.new
47
+ message << <<END
45
48
  Path: #{s.request.path}
46
49
 
47
50
  Backtrace:
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The error_handler plugin adds an error handler to the routing,
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  require 'delegate'
2
4
 
3
5
  class Roda
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The h plugin adds an +h+ instance method that will HTML
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The halt plugin augments the standard request +halt+ method to allow the response
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The hash_matcher plugin adds the hash_matcher class method, which
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The head plugin attempts to automatically handle HEAD requests,
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The header_matchers plugin adds hash matchers for matching on less-common
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The heartbeat handles heartbeat/status requests. If a request for
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The hooks plugin adds before and after hooks to the request cycle.
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The indifferent_params plugin adds a +params+ instance
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  require 'json'
2
4
 
3
5
  class Roda
@@ -44,10 +46,16 @@ class Roda
44
46
  # +:include_request+ option, which will pass in the request
45
47
  # object as the second argument when calling the serializer.
46
48
  #
47
- # plugin :json, include_request=>true, serializer=>proc{|o, request| ...}
49
+ # plugin :json, :include_request=>true, :serializer=>proc{|o, request| ...}
50
+ #
51
+ # The default content-type is 'application/json', but you can change that
52
+ # using the +:content_type+ option:
53
+ #
54
+ # plugin :json, :content_type=>'application/xml'
48
55
  module Json
49
56
  OPTS = {}.freeze
50
57
  DEFAULT_SERIALIZER = lambda{|o| o.to_json}
58
+ DEFAULT_CONTENT_TYPE = 'application/json'.freeze
51
59
 
52
60
  # Set the classes to automatically convert to JSON, and the serializer to use.
53
61
  def self.configure(app, opts=OPTS)
@@ -60,6 +68,8 @@ class Roda
60
68
  app.opts[:json_result_serializer] = opts[:serializer] || app.opts[:json_result_serializer] || DEFAULT_SERIALIZER
61
69
 
62
70
  app.opts[:json_result_include_request] = opts[:include_request] || app.opts[:json_result_include_request]
71
+
72
+ app.opts[:json_result_content_type] = opts[:content_type] || DEFAULT_CONTENT_TYPE
63
73
  end
64
74
 
65
75
  module ClassMethods
@@ -71,7 +81,6 @@ class Roda
71
81
 
72
82
  module RequestMethods
73
83
  CONTENT_TYPE = 'Content-Type'.freeze
74
- APPLICATION_JSON = 'application/json'.freeze
75
84
 
76
85
  private
77
86
 
@@ -81,7 +90,7 @@ class Roda
81
90
  def block_result_body(result)
82
91
  case result
83
92
  when *roda_class.json_result_classes
84
- response[CONTENT_TYPE] = APPLICATION_JSON
93
+ response[CONTENT_TYPE] ||= roda_class.opts[:json_result_content_type]
85
94
  convert_to_json(result)
86
95
  else
87
96
  super
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  require 'json'
2
4
 
3
5
  class Roda
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  require 'stringio'
2
4
  require 'mail'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The match_affix plugin allows changing the default prefix and suffix used for
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The middleware plugin allows the Roda app to be used as
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The module_include plugin adds request_module and response_module class methods
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The multi_route plugin allows for multiple named routes, which the
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The multi_run plugin provides the ability to easily dispatch to other
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The multi_view plugin makes it easy to render multiple views, where the
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The named_templates plugin allows you to specify templates by name,
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The not_allowed plugin makes Roda attempt to automatically
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The not_found plugin adds a +not_found+ class method which sets
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The padrino_render plugin adds rendering support that is
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The param_matchers plugin adds hash matchers that operate
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The partials plugin adds a +partial+ method, which renders
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The pass plugin adds a request +pass+ method to skip the current match
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The path plugin adds support for named paths. Using the +path+ class method, you can
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The path_matchers plugin adds hash matchers that operate
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The path_rewriter plugin allows you to rewrite the remaining path
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The per_thread_caching plugin changes the default cache
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The precompile_templates plugin adds support for precompiling template code.
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  require "tilt"
2
4
 
3
5
  class Roda
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The render_each plugin allows you to render a template for each
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The response_request plugin gives the response access to the
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The run_handler plugin allows r.run to take a block, which is yielded
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The shared_vars plugin adds a shared method for storing
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The sinatra_helpers plugin ports most of the helper methods
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The slash_path_empty plugin considers "/" as an empty path,
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The static plugin loads the Rack::Static middleware into the application.
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The status_handler plugin adds a +status_handler+ method which sets a
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The streaming plugin adds support for streaming responses
@@ -100,11 +102,16 @@ class Roda
100
102
  end
101
103
 
102
104
  # Add output to the streaming response body.
103
- def <<(data)
105
+ def write(data)
104
106
  @scheduler.schedule{@front.call(data.to_s)}
105
107
  self
106
108
  end
107
109
 
110
+ # Alias for +write+.
111
+ def <<(data)
112
+ write(data)
113
+ end
114
+
108
115
  # Add the given block as a callback to call when the block closes.
109
116
  def callback(&block)
110
117
  return yield if closed?
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The symbol_matchers plugin allows you do define custom regexps to use
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The symbol_views plugin allows match blocks to return
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  class Roda
2
4
  module RodaPlugins
3
5
  # The view_options plugin allows you to override view and layout
@@ -1,3 +1,5 @@
1
+ # frozen-string-literal: true
2
+
1
3
  require 'faye/websocket'
2
4
 
3
5
  class Roda
@@ -4,7 +4,7 @@ class Roda
4
4
  RodaMajorVersion = 2
5
5
 
6
6
  # The minor version of Roda, updated for new feature releases of Roda.
7
- RodaMinorVersion = 9
7
+ RodaMinorVersion = 10
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
@@ -30,7 +30,7 @@ describe "opts" do
30
30
 
31
31
  it "should only shallow clone by default" do
32
32
  c = Class.new(Roda)
33
- c.opts[:foo] = "bar"
33
+ c.opts[:foo] = "bar".dup
34
34
  c.opts[:foo].must_equal "bar"
35
35
 
36
36
  sc = Class.new(c)
@@ -45,7 +45,7 @@ describe "chunked plugin" do
45
45
  delay do
46
46
  @h << 'i'
47
47
  end
48
- @h = 'h'
48
+ @h = String.new('h')
49
49
  chunked(:inline=>'m<%= @h %>', :layout=>{:inline=>'<%= @h %><%= yield %>t'}) do
50
50
  @h << 'j'
51
51
  end
@@ -23,6 +23,11 @@ describe "json plugin" do
23
23
  r.is 'c' do
24
24
  c.new
25
25
  end
26
+
27
+ r.is 'd' do
28
+ response['Content-Type'] = 'foo'
29
+ c.new
30
+ end
26
31
  end
27
32
  end
28
33
  end
@@ -34,6 +39,10 @@ describe "json plugin" do
34
39
  header('Content-Type').must_equal 'text/html'
35
40
  end
36
41
 
42
+ it "should not override existing content type for a json response" do
43
+ header('Content-Type', "/d").must_equal 'foo'
44
+ end
45
+
37
46
  it "should convert objects to json" do
38
47
  body('/array').gsub(/\s/, '').must_equal '[1,2,3]'
39
48
  body('/hash').gsub(/\s/, '').must_equal '{"a":"b"}'
@@ -59,4 +68,9 @@ describe "json plugin" do
59
68
 
60
69
  body("/hash").must_equal 'b:/hash'
61
70
  end
71
+
72
+ it "should allow custom content type for a response" do
73
+ app.plugin :json, :content_type => "application/xml"
74
+ header('Content-Type', "/array").must_equal 'application/xml'
75
+ end
62
76
  end
@@ -235,7 +235,6 @@ describe "sinatra_helpers plugin" do
235
235
  it "looks up mime types in Rack's MIME registry" do
236
236
  Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
237
237
  body('foo').must_equal 'application/foo'
238
- body(:foo).must_equal 'application/foo'
239
238
  body('.foo').must_equal 'application/foo'
240
239
  end
241
240
 
@@ -252,8 +251,8 @@ describe "sinatra_helpers plugin" do
252
251
  end
253
252
 
254
253
  it 'supports mime types registered at the class level' do
255
- app.mime_type :foo, 'application/foo'
256
- body(:foo).must_equal 'application/foo'
254
+ app.mime_type :foo, 'application/foo2'
255
+ body('foo').must_equal 'application/foo2'
257
256
  end
258
257
  end
259
258
 
@@ -4,14 +4,14 @@ describe "streaming plugin" do
4
4
  it "adds stream method for streaming responses" do
5
5
  app(:streaming) do |r|
6
6
  stream do |out|
7
- %w'a b c'.each{|v| out << v}
7
+ %w'a b c'.each{|v| out << v; out.write(v) }
8
8
  end
9
9
  end
10
10
 
11
11
  s, h, b = req
12
12
  s.must_equal 200
13
13
  h.must_equal('Content-Type'=>'text/html')
14
- b.to_a.must_equal %w'a b c'
14
+ b.to_a.must_equal %w'a a b b c c'
15
15
  end
16
16
 
17
17
  it "should handle errors when streaming, and run callbacks" do
@@ -43,6 +43,8 @@ describe "websockets plugin" do
43
43
  @port = 9791
44
44
  q = Queue.new
45
45
  Thread.new do
46
+ #$DEBUG=true
47
+ #Thin::Logging.trace = true
46
48
  Thin::Logging.silent = true
47
49
  Rack::Handler.get('thin').run(app, :Port => @port) do |s|
48
50
  @server = s
@@ -52,6 +54,7 @@ describe "websockets plugin" do
52
54
  q.pop
53
55
  end
54
56
  after do
57
+ #$DEBUG=nil
55
58
  @server.stop
56
59
  end
57
60
 
@@ -19,7 +19,7 @@ describe "session handling" do
19
19
 
20
20
  route do |r|
21
21
  r.on do
22
- (session[1] ||= 'a') << 'b'
22
+ (session[1] ||= 'a'.dup) << 'b'
23
23
  session[1]
24
24
  end
25
25
  end
@@ -47,7 +47,7 @@ class Minitest::Spec
47
47
  if path.is_a?(Hash)
48
48
  env = path
49
49
  else
50
- env['PATH_INFO'] = path
50
+ env['PATH_INFO'] = path.dup
51
51
  end
52
52
 
53
53
  env = {"REQUEST_METHOD" => "GET", "PATH_INFO" => "/", "SCRIPT_NAME" => ""}.merge(env)
@@ -63,7 +63,7 @@ class Minitest::Spec
63
63
  end
64
64
 
65
65
  def body(path='/', env={})
66
- s = ''
66
+ s = String.new
67
67
  b = req(path, env)[2]
68
68
  b.each{|x| s << x}
69
69
  b.close if b.respond_to?(:close)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-15 00:00:00.000000000 Z
11
+ date: 2016-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -175,6 +175,7 @@ extra_rdoc_files:
175
175
  - doc/release_notes/2.7.0.txt
176
176
  - doc/release_notes/2.8.0.txt
177
177
  - doc/release_notes/2.9.0.txt
178
+ - doc/release_notes/2.10.0.txt
178
179
  files:
179
180
  - CHANGELOG
180
181
  - MIT-LICENSE
@@ -187,6 +188,7 @@ files:
187
188
  - doc/release_notes/1.3.0.txt
188
189
  - doc/release_notes/2.0.0.txt
189
190
  - doc/release_notes/2.1.0.txt
191
+ - doc/release_notes/2.10.0.txt
190
192
  - doc/release_notes/2.2.0.txt
191
193
  - doc/release_notes/2.3.0.txt
192
194
  - doc/release_notes/2.4.0.txt
@@ -373,7 +375,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
373
375
  requirements:
374
376
  - - ">="
375
377
  - !ruby/object:Gem::Version
376
- version: '0'
378
+ version: 1.8.7
377
379
  required_rubygems_version: !ruby/object:Gem::Requirement
378
380
  requirements:
379
381
  - - ">="
@@ -381,7 +383,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
381
383
  version: '0'
382
384
  requirements: []
383
385
  rubyforge_project:
384
- rubygems_version: 2.4.5.1
386
+ rubygems_version: 2.5.1
385
387
  signing_key:
386
388
  specification_version: 4
387
389
  summary: Routing tree web framework toolkit