Class: Gct::TempLocalFile

Inherits:
Object
  • Object
show all
Defined in:
lib/gct/temp_local_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content = '', file_name = '') ⇒ TempLocalFile

Returns a new instance of TempLocalFile.



7
8
9
10
# File 'lib/gct/temp_local_file.rb', line 7

def initialize(content = '', file_name = '')
  @content = content
  @file_name = file_name
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/gct/temp_local_file.rb', line 3

def content
  @content
end

#file_nameObject

Returns the value of attribute file_name.



5
6
7
# File 'lib/gct/temp_local_file.rb', line 5

def file_name
  @file_name
end

Instance Method Details

#full_pathObject



45
46
47
# File 'lib/gct/temp_local_file.rb', line 45

def full_path
  tmp_folder
end

#readObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/gct/temp_local_file.rb', line 23

def read
  begin
    file = File.open(tmp_folder, "r")
    file.read
  rescue IOError => e
    raise e.message
  ensure
    file.close unless file.nil?
  end
end

#read_path_file(path, file) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/gct/temp_local_file.rb', line 34

def read_path_file(path, file)
  begin
    file = File.new(File.join(path, file), "r")
    file.read
  rescue IOError => e
    raise e.message
  ensure
    file.close unless file.nil?
  end
end

#tmp_folderObject



49
50
51
# File 'lib/gct/temp_local_file.rb', line 49

def tmp_folder
  "#{Generator::GctFile.temp_folder_path}/#{file_name}"
end

#writeObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/gct/temp_local_file.rb', line 12

def write
  begin
    file = File.open(tmp_folder, "w")
    file.write(@content) 
  rescue IOError => e
    raise e.message
  ensure
    file.close unless file.nil?
  end
end