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.



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

Returns:

  • (Boolean)


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

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

#local_contentObject



57
58
59
# File 'lib/geminabox/proxy/file_handler.rb', line 57

def local_content
  File.binread(local_path)
end

#local_file_exists?Boolean

Returns:

  • (Boolean)


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

def local_file_exists?
  file_exists? local_path
end

#local_pathObject



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

def local_path
  File.expand_path(file_name, root_path)
end

#proxy_file_exists?Boolean

Returns:

  • (Boolean)


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

def proxy_file_exists?
  file_exists? proxy_path
end

#proxy_folder_nameObject



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

def proxy_folder_name
  'proxy'
end

#proxy_folder_pathObject



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_pathObject



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

def proxy_path
  File.expand_path(file_name, proxy_folder_path)
end

#remote_contentObject



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_urlObject



53
54
55
# File 'lib/geminabox/proxy/file_handler.rb', line 53

def remote_url
  URI.join(Geminabox.ruby_gems_url, file_name)
end

#root_pathObject



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

def root_path
  Geminabox.data
end