Module: TMP::CORE
- Included in:
- TMP, InstanceCore
- Defined in:
- lib/tmp/deprecated/core.rb
Instance Method Summary collapse
- #block(variable_name, *args, &block_obj) ⇒ Object
- #default_folder_path ⇒ Object
- #path(variable_name, *args) ⇒ Object
- #project_name(name_string = nil) ⇒ Object (also: #project_folder)
- #purge_files ⇒ Object (also: #purge!, #purge)
- #read(variable_name) ⇒ Object
- #tmp_folder_init ⇒ Object (also: #folder_init)
- #tmp_folder_path(path_string = nil) ⇒ Object (also: #folder_path)
- #tmpdir ⇒ Object
- #write(variable_name, data_object) ⇒ Object
Instance Method Details
#block(variable_name, *args, &block_obj) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/tmp/deprecated/core.rb', line 80 def block variable_name, *args, &block_obj $stderr.puts('warning this is deprecated, will be removed in the further releases!(tmp gem)') tmp_folder_init = args.select{|e|(e.class <= ::Hash)}.reduce({},:merge!) args.select!{|e|!(e.class <= ::Hash)} [:file_extension] ||= [:extension] || [:ext] file_name = variable_name.to_s [:file_mod] ||= [:mod] || args[0].class <= ::String ? args[0] : nil unless [:file_extension].nil? while [:file_extension][0] == '.' [:file_extension][0]= '' end file_name += ".#{[:file_extension]}" end if File.exist?(File.join( tmp_folder_path, file_name )) [:file_mod] ||= "r+" else [:file_mod] ||= "w+" end begin return File.open( File.join( tmp_folder_path, file_name ), [:file_mod], &block_obj ) rescue Errno::ENOENT var_file= File.new( File.join( tmp_folder_path, file_name ), [:file_mod]) block_obj.call(var_file) unless block_obj.nil? var_file.close end end |
#default_folder_path ⇒ Object
28 29 30 |
# File 'lib/tmp/deprecated/core.rb', line 28 def default_folder_path File.join( tmpdir , project_name ) end |
#path(variable_name, *args) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/tmp/deprecated/core.rb', line 140 def path variable_name,*args $stderr.puts('warning this is deprecated, will be removed in the further releases!(tmp gem)') = args.select{|e|(e.class <= ::Hash)}.reduce({},:merge!) args.select!{|e|!(e.class <= ::Hash)} variable_name = variable_name.to_s [:file_extension] ||= [:extension] || [:ext] unless [:file_extension].nil? while [:file_extension][0] == '.' [:file_extension][0]= '' end variable_name += ".#{[:file_extension]}" end tmp_folder_init path_to_file= File.join( tmp_folder_path, variable_name ) unless File.exist?(path_to_file) File.open( path_to_file ,"w") {|f| f.write(""); f.close } end return path_to_file end |
#project_name(name_string = nil) ⇒ Object Also known as: project_folder
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tmp/deprecated/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
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/tmp/deprecated/core.rb', line 165 def purge_files Dir.glob( File.join( tmp_folder_path,'**','*' ) ).map do |file_path| begin File.delete file_path rescue Errno::ENOENT => ex ex end end end |
#read(variable_name) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/tmp/deprecated/core.rb', line 119 def read variable_name $stderr.puts('warning this is deprecated, will be removed in the further releases!(tmp gem)') 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| var= file.read begin return ::Marshal.load var rescue return var end end end |
#tmp_folder_init ⇒ Object Also known as: folder_init
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tmp/deprecated/core.rb', line 53 def tmp_folder_init begin Dir.mkdir tmp_folder_path return true rescue Errno::EEXIST return false end end |
#tmp_folder_path(path_string = nil) ⇒ Object Also known as: folder_path
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tmp/deprecated/core.rb', line 33 def tmp_folder_path path_string= nil $stderr.puts('warning this is deprecated, will be removed in the further releases!(tmp gem)') 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 |
#tmpdir ⇒ Object
24 25 26 |
# File 'lib/tmp/deprecated/core.rb', line 24 def tmpdir ::Dir.tmpdir end |
#write(variable_name, data_object) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tmp/deprecated/core.rb', line 68 def write variable_name, data_object $stderr.puts('warning this is deprecated, will be removed in the further releases!(tmp gem)') 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 |