sinatra-contrib 2.2.4 → 3.0.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
  SHA256:
3
- metadata.gz: afa15c985b40f0c6679ed5a072565e05bd65c1d61abc77fb54617f3b3c4dff98
4
- data.tar.gz: d301da7cb0cbcefc3de53d2665fbd3aebf1244ae5ddc29c665cacd4b80f9ebc5
3
+ metadata.gz: b1606208f2d126996b156d899ccd999bbac16eede55a2b3fc4d5070260993cc5
4
+ data.tar.gz: be0646504c34bdc361f4242a236c8979f91b2958fe0f9cce401253bfc944036d
5
5
  SHA512:
6
- metadata.gz: 36f4da234684c872e28d35f623f0587aa135fb34c372fd8be12f2037958bdaa9fccb9cd6b9c9e6514e12d3d613e388da0f4996d719a9c1a29d42db8fb9bd15c9
7
- data.tar.gz: f50a7809a699a3b77d5c0d368f189fd860f5cc73451f1a67097b0af55030eec508be7c3f8b96fb6284751eab0c9d3f5c93e7e0fe130998107207413f0a63b9af
6
+ metadata.gz: 6a5cd60ad8293f3eaf839dca15ba27e25e20f7b0ac48b66c1fb0133709f1aec00492ade424fff55acd4fa3677fc390863d18be769172db953684b07a7c11f8d7
7
+ data.tar.gz: b7b269f3f99c2062da6e658f9c7ccbb2c3c48b333c23270f827425f6879801d68db51a6b844bbe34b0daf65d17945b91204f80e125c73bd8daba4248de3165d5
data/README.md CHANGED
@@ -22,8 +22,8 @@ Currently included:
22
22
 
23
23
  * [`sinatra/config_file`][sinatra-config-file]: Allows loading configuration from yaml files.
24
24
 
25
- * [`sinatra/content_for`][sinatra-content-for]: Adds Rails-style `content_for` helpers to Haml, Erb, Erubi,
26
- Erubis and Slim.
25
+ * [`sinatra/content_for`][sinatra-content-for]: Adds Rails-style `content_for` helpers to Haml, Erb, Erubi
26
+ and Slim.
27
27
 
28
28
  * [`sinatra/cookies`][sinatra-cookies]: A `cookies` helper for reading and writing cookies.
29
29
 
@@ -58,7 +58,9 @@ existing APIs.
58
58
 
59
59
  Currently included:
60
60
 
61
- * [`sinatra/reloader`][sinatra-reloader]: Automatically reloads Ruby files on code changes.
61
+ * [`sinatra/reloader`][sinatra-reloader]: Automatically reloads Ruby files on code changes. **DEPRECATED**: Please consider
62
+ consider using an alternative like [rerun](https://github.com/alexch/rerun) or
63
+ [rack-unreloader](https://github.com/jeremyevans/rack-unreloader) instead.
62
64
 
63
65
  ### Other Tools
64
66
 
data/Rakefile CHANGED
@@ -1,12 +1,14 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
2
4
  require 'open-uri'
3
5
  require 'yaml'
4
6
  require 'sinatra/contrib/version'
5
7
 
6
- desc "run specs"
7
- task(:spec) { ruby '-S rspec spec -cw' }
8
- task(:test => :spec)
9
- task(:default => :spec)
8
+ desc 'run specs'
9
+ task(:spec) { ruby '-S rspec' }
10
+ task(test: :spec)
11
+ task(default: :spec)
10
12
 
11
13
  namespace :doc do
12
14
  task :readmes do
@@ -14,36 +16,37 @@ namespace :doc do
14
16
  puts "Trying file... #{file}"
15
17
  excluded_files = %w[lib/sinatra/contrib.rb lib/sinatra/decompile.rb]
16
18
  next if excluded_files.include?(file)
19
+
17
20
  doc = File.read(file)[/^module Sinatra(\n)+( #[^\n]*\n)*/m].scan(/^ *#(?!#) ?(.*)\n/).join("\n")
18
- file = "doc/#{file[4..-4].tr("/_", "-")}.rdoc"
19
- Dir.mkdir "doc" unless File.directory? "doc"
21
+ file = "doc/#{file[4..-4].tr('/_', '-')}.rdoc"
22
+ Dir.mkdir 'doc' unless File.directory? 'doc'
20
23
  puts "writing #{file}"
21
- File.open(file, "w") { |f| f << doc }
24
+ File.open(file, 'w') { |f| f << doc }
22
25
  end
23
26
  end
24
27
 
25
28
  task :index do
26
- doc = File.read("README.md")
27
- file = "doc/sinatra-contrib-readme.md"
28
- Dir.mkdir "doc" unless File.directory? "doc"
29
+ doc = File.read('README.md')
30
+ file = 'doc/sinatra-contrib-readme.md'
31
+ Dir.mkdir 'doc' unless File.directory? 'doc'
29
32
  puts "writing #{file}"
30
- File.open(file, "w") { |f| f << doc }
33
+ File.open(file, 'w') { |f| f << doc }
31
34
  end
32
35
 
33
- task :all => [:readmes, :index]
36
+ task all: %i[readmes index]
34
37
  end
35
38
 
36
- desc "generate documentation"
37
- task :doc => 'doc:all'
39
+ desc 'generate documentation'
40
+ task doc: 'doc:all'
38
41
 
39
- desc "generate gemspec"
42
+ desc 'generate gemspec'
40
43
  task 'sinatra-contrib.gemspec' do
41
44
  content = File.read 'sinatra-contrib.gemspec'
42
45
 
43
46
  fields = {
44
- :authors => `git shortlog -sn`.scan(/[^\d\s].*/),
45
- :email => `git shortlog -sne`.scan(/[^<]+@[^>]+/),
46
- :files => `git ls-files`.split("\n").reject { |f| f =~ /^(\.|Gemfile)/ }
47
+ authors: `git shortlog -sn`.scan(/[^\d\s].*/),
48
+ email: `git shortlog -sne`.scan(/[^<]+@[^>]+/),
49
+ files: `git ls-files`.split("\n").grep_v(/^(\.|Gemfile)/)
47
50
  }
48
51
 
49
52
  fields.each do |field, values|
@@ -56,9 +59,9 @@ task 'sinatra-contrib.gemspec' do
56
59
  File.open('sinatra-contrib.gemspec', 'w') { |f| f << content }
57
60
  end
58
61
 
59
- task :gemspec => 'sinatra-contrib.gemspec'
62
+ task gemspec: 'sinatra-contrib.gemspec'
60
63
 
61
- task :release => :gemspec do
64
+ task release: :gemspec do
62
65
  sh <<-SH
63
66
  rm -Rf sinatra-contrib*.gem &&
64
67
  gem build sinatra-contrib.gemspec &&
@@ -70,4 +73,3 @@ task :release => :gemspec do
70
73
  git push --tags && (git push origin --tags || true)
71
74
  SH
72
75
  end
73
-
data/ideas.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  * `sinatra-smart-cache`: update cache header only if arguments are more
13
13
  restrictive than curent value, set caching headers that way for most helper
14
- methods (i.e. `sass` or `send_file`)
14
+ methods (i.e. `send_file`)
15
15
 
16
16
  * Some verbose logging extension: Log what filters, routes, error handlers,
17
17
  templates, and so on is used.
@@ -26,4 +26,4 @@
26
26
 
27
27
  * Rewrite of `sinatra-compass`?
28
28
 
29
- * Helpers for HTML escaping and such.
29
+ * Helpers for HTML escaping and such.
@@ -86,17 +86,19 @@ module Sinatra
86
86
 
87
87
  def capture(*args, &block)
88
88
  return block[*args] if ruby?
89
+
89
90
  if haml? && Tilt[:haml] == Tilt::HamlTemplate
90
91
  buffer = Haml::Buffer.new(nil, Haml::Options.new.for_buffer)
91
92
  with_haml_buffer(buffer) { capture_haml(*args, &block) }
92
93
  else
93
- @_out_buf, _buf_was = '', @_out_buf
94
+ buf_was = @_out_buf
95
+ @_out_buf = ''
94
96
  begin
95
97
  raw = block[*args]
96
98
  captured = block.binding.eval('@_out_buf')
97
99
  captured.empty? ? raw : captured
98
100
  ensure
99
- @_out_buf = _buf_was
101
+ @_out_buf = buf_was
100
102
  end
101
103
  end
102
104
  end
@@ -3,7 +3,6 @@ require 'yaml'
3
3
  require 'erb'
4
4
 
5
5
  module Sinatra
6
-
7
6
  # = Sinatra::ConfigFile
8
7
  #
9
8
  # <tt>Sinatra::ConfigFile</tt> is an extension that allows you to load the
@@ -107,7 +106,6 @@ module Sinatra
107
106
  # bar: 'baz' # override the default value
108
107
  #
109
108
  module ConfigFile
110
-
111
109
  # When the extension is registered sets the +environments+ setting to the
112
110
  # traditional environments: development, test and production.
113
111
  def self.registered(base)
@@ -122,13 +120,10 @@ module Sinatra
122
120
  paths.each do |pattern|
123
121
  Dir.glob(pattern) do |file|
124
122
  raise UnsupportedConfigType unless ['.yml', '.yaml', '.erb'].include?(File.extname(file))
123
+
125
124
  logger.info "loading config file '#{file}'" if logging? && respond_to?(:logger)
126
- document = ERB.new(IO.read(file)).result
127
- yaml = begin
128
- YAML.load(document, aliases: true)
129
- rescue ArgumentError
130
- YAML.load(document)
131
- end
125
+ document = ERB.new(File.read(file)).result
126
+ yaml = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(document) : YAML.load(document)
132
127
  config = config_for_env(yaml)
133
128
  config.each_pair { |key, value| set(key, value) }
134
129
  end
@@ -136,7 +131,7 @@ module Sinatra
136
131
  end
137
132
  end
138
133
 
139
- class UnsupportedConfigType < Exception
134
+ class UnsupportedConfigType < StandardError
140
135
  def message
141
136
  'Invalid config file type, use .yml, .yaml or .erb'
142
137
  end
@@ -1,15 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/base'
2
4
  require 'sinatra/capture'
3
5
 
4
6
  module Sinatra
5
-
6
7
  # = Sinatra::ContentFor
7
8
  #
8
9
  # <tt>Sinatra::ContentFor</tt> is a set of helpers that allows you to capture
9
10
  # blocks inside views to be rendered later during the request. The most
10
11
  # common use is to populate different parts of your layout from your view.
11
12
  #
12
- # The currently supported engines are: Erb, Erubi, Erubis, Haml and Slim.
13
+ # The currently supported engines are: Erb, Erubi, Haml and Slim.
13
14
  #
14
15
  # == Usage
15
16
  #
@@ -174,11 +175,11 @@ module Sinatra
174
175
  # for <tt>:head</tt>.
175
176
  def yield_content(key, *args, &block)
176
177
  if block_given? && !content_for?(key)
177
- (haml? && Tilt[:haml] == Tilt::HamlTemplate) ? capture_haml(*args, &block) : yield(*args)
178
+ haml? && Tilt[:haml] == Tilt::HamlTemplate ? capture_haml(*args, &block) : yield(*args)
178
179
  else
179
180
  content = content_blocks[key.to_sym].map { |b| capture(*args, &b) }
180
181
  content.join.tap do |c|
181
- if block_given? && (erb? || erubi? || erubis?)
182
+ if block_given? && (erb? || erubi?)
182
183
  @_out_buf << c
183
184
  end
184
185
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/contrib'
2
4
  Sinatra.register Sinatra::Contrib::All
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/base'
2
4
  require 'sinatra/contrib/version'
3
5
 
@@ -5,7 +7,7 @@ module Sinatra
5
7
  module Contrib
6
8
  module Loader
7
9
  def extensions
8
- @extensions ||= {:helpers => [], :register => []}
10
+ @extensions ||= { helpers: [], register: [] }
9
11
  end
10
12
 
11
13
  def register(name, path)
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sinatra
2
4
  module Contrib
3
- VERSION = '2.2.3'
5
+ VERSION = '3.0.0'
4
6
  end
5
7
  end
6
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/contrib/setup'
2
4
 
3
5
  module Sinatra
@@ -25,7 +27,6 @@ module Sinatra
25
27
  ##
26
28
  # Other extensions you don't want to be loaded unless needed.
27
29
  module Custom
28
- # register :Compass, 'sinatra/compass'
29
30
  register :Reloader, 'sinatra/reloader'
30
31
  end
31
32
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/base'
2
4
 
3
5
  module Sinatra
@@ -65,15 +67,15 @@ module Sinatra
65
67
  @deleted = []
66
68
 
67
69
  @options = {
68
- :path => @request.script_name.to_s.empty? ? '/' : @request.script_name,
69
- :domain => @request.host == 'localhost' ? nil : @request.host,
70
- :secure => @request.secure?,
71
- :httponly => true
70
+ path: @request.script_name.to_s.empty? ? '/' : @request.script_name,
71
+ domain: @request.host == 'localhost' ? nil : @request.host,
72
+ secure: @request.secure?,
73
+ httponly: true
72
74
  }
73
75
 
74
- if app.settings.respond_to? :cookie_options
75
- @options.merge! app.settings.cookie_options
76
- end
76
+ return unless app.settings.respond_to? :cookie_options
77
+
78
+ @options.merge! app.settings.cookie_options
77
79
  end
78
80
 
79
81
  def ==(other)
@@ -88,9 +90,11 @@ module Sinatra
88
90
  set(key, value: value)
89
91
  end
90
92
 
91
- def assoc(key)
92
- to_hash.assoc(key.to_s)
93
- end if Hash.method_defined? :assoc
93
+ if Hash.method_defined? :assoc
94
+ def assoc(key)
95
+ to_hash.assoc(key.to_s)
96
+ end
97
+ end
94
98
 
95
99
  def clear
96
100
  each_key { |k| delete(k) }
@@ -114,17 +118,20 @@ module Sinatra
114
118
 
115
119
  def delete_if
116
120
  return enum_for(__method__) unless block_given?
121
+
117
122
  each { |k, v| delete(k) if yield(k, v) }
118
123
  self
119
124
  end
120
125
 
121
126
  def each(&block)
122
127
  return enum_for(__method__) unless block_given?
128
+
123
129
  to_hash.each(&block)
124
130
  end
125
131
 
126
132
  def each_key(&block)
127
133
  return enum_for(__method__) unless block_given?
134
+
128
135
  to_hash.each_key(&block)
129
136
  end
130
137
 
@@ -132,6 +139,7 @@ module Sinatra
132
139
 
133
140
  def each_value(&block)
134
141
  return enum_for(__method__) unless block_given?
142
+
135
143
  to_hash.each_value(&block)
136
144
  end
137
145
 
@@ -145,16 +153,18 @@ module Sinatra
145
153
  end
146
154
  end
147
155
 
148
- def flatten
149
- to_hash.flatten
150
- end if Hash.method_defined? :flatten
156
+ if Hash.method_defined? :flatten
157
+ def flatten
158
+ to_hash.flatten
159
+ end
160
+ end
151
161
 
152
162
  def has_key?(key)
153
- response_cookies.has_key? key.to_s or request_cookies.has_key? key.to_s
163
+ response_cookies.key? key.to_s or request_cookies.key? key.to_s
154
164
  end
155
165
 
156
166
  def has_value?(value)
157
- response_cookies.has_value? value or request_cookies.has_value? value
167
+ response_cookies.value? value or request_cookies.value? value
158
168
  end
159
169
 
160
170
  def hash
@@ -164,22 +174,20 @@ module Sinatra
164
174
  alias include? has_key?
165
175
  alias member? has_key?
166
176
 
167
- def index(value)
168
- warn "Hash#index is deprecated; use Hash#key"
169
- key(value)
170
- end
171
-
172
177
  def inspect
173
178
  "<##{self.class}: #{to_hash.inspect[1..-2]}>"
174
179
  end
175
180
 
176
- def invert
177
- to_hash.invert
178
- end if Hash.method_defined? :invert
181
+ if Hash.method_defined? :invert
182
+ def invert
183
+ to_hash.invert
184
+ end
185
+ end
179
186
 
180
187
  def keep_if
181
188
  return enum_for(__method__) unless block_given?
182
- delete_if { |*a| not yield(*a) }
189
+
190
+ delete_if { |*a| !yield(*a) }
183
191
  end
184
192
 
185
193
  def key(value)
@@ -202,11 +210,11 @@ module Sinatra
202
210
 
203
211
  def merge!(other)
204
212
  other.each_pair do |key, value|
205
- if block_given? and include? key
206
- self[key] = yield(key.to_s, self[key], value)
207
- else
208
- self[key] = value
209
- end
213
+ self[key] = if block_given? && include?(key)
214
+ yield(key.to_s, self[key], value)
215
+ else
216
+ value
217
+ end
210
218
  end
211
219
  end
212
220
 
@@ -222,18 +230,20 @@ module Sinatra
222
230
 
223
231
  def reject(&block)
224
232
  return enum_for(__method__) unless block_given?
233
+
225
234
  to_hash.reject(&block)
226
235
  end
227
236
 
228
237
  alias reject! delete_if
229
238
 
230
239
  def replace(other)
231
- select! { |k, v| other.include?(k) or other.include?(k.to_s) }
240
+ select! { |k, _v| other.include?(k) or other.include?(k.to_s) }
232
241
  merge! other
233
242
  end
234
243
 
235
244
  def select(&block)
236
245
  return enum_for(__method__) unless block_given?
246
+
237
247
  to_hash.select(&block)
238
248
  end
239
249
 
@@ -251,9 +261,11 @@ module Sinatra
251
261
 
252
262
  alias size length
253
263
 
254
- def sort(&block)
255
- to_hash.sort(&block)
256
- end if Hash.method_defined? :sort
264
+ if Hash.method_defined? :sort
265
+ def sort(&block)
266
+ to_hash.sort(&block)
267
+ end
268
+ end
257
269
 
258
270
  alias store []=
259
271
 
@@ -305,6 +317,7 @@ module Sinatra
305
317
  string.each_line do |line|
306
318
  key, value = line.split(';', 2).first.to_s.split('=', 2)
307
319
  next if key.nil?
320
+
308
321
  key = Rack::Utils.unescape(key)
309
322
  if line =~ /expires=Thu, 01[-\s]Jan[-\s]1970/
310
323
  @deleted << key
@@ -319,7 +332,7 @@ module Sinatra
319
332
  end
320
333
 
321
334
  def request_cookies
322
- @request.cookies.reject { |key, value| deleted.include? key }
335
+ @request.cookies.reject { |key, _value| deleted.include? key }
323
336
  end
324
337
  end
325
338
 
@@ -1,5 +1,6 @@
1
- module Sinatra
1
+ # frozen_string_literal: true
2
2
 
3
+ module Sinatra
3
4
  # = Sinatra::CustomLogger
4
5
  #
5
6
  # CustomLogger extension allows you to define your own logger instance
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/base'
2
4
 
3
5
  module Sinatra
@@ -12,21 +14,12 @@ module Sinatra
12
14
  end
13
15
 
14
16
  # Returns true if the current engine is `:erubi`, or `Tilt[:erb]` is set
15
- # to Tilt::ErubisTemplate.
17
+ # to Tilt::ErubiTemplate.
16
18
  #
17
19
  # @return [Boolean] Returns true if current engine is `:erubi`.
18
20
  def erubi?
19
21
  @current_engine == :erubi or
20
- erb? && Tilt[:erb] == Tilt::ErubiTemplate
21
- end
22
-
23
- # Returns true if the current engine is `:erubis`, or `Tilt[:erb]` is set
24
- # to Tilt::ErubisTemplate.
25
- #
26
- # @return [Boolean] Returns true if current engine is `:erubis`.
27
- def erubis?
28
- @current_engine == :erubis or
29
- erb? && Tilt[:erb] == Tilt::ErubisTemplate
22
+ (erb? && Tilt[:erb] == Tilt::ErubiTemplate)
30
23
  end
31
24
 
32
25
  # @return [Boolean] Returns true if current engine is `:haml`.
@@ -34,21 +27,6 @@ module Sinatra
34
27
  @current_engine == :haml
35
28
  end
36
29
 
37
- # @return [Boolean] Returns true if current engine is `:sass`.
38
- def sass?
39
- @current_engine == :sass
40
- end
41
-
42
- # @return [Boolean] Returns true if current engine is `:scss`.
43
- def scss?
44
- @current_engine == :scss
45
- end
46
-
47
- # @return [Boolean] Returns true if current engine is `:less`.
48
- def less?
49
- @current_engine == :less
50
- end
51
-
52
30
  # @return [Boolean] Returns true if current engine is `:builder`.
53
31
  def builder?
54
32
  @current_engine == :builder
@@ -64,31 +42,16 @@ module Sinatra
64
42
  @current_engine == :markdown
65
43
  end
66
44
 
67
- # @return [Boolean] Returns true if current engine is `:textile.
68
- def textile?
69
- @current_engine == :textile
70
- end
71
-
72
45
  # @return [Boolean] Returns true if current engine is `:rdoc`.
73
46
  def rdoc?
74
47
  @current_engine == :rdoc
75
48
  end
76
49
 
77
- # @return [Boolean] Returns true if current engine is `:radius.
78
- def radius?
79
- @current_engine == :radius
80
- end
81
-
82
50
  # @return [Boolean] Returns true if current engine is `:markaby`.
83
51
  def markaby?
84
52
  @current_engine == :markaby
85
53
  end
86
54
 
87
- # @return [Boolean] Returns true if current engine is `:coffee`.
88
- def coffee?
89
- @current_engine == :coffee
90
- end
91
-
92
55
  # @return [Boolean] Returns true if current engine is `:nokogiri`.
93
56
  def nokogiri?
94
57
  @current_engine == :nokogiri
@@ -99,11 +62,6 @@ module Sinatra
99
62
  @current_engine == :slim
100
63
  end
101
64
 
102
- # @return [Boolean] Returns true if current engine is `:creole`.
103
- def creole?
104
- @current_engine == :creole
105
- end
106
-
107
65
  # @return [Boolean] Returns true if current engine is `:ruby`.
108
66
  def ruby?
109
67
  @current_engine == :ruby
@@ -116,7 +74,8 @@ module Sinatra
116
74
 
117
75
  # @param engine [Symbol, String] Name of Engine to shift to.
118
76
  def with_engine(engine)
119
- @current_engine, engine_was = engine.to_sym, @current_engine
77
+ engine_was = @current_engine
78
+ @current_engine = engine.to_sym
120
79
  yield
121
80
  ensure
122
81
  @current_engine = engine_was
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/base'
2
4
 
3
5
  module Sinatra
4
-
5
6
  # = Sinatra::Extension
6
7
  #
7
8
  # <tt>Sinatra::Extension</tt> is a mixin that provides some syntactic sugar
@@ -81,13 +82,14 @@ module Sinatra
81
82
 
82
83
  def method_missing(method, *args, &block)
83
84
  return super unless Sinatra::Base.respond_to? method
85
+
84
86
  record(method, *args, &block)
85
87
  DontCall.new(method)
86
88
  end
87
89
 
88
90
  class DontCall < BasicObject
89
91
  def initialize(method) @method = method end
90
- def method_missing(*) fail "not supposed to use result of #@method!" end
92
+ def method_missing(*) raise "not supposed to use result of #{@method}!" end
91
93
  def inspect; "#<#{self.class}: #{@method}>" end
92
94
  end
93
95
  end
data/lib/sinatra/json.rb CHANGED
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/base'
2
4
  require 'multi_json'
3
5
  module Sinatra
4
-
5
6
  # = Sinatra::JSON
6
7
  #
7
8
  # <tt>Sinatra::JSON</tt> adds a helper method, called +json+, for (obviously)
@@ -95,7 +96,7 @@ module Sinatra
95
96
 
96
97
  def json(object, options = {})
97
98
  content_type resolve_content_type(options)
98
- resolve_encoder_action object, resolve_encoder(options)
99
+ resolve_encoder_action object, resolve_encoder(options)
99
100
  end
100
101
 
101
102
  private
@@ -109,16 +110,14 @@ module Sinatra
109
110
  end
110
111
 
111
112
  def resolve_encoder_action(object, encoder)
112
- [:encode, :generate].each do |method|
113
+ %i[encode generate].each do |method|
113
114
  return encoder.send(method, object) if encoder.respond_to? method
114
115
  end
115
- if encoder.is_a? Symbol
116
- object.__send__(encoder)
117
- else
118
- fail "#{encoder} does not respond to #generate nor #encode"
119
- end #if
120
- end #resolve_encoder_action
121
- end #JSON
116
+ raise "#{encoder} does not respond to #generate nor #encode" unless encoder.is_a? Symbol
117
+
118
+ object.__send__(encoder)
119
+ end
120
+ end
122
121
 
123
122
  Base.set :json_encoder do
124
123
  ::MultiJson