Class: Geminabox::Proxy::FileHandler
- Inherits:
-
Object
- Object
- Geminabox::Proxy::FileHandler
- Defined in:
- lib/geminabox/proxy/file_handler.rb
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Instance Method Summary collapse
- #file_exists?(path) ⇒ Boolean
-
#initialize(file_name) ⇒ FileHandler
constructor
A new instance of FileHandler.
- #local_content ⇒ Object
- #local_file_exists? ⇒ Boolean
- #local_path ⇒ Object
- #proxy_file_exists? ⇒ Boolean
- #proxy_folder_name ⇒ Object
- #proxy_folder_path ⇒ Object
- #proxy_path ⇒ Object
- #remote_content ⇒ Object
- #remote_url ⇒ Object
- #root_path ⇒ Object
Constructor Details
#initialize(file_name) ⇒ FileHandler
Returns a new instance of FileHandler.
9 10 11 12 |
# File 'lib/geminabox/proxy/file_handler.rb', line 9 def initialize(file_name) @file_name = file_name ensure_destination_exists end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
7 8 9 |
# File 'lib/geminabox/proxy/file_handler.rb', line 7 def file_name @file_name end |
Instance Method Details
#file_exists?(path) ⇒ Boolean
34 35 36 |
# File 'lib/geminabox/proxy/file_handler.rb', line 34 def file_exists?(path) File.exist? path end |
#local_content ⇒ Object
57 58 59 |
# File 'lib/geminabox/proxy/file_handler.rb', line 57 def local_content File.binread(local_path) end |
#local_file_exists? ⇒ Boolean
22 23 24 |
# File 'lib/geminabox/proxy/file_handler.rb', line 22 def local_file_exists? file_exists? local_path end |
#local_path ⇒ Object
14 15 16 |
# File 'lib/geminabox/proxy/file_handler.rb', line 14 def local_path File.(file_name, root_path) end |
#proxy_file_exists? ⇒ Boolean
26 27 28 |
# File 'lib/geminabox/proxy/file_handler.rb', line 26 def proxy_file_exists? file_exists? proxy_path end |
#proxy_folder_name ⇒ Object
42 43 44 |
# File 'lib/geminabox/proxy/file_handler.rb', line 42 def proxy_folder_name 'proxy' end |
#proxy_folder_path ⇒ Object
38 39 40 |
# File 'lib/geminabox/proxy/file_handler.rb', line 38 def proxy_folder_path File.join(root_path, proxy_folder_name) end |
#proxy_path ⇒ Object
30 31 32 |
# File 'lib/geminabox/proxy/file_handler.rb', line 30 def proxy_path File.(file_name, proxy_folder_path) end |
#remote_content ⇒ Object
46 47 48 49 50 51 |
# File 'lib/geminabox/proxy/file_handler.rb', line 46 def remote_content Geminabox.http_adapter.get_content(remote_url) rescue return nil if Geminabox.allow_remote_failure raise GemStoreError.new(500, "Unable to get content from #{remote_url}") end |
#remote_url ⇒ Object
53 54 55 |
# File 'lib/geminabox/proxy/file_handler.rb', line 53 def remote_url URI.join(Geminabox.ruby_gems_url, file_name) end |