Class: Flame::Dispatcher::Static::StaticFile
- Inherits:
-
Object
- Object
- Flame::Dispatcher::Static::StaticFile
- Defined in:
- lib/flame/dispatcher/static.rb
Overview
Class for static files with helpers methods
Instance Method Summary collapse
- #content ⇒ Object
- #exist? ⇒ Boolean
- #extname ⇒ Object
-
#initialize(filename, dir) ⇒ StaticFile
constructor
A new instance of StaticFile.
- #mtime ⇒ Object
- #newer?(http_since) ⇒ Boolean
- #path(with_version: false) ⇒ Object
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
#content ⇒ Object
51 52 53 |
# File 'lib/flame/dispatcher/static.rb', line 51 def content File.read(@path) end |
#exist? ⇒ Boolean
35 36 37 |
# File 'lib/flame/dispatcher/static.rb', line 35 def exist? File.exist?(@path) && File.file?(@path) end |
#extname ⇒ Object
43 44 45 |
# File 'lib/flame/dispatcher/static.rb', line 43 def extname File.extname(@path) end |
#mtime ⇒ Object
39 40 41 |
# File 'lib/flame/dispatcher/static.rb', line 39 def mtime File.mtime(@path) end |
#newer?(http_since) ⇒ 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 |