lib/deas/runner.rb in deas-0.43.1 vs lib/deas/runner.rb in deas-0.43.2
- old
+ new
@@ -186,11 +186,11 @@
attr_reader :value
def initialize(value)
@value = if value.is_a?(::Array)
value.map{ |i| self.class.new(i).value }
- elsif Rack::Utils.params_hash_type?(value)
+ elsif self.hash_type?(value)
value.inject({}){ |h, (k, v)| h[k.to_s] = self.class.new(v).value; h }
elsif self.file_type?(value)
value
else
value.to_s
@@ -199,10 +199,18 @@
def file_type?(value)
raise NotImplementedError
end
+ def hash_type?(value)
+ # this supports older Rack versions (that don't have
+ # Utils#params_hash_type?)
+ ( Rack::Utils.respond_to?('params_hash_type?') &&
+ Rack::Utils.params_hash_type?(value)
+ ) || value.kind_of?(::Hash)
+ end
+
end
class SendFileBody
# this class borrows from the body range handling in Rack::File.
@@ -213,11 +221,11 @@
def initialize(env, path_name)
@path_name = path_name
file_size = @path_name.size? || Rack::Utils.bytesize(path_name.read)
- ranges = Rack::Utils.byte_ranges(env, file_size)
+ ranges = byte_ranges(env, file_size)
if ranges.nil? || ranges.empty? || ranges.length > 1
# No ranges or multiple ranges are not supported
@range = 0..file_size-1
@content_range = nil
else
@@ -258,9 +266,19 @@
def ==(other_body)
self.path_name.to_s == other_body.path_name.to_s &&
self.range_begin == other_body.range_begin &&
self.range_end == other_body.range_end
+ end
+
+ private
+
+ def byte_ranges(env, file_size)
+ if Rack::Utils.respond_to?('byte_ranges')
+ Rack::Utils.byte_ranges(env, file_size)
+ else
+ nil
+ end
end
end
end