tmp 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb58e98bc963a58a1800b4ee6675229bcf89fb30
4
- data.tar.gz: 4952c7a5d2f3ed0a6f9ffd5f7aabad59a81b4b1c
3
+ metadata.gz: c9cdcb7143213d0cc2358bc0ad3af6787abe4786
4
+ data.tar.gz: 8e5ae50398fb70f6232d27a47a33b6ee9c14a0dd
5
5
  SHA512:
6
- metadata.gz: 80ba989fc0616416c8e253be14859b39193517417772c228d2e4ebd63db858cf9e7b8d59ada6fa21fe758a958a79a75d329abb83506e965e1d99a01a454c3fcb
7
- data.tar.gz: 7a9348c202c72b017d49470f0f9b222654955db976777cf21cfb97024d11f9758d1e8a31732abfbcedc5fa82a5fe5b65ce596419b3f74b7986877bbcad8a1120
6
+ metadata.gz: 9501958ca1cf1821a6fb3a2d5bb770a30ab481898582b2736cf7b87737335f57264a9250e2b536c38414e0c4865495c8513747a77ef325934ac95c6b030bef43
7
+ data.tar.gz: 22c254e9e7f6c108bfa2018e68bda37a99d8fcc92e3e64d2744ba26ec188faa06f6c5c0c90a73abc3b1abb52d3559d48c142c70eeae1c22a9ead68df5458a3f2
data/README.md CHANGED
@@ -42,6 +42,24 @@ you can config the folder path for custom tmp folder use case if you dont want t
42
42
  puts tmp.hello #> { hello: 'world'}
43
43
  ```
44
44
 
45
+ ### Remove tmp objects
46
+
47
+ you can remove tmp objects by purge them
48
+
49
+ ```ruby
50
+ require 'tmp'
51
+
52
+ tmp.hello = { hello: 'world'}
53
+
54
+ # now it's set
55
+ puts tmp.hello #> { hello: 'world'}
56
+
57
+ TMP.purge!
58
+
59
+ # now it's nil
60
+ puts tmp.hello #> nil
61
+ ```
62
+
45
63
  ### TODO
46
64
 
47
65
  * make ssl encryption for the tmp files opt able
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
@@ -12,3 +12,7 @@ puts tmp.hello #> { hello: 'world'}
12
12
  # undefined variable
13
13
  puts tmp.sup #> nil
14
14
 
15
+ TMP.purge!
16
+
17
+ # call after tmp is purged
18
+ puts tmp.hello #> nil
@@ -3,7 +3,6 @@ module TMP
3
3
  module Config
4
4
  class << self
5
5
 
6
-
7
6
  def default_folder_path
8
7
  File.join( Dir.tmpdir, ( Dir.pwd.split(File::Separator).last.to_s ) )
9
8
  end
@@ -25,7 +24,11 @@ module TMP
25
24
 
26
25
  end
27
26
 
28
-
29
27
  end
30
28
  end
29
+
30
+ def self.folder_path obj
31
+ self::Config.folder_path(obj)
32
+ end
33
+
31
34
  end
@@ -1,63 +1,98 @@
1
1
  #encoding: UTF-8
2
2
  module TMP
3
- class << self
4
3
 
5
- def tmp_folder_path
4
+ module Support
6
5
 
7
- modifier= ""
8
- ::TMP::Config.folder_path
6
+ class << self
9
7
 
10
- end
8
+ def tmp_folder_path
9
+ ::TMP::Config.folder_path
10
+ end
11
11
 
12
- alias :folder_path :tmp_folder_path
12
+ alias :folder_path :tmp_folder_path
13
13
 
14
- def tmp_folder_init
14
+ def tmp_folder_init
15
15
 
16
- begin
16
+ begin
17
17
 
18
- Dir.mkdir tmp_folder_path
19
- return true
18
+ Dir.mkdir tmp_folder_path
19
+ return true
20
20
 
21
- rescue Errno::EEXIST
22
- return false
23
- end
21
+ rescue Errno::EEXIST
22
+ return false
23
+ end
24
24
 
25
- end
25
+ end
26
26
 
27
- def read_buffer path
27
+ def read_buffer path
28
28
 
29
- comm_line= File.open(path,"r")
29
+ comm_line= File.open(path,"r")
30
30
 
31
- read_buffer = ::Thread.new do
32
- while !comm_line.eof?
33
- @value = ::Marshal.load( comm_line )
31
+ read_buffer = ::Thread.new do
32
+ while !comm_line.eof?
33
+ @value = ::Marshal.load( comm_line )
34
+ end
34
35
  end
36
+
35
37
  end
36
38
 
37
- end
39
+ def write variable_name, data_object
38
40
 
39
- def write variable_name, data_object
41
+ tmp_folder_init
40
42
 
41
- tmp_folder_init
43
+ File.open( File.join(tmp_folder_path,variable_name.to_s) ,"w") do |file|
44
+ return file.write ::Marshal.dump(data_object)
45
+ end
42
46
 
43
- File.open( File.join(tmp_folder_path,variable_name.to_s) ,"w") do |file|
44
- return file.write ::Marshal.dump(data_object)
45
47
  end
46
48
 
47
- end
49
+ def read variable_name
50
+
51
+ unless File.exist?(File.join(tmp_folder_path,variable_name.to_s))
52
+ return nil
53
+ end
48
54
 
49
- def read variable_name
55
+ File.open( File.join(tmp_folder_path,variable_name.to_s) ,"r") do |file|
56
+ return ::Marshal.load file.read
57
+ end
50
58
 
51
- unless File.exist?(File.join(tmp_folder_path,variable_name.to_s))
52
- return nil
53
59
  end
54
60
 
55
- File.open( File.join(tmp_folder_path,variable_name.to_s) ,"r") do |file|
56
- return ::Marshal.load file.read
61
+ def purge_files
62
+
63
+ Dir.glob( File.join( tmp_folder_path,'**','*' ) ).each do |file_path|
64
+
65
+ begin
66
+ File.delete file_path
67
+ rescue Errno::ENOENT
68
+ end
69
+
70
+ end
71
+
57
72
  end
58
73
 
74
+
75
+
76
+ end
77
+ end
78
+
79
+ class << self
80
+
81
+ def write(*args)
82
+ self::Support.write(*args)
83
+ end
84
+
85
+ def read(*args)
86
+ self::Support.read(*args)
59
87
  end
60
88
 
89
+ def purge!
90
+ self::Support.purge_files
91
+ end
92
+
93
+ alias :purge :purge!
94
+
61
95
  end
62
96
 
97
+
63
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi