Class: MountableFileServer::Endpoint
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- MountableFileServer::Endpoint
- Defined in:
- lib/mountable_file_server/endpoint.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #deliver_file(filename) ⇒ Object
-
#initialize(configuration = MountableFileServer.configuration) ⇒ Endpoint
constructor
A new instance of Endpoint.
Constructor Details
#initialize(configuration = MountableFileServer.configuration) ⇒ Endpoint
Returns a new instance of Endpoint.
10 11 12 13 |
# File 'lib/mountable_file_server/endpoint.rb', line 10 def initialize(configuration = MountableFileServer.configuration) @configuration = configuration super end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
8 9 10 |
# File 'lib/mountable_file_server/endpoint.rb', line 8 def configuration @configuration end |
Instance Method Details
#deliver_file(filename) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mountable_file_server/endpoint.rb', line 30 def deliver_file(filename) path_to_file = File.join(configuration.stored_at, 'public', filename) if File.file?(path_to_file) send_file path_to_file else if filename.count('.') == 2 parts = filename.split('.') base_filename = "#{parts[0]}.#{parts[2]}" path_to_base_file = File.join(configuration.stored_at, 'public', base_filename) if File.file?(path_to_base_file) resize_command = UrlSafeBase64.decode64 parts[1] image = MiniMagick::Image.open path_to_base_file image.resize resize_command.to_s image.write path_to_file send_file path_to_file else not_found end else not_found end not_found end end |