module TMP::CORE
Public Instance Methods
block(variable_name, *args, &block_obj)
click to toggle source
# 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 options = args.select{|e|(e.class <= ::Hash)}.reduce({},:merge!) args.select!{|e|!(e.class <= ::Hash)} options[:file_extension] ||= options[:extension] || options[:ext] file_name = variable_name.to_s options[:file_mod] ||= options[:mod] || args[0].class <= ::String ? args[0] : nil unless options[:file_extension].nil? while options[:file_extension][0] == '.' options[:file_extension][0]= '' end file_name += ".#{options[:file_extension]}" end if File.exist?(File.join( tmp_folder_path, file_name )) options[:file_mod] ||= "r+" else options[:file_mod] ||= "w+" end begin return File.open( File.join( tmp_folder_path, file_name ), options[:file_mod], &block_obj ) rescue Errno::ENOENT var_file= File.new( File.join( tmp_folder_path, file_name ), options[:file_mod]) block_obj.call(var_file) unless block_obj.nil? var_file.close end end
default_folder_path()
click to toggle source
# File lib/tmp/deprecated/core.rb, line 28 def default_folder_path File.join( tmpdir , project_name ) end
path(variable_name,*args)
click to toggle source
# 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)') options = args.select{|e|(e.class <= ::Hash)}.reduce({},:merge!) args.select!{|e|!(e.class <= ::Hash)} variable_name = variable_name.to_s options[:file_extension] ||= options[:extension] || options[:ext] unless options[:file_extension].nil? while options[:file_extension][0] == '.' options[:file_extension][0]= '' end variable_name += ".#{options[: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)
click to toggle source
# 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
Also aliased as: project_folder
purge_files()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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
Also aliased as: folder_init
tmp_folder_path(path_string= nil)
click to toggle source
# 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
Also aliased as: folder_path
tmpdir()
click to toggle source
# File lib/tmp/deprecated/core.rb, line 24 def tmpdir ::Dir.tmpdir end
write(variable_name, data_object)
click to toggle source
# 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