Class: Flame::Dispatcher::Static::StaticFile

Inherits:
Object
  • Object
show all
Defined in:
lib/flame/dispatcher/static.rb

Overview

Class for static files with helpers methods

Instance Method Summary collapse

Constructor Details

#initialize(filename, dir) ⇒ StaticFile

Returns a new instance of StaticFile.



30
31
32
33
# File 'lib/flame/dispatcher/static.rb', line 30

def initialize(filename, dir)
	@filename = filename.to_s
	@path = File.join dir, URI.decode(@filename)
end

Instance Method Details

#contentObject



51
52
53
# File 'lib/flame/dispatcher/static.rb', line 51

def content
	File.read(@path)
end

#exist?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/flame/dispatcher/static.rb', line 35

def exist?
	File.exist?(@path) && File.file?(@path)
end

#extnameObject



43
44
45
# File 'lib/flame/dispatcher/static.rb', line 43

def extname
	File.extname(@path)
end

#mtimeObject



39
40
41
# File 'lib/flame/dispatcher/static.rb', line 39

def mtime
	File.mtime(@path)
end

#newer?(http_since) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/flame/dispatcher/static.rb', line 47

def newer?(http_since)
	http_since && Time.httpdate(http_since).to_i >= mtime.to_i
end

#path(with_version: false) ⇒ Object



55
56
57
58
# File 'lib/flame/dispatcher/static.rb', line 55

def path(with_version: false)
	path = @filename
	with_version ? "#{path}?v=#{mtime.to_i}" : path
end