Class: Geminabox::Proxy::Splicer

Inherits:
FileHandler show all
Defined in:
lib/geminabox/proxy/splicer.rb

Instance Attribute Summary

Attributes inherited from FileHandler

#file_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FileHandler

#file_exists?, #initialize, #local_content, #local_file_exists?, #local_path, #proxy_file_exists?, #proxy_folder_name, #proxy_folder_path, #proxy_path, #remote_content, #remote_url, #root_path

Constructor Details

This class inherits a constructor from Geminabox::Proxy::FileHandler

Class Method Details

.make(file_name) ⇒ Object



11
12
13
14
15
# File 'lib/geminabox/proxy/splicer.rb', line 11

def self.make(file_name)
  splicer = new(file_name)
  splicer.create
  splicer
end

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/geminabox/proxy/splicer.rb', line 17

def create
  if data = new_content
    f = Tempfile.create('geminabox')
    f.binmode
    begin
      f.write(data)
    ensure
      f.close rescue nil
    end
    FileUtils.mv f.path, splice_path
  end
end

#gzip?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/geminabox/proxy/splicer.rb', line 58

def gzip?
  /\.gz$/ =~ file_name
end

#merge_contentObject



50
51
52
53
54
55
56
# File 'lib/geminabox/proxy/splicer.rb', line 50

def merge_content
  if gzip?
    merge_gziped_content
  else
    merge_text_content
  end
end

#new_contentObject



30
31
32
33
34
35
36
# File 'lib/geminabox/proxy/splicer.rb', line 30

def new_content
  if local_file_exists?
    merge_content
  else
    remote_content
  end
end

#splice_file_exists?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/geminabox/proxy/splicer.rb', line 46

def splice_file_exists?
  file_exists? splice_path
end

#splice_folder_pathObject



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

def splice_folder_path
  proxy_folder_path
end

#splice_pathObject



38
39
40
# File 'lib/geminabox/proxy/splicer.rb', line 38

def splice_path
  proxy_path
end