Class: Geminabox::Proxy::FileHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/geminabox/proxy/file_handler.rb

Direct Known Subclasses

Copier, Splicer

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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

Returns:

  • (Boolean)

33
34
35
# File 'lib/geminabox/proxy/file_handler.rb', line 33

def file_exists?(path)
  File.exists? path
end

#local_contentObject


55
56
57
# File 'lib/geminabox/proxy/file_handler.rb', line 55

def local_content
  File.read(local_path).force_encoding(encoding)
end

#local_file_exists?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'lib/geminabox/proxy/file_handler.rb', line 21

def local_file_exists?
  file_exists? local_path
end

#local_pathObject


13
14
15
# File 'lib/geminabox/proxy/file_handler.rb', line 13

def local_path
  File.expand_path(file_name, root_path)
end

#proxy_file_exists?Boolean

Returns:

  • (Boolean)

25
26
27
# File 'lib/geminabox/proxy/file_handler.rb', line 25

def proxy_file_exists?
  file_exists? proxy_path
end

#proxy_folder_nameObject


41
42
43
# File 'lib/geminabox/proxy/file_handler.rb', line 41

def proxy_folder_name
  'proxy'
end

#proxy_folder_pathObject


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_pathObject


29
30
31
# File 'lib/geminabox/proxy/file_handler.rb', line 29

def proxy_path
  File.expand_path(file_name, proxy_folder_path)
end

#remote_contentObject


45
46
47
48
49
# 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_urlObject


51
52
53
# File 'lib/geminabox/proxy/file_handler.rb', line 51

def remote_url
  "http://rubygems.org/#{file_name}"
end

#root_pathObject


17
18
19
# File 'lib/geminabox/proxy/file_handler.rb', line 17

def root_path
  Geminabox.data
end