Class: Rack::XapFile
- Inherits:
-
Object
- Object
- Rack::XapFile
- Defined in:
- lib/rack/xapper.rb
Constant Summary collapse
- F =
::File
Instance Method Summary collapse
- #_call(env) ⇒ Object
- #call(env) ⇒ Object
- #dev_env? ⇒ Boolean
- #each ⇒ Object
- #forbidden ⇒ Object
-
#initialize(options) ⇒ XapFile
constructor
A new instance of XapFile.
- #not_found ⇒ Object
- #xap_changed? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ XapFile
Returns a new instance of XapFile.
231 232 233 234 235 236 |
# File 'lib/rack/xapper.rb', line 231 def initialize() @options = .dup xap_name = "#{@options[:xap_name]}" xap_name = "#{xap_name}.xap" if xap_name !~ /\.xap$/ @xap_path = @options[:root] + "/" + @options[:xap_path] + "/" + xap_name end |
Instance Method Details
#_call(env) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/rack/xapper.rb', line 244 def _call(env) @path_info = Utils.unescape(env["PATH_INFO"]) return forbidden if @path_info.include? ".." if dev_env? or xap_changed? FileUtils.rm_f(@xap_path) if F.exist?(@xap_path) XapBuilder.xap_to_disk @options end begin if F.file?(@xap_path) && F.readable?(@xap_path) [200, { "Date" => F.mtime(@xap_path).httpdate, "Content-Type" => Mime.mime_type(F.extname(@xap_path), 'application/x-zip-compressed'), "Cache-Control" => "no-cache", "Expires" => "-1", 'Pragma' => "no-cache", "Content-Length" => F.size?(@xap_path).to_s }, self] else raise Errno::EPERM end rescue SystemCallError not_found end end |
#call(env) ⇒ Object
238 239 240 |
# File 'lib/rack/xapper.rb', line 238 def call(env) dup._call(env) end |
#dev_env? ⇒ Boolean
271 272 273 |
# File 'lib/rack/xapper.rb', line 271 def dev_env? (ENV['RACK_ENV'] || 'development').to_sym != :production end |
#each ⇒ Object
296 297 298 299 300 301 302 |
# File 'lib/rack/xapper.rb', line 296 def each F.open(@xap_path, "rb") { |file| while part = file.read(8192) yield part end } end |
#forbidden ⇒ Object
282 283 284 285 286 287 |
# File 'lib/rack/xapper.rb', line 282 def forbidden body = "Forbidden\n" [403, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s}, [body]] end |
#not_found ⇒ Object
289 290 291 292 293 294 |
# File 'lib/rack/xapper.rb', line 289 def not_found body = "File not found: #{@path_info}\n" [404, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s}, [body]] end |
#xap_changed? ⇒ Boolean
275 276 277 278 279 280 |
# File 'lib/rack/xapper.rb', line 275 def xap_changed? XapBuilder.(@options) files = @options[:application_files] + @options[:extra_app_files] + @options[:assembly_files] xap_mtime = File.mtime(@xap_path) files.any?{ |f| File.mtime(f) > xap_mtime } end |