class Spire::Public
Public Class Methods
new(opts={:render=>true})
click to toggle source
# File lib/spire/public.rb, line 5 def initialize(opts={:render=>true}) @opts = opts end
return_file(file)
click to toggle source
# File lib/spire/public.rb, line 9 def self.return_file(file) file_object = Public.new :file => file, :render => true file = file_object.create_response if file == 404 return Error.return_error :status => 404 else return Response.new(file[:file], file[:content_type], 200) end end
Public Instance Methods
create_response()
click to toggle source
# File lib/spire/public.rb, line 20 def create_response file_extension = File.extname(@opts[:file]) Mime.return_mimes ? @content_type = Mime.return_mimes[file_extension] : false if !@opts[:render] return [false, @content_type] end path = File.expand_path(__FILE__) path["lib/spire/public.rb"] = "public/#{@opts[:file]}" if File.exists?(path) file = IO.read(path) @return = {} @return[:file] = file @return[:content_type] = @content_type return @return else return 404 end end