Module: TMP::CORE
- Included in:
- TMP, InstanceCore
- Defined in:
- lib/tmp/core.rb
Instance Method Summary collapse
- #default_folder_path ⇒ Object
- #folder_path(path_string = nil) ⇒ Object (also: #tmp_folder_path)
- #path(variable_name) ⇒ Object
- #project_name(name_string = nil) ⇒ Object
- #purge_files ⇒ Object (also: #purge!, #purge)
- #read(variable_name) ⇒ Object
- #tmp_folder_init ⇒ Object (also: #folder_init)
- #write(variable_name, data_object) ⇒ Object
Instance Method Details
#default_folder_path ⇒ Object
22 23 24 |
# File 'lib/tmp/core.rb', line 22 def default_folder_path File.join( Dir.tmpdir , project_name ) end |
#folder_path(path_string = nil) ⇒ Object Also known as: tmp_folder_path
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tmp/core.rb', line 27 def folder_path path_string= nil unless path_string.nil? unless path_string.class <= String raise ArgumentError,"invalid path class, must be string like" end @folder_path = File.absolute_path(path_string) end @folder_path || default_folder_path end |
#path(variable_name) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/tmp/core.rb', line 86 def path variable_name tmp_folder_init path_to_file= File.join(tmp_folder_path,variable_name.to_s) unless File.exist?(path_to_file) File.open( path_to_file ,"w") end return path_to_file end |
#project_name(name_string = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tmp/core.rb', line 6 def project_name name_string= nil unless name_string.nil? unless name_string.class <= String raise ArgumentError,"invalid name string" end @project_name = name_string end @project_name || Dir.pwd.split(File::Separator).last.to_s end |
#purge_files ⇒ Object Also known as: purge!, purge
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/tmp/core.rb', line 97 def purge_files Dir.glob( File.join( tmp_folder_path,'**','*' ) ).each do |file_path| begin File.delete file_path rescue Errno::ENOENT end end end |
#read(variable_name) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tmp/core.rb', line 70 def read variable_name unless File.exist?(File.join(tmp_folder_path,variable_name.to_s)) return nil end File.open( File.join(tmp_folder_path,variable_name.to_s) ,"r") do |file| begin return ::Marshal.load file.read rescue return file.read end end end |
#tmp_folder_init ⇒ Object Also known as: folder_init
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tmp/core.rb', line 45 def tmp_folder_init begin Dir.mkdir tmp_folder_path return true rescue Errno::EEXIST return false end end |
#write(variable_name, data_object) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/tmp/core.rb', line 60 def write variable_name, data_object tmp_folder_init File.open( File.join(tmp_folder_path,variable_name.to_s) ,"w") do |file| return file.write ::Marshal.dump(data_object) end end |