class Geminabox::Proxy::FileHandler
Attributes
file_name[R]
Public Class Methods
new(file_name)
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 8 def initialize(file_name) @file_name = file_name ensure_destination_exists end
Public Instance Methods
file_exists?(path)
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 33 def file_exists?(path) File.exists? path end
local_content()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 55 def local_content File.read(local_path).force_encoding(encoding) end
local_file_exists?()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 21 def local_file_exists? file_exists? local_path end
local_path()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 13 def local_path File.expand_path(file_name, root_path) end
proxy_file_exists?()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 25 def proxy_file_exists? file_exists? proxy_path end
proxy_folder_name()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 41 def proxy_folder_name 'proxy' end
proxy_folder_path()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 37 def proxy_folder_path File.join(root_path, proxy_folder_name) end
proxy_path()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 29 def proxy_path File.expand_path(file_name, proxy_folder_path) end
remote_content()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 45 def remote_content Geminabox.http_adapter.get_content(remote_url).force_encoding(encoding) rescue raise GemStoreError.new(500, "Unable to get content from #{remote_url}") end
remote_url()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 51 def remote_url "http://rubygems.org/#{file_name}" end
root_path()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 17 def root_path Geminabox.data end
Private Instance Methods
create_local_folder()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 89 def create_local_folder FileUtils.mkdir_p(local_file_folder) end
create_proxy_folder()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 77 def create_proxy_folder FileUtils.mkdir_p(proxy_file_folder) end
encoding()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 60 def encoding "UTF-8" end
ensure_destination_exists()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 64 def ensure_destination_exists create_local_folder unless local_folder_exists? create_proxy_folder unless proxy_folder_exists? end
local_file_folder()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 81 def local_file_folder File.dirname local_path end
local_folder_exists?()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 85 def local_folder_exists? Dir.exists?(local_file_folder) end
proxy_file_folder()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 69 def proxy_file_folder File.dirname proxy_path end
proxy_folder_exists?()
click to toggle source
# File lib/geminabox/proxy/file_handler.rb, line 73 def proxy_folder_exists? Dir.exists?(proxy_file_folder) end