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.
8 9 10 11 |
# File 'lib/geminabox/proxy/file_handler.rb', line 8 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.
6 7 8 |
# File 'lib/geminabox/proxy/file_handler.rb', line 6 def file_name @file_name end |
Instance Method Details
#file_exists?(path) ⇒ Boolean
33 34 35 |
# File 'lib/geminabox/proxy/file_handler.rb', line 33 def file_exists?(path) File.exists? path end |
#local_content ⇒ Object
53 54 55 |
# File 'lib/geminabox/proxy/file_handler.rb', line 53 def local_content File.read(local_path).force_encoding(encoding) end |
#local_file_exists? ⇒ Boolean
21 22 23 |
# File 'lib/geminabox/proxy/file_handler.rb', line 21 def local_file_exists? file_exists? local_path end |
#local_path ⇒ Object
13 14 15 |
# File 'lib/geminabox/proxy/file_handler.rb', line 13 def local_path File.(file_name, root_path) end |
#proxy_file_exists? ⇒ Boolean
25 26 27 |
# File 'lib/geminabox/proxy/file_handler.rb', line 25 def proxy_file_exists? file_exists? proxy_path end |
#proxy_folder_name ⇒ Object
41 42 43 |
# File 'lib/geminabox/proxy/file_handler.rb', line 41 def proxy_folder_name 'proxy' end |
#proxy_folder_path ⇒ Object
37 38 39 |
# File 'lib/geminabox/proxy/file_handler.rb', line 37 def proxy_folder_path File.join(root_path, proxy_folder_name) end |
#proxy_path ⇒ Object
29 30 31 |
# File 'lib/geminabox/proxy/file_handler.rb', line 29 def proxy_path File.(file_name, proxy_folder_path) end |
#remote_content ⇒ Object
45 46 47 |
# File 'lib/geminabox/proxy/file_handler.rb', line 45 def remote_content HTTPClient.get_content(remote_url).force_encoding(encoding) end |
#remote_url ⇒ Object
49 50 51 |
# File 'lib/geminabox/proxy/file_handler.rb', line 49 def remote_url "http://rubygems.org/#{file_name}" end |