Class: Snapa::File
- Inherits:
-
Rack::File
- Object
- Rack::File
- Snapa::File
- Defined in:
- lib/snapa.rb
Instance Method Summary collapse
- #_call(env) ⇒ Object
- #build(request) ⇒ Object
- #cache_path ⇒ Object
- #cmd ⇒ Object
-
#initialize(root, options = {}) ⇒ File
constructor
A new instance of File.
- #path(request) ⇒ Object
- #script ⇒ Object
- #url(request) ⇒ Object
Constructor Details
Instance Method Details
#_call(env) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/snapa.rb', line 37 def _call(env) request = ::Rack::Request.new(env) build(request) unless F.file?(path(request)) serving(env) end |
#build(request) ⇒ Object
25 26 27 |
# File 'lib/snapa.rb', line 25 def build(request) system [cmd, script, "'#{url(request)}'", "'#{@path}'"].join(' ') end |
#cache_path ⇒ Object
29 30 31 |
# File 'lib/snapa.rb', line 29 def cache_path @cache_path ||= defined?(Rails) ? Rails.root.join('public/system') : '/tmp' end |
#cmd ⇒ Object
13 14 15 |
# File 'lib/snapa.rb', line 13 def cmd 'phantomjs' end |
#path(request) ⇒ Object
33 34 35 |
# File 'lib/snapa.rb', line 33 def path(request) @path ||= F.join(cache_path, 'snapa', ::Digest::MD5.hexdigest(request.query_string) + '.png') end |
#script ⇒ Object
17 18 19 |
# File 'lib/snapa.rb', line 17 def script F.('../snapa.js', __FILE__) end |
#url(request) ⇒ Object
21 22 23 |
# File 'lib/snapa.rb', line 21 def url(request) [@root, request.query_string].join('?') end |