tmp 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/VERSION +1 -1
- data/examples/blocks.rb +16 -9
- data/lib/tmp/core.rb +19 -4
- data/lib/tmp/dsl.rb +3 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e10614c8749f3942598c9d559b2480bff634f60
|
4
|
+
data.tar.gz: 930e5474223903a4e981df6d5adac55794fdbf33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dcab98b0ca139c615c3249544032f05ca8ef4416fb8579c81251bd0319c4a251ac8a75af9220ada97e3e6ff0fe18a51c209b6fdfec266dbec5622264931cbb9
|
7
|
+
data.tar.gz: 8d9a38ec424dc5a282a19bd4a712851901dbf216e005559b61ec574bd0d6a9d0aabc8754172dd9bbf223bad64146c8738f0c67c1943a1cc7b90545a0cf340a32
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -64,7 +64,11 @@ you can config the folder path for custom tmp folder use case if you dont want t
|
|
64
64
|
|
65
65
|
```ruby
|
66
66
|
|
67
|
+
require 'tmp'
|
67
68
|
|
69
|
+
puts __TMP__.random #> nil or empty string because never used or just freshly initialized file
|
70
|
+
puts __TMP__.random__path__ #> path to random named file,
|
71
|
+
# if not exist, make an empty one
|
68
72
|
|
69
73
|
```
|
70
74
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.
|
1
|
+
2.2.1
|
data/examples/blocks.rb
CHANGED
@@ -1,31 +1,38 @@
|
|
1
1
|
require 'tmp'
|
2
2
|
|
3
|
+
tmp.purge!
|
3
4
|
# using blocks is simply as this
|
5
|
+
tmp.some_file_name "w+" do |file|
|
6
|
+
file.write Random.rand(1000...9999)
|
7
|
+
end
|
8
|
+
|
4
9
|
tmp.some_file_name do |file|
|
5
|
-
file.
|
10
|
+
puts file.readline #> some random number
|
6
11
|
end
|
7
12
|
|
8
13
|
# reopen the new file is also simple
|
9
14
|
tmp.some_file_name do |file|
|
10
15
|
|
11
16
|
while line = file.gets
|
17
|
+
#> some random number same as above
|
12
18
|
puts line
|
13
19
|
end
|
14
20
|
|
15
|
-
file.write Random.rand(100...1000)
|
16
|
-
|
17
21
|
end
|
18
22
|
|
19
23
|
# you can set the file mod if you like, by default it's based on file e
|
20
24
|
tmp.some_file_name "w+" do |file|
|
21
25
|
|
22
|
-
|
23
|
-
puts line
|
24
|
-
end
|
25
|
-
# totaly nothing writed out to console because the "w+"
|
26
|
+
puts file.readlines.inspect #> [] empty array because the file got w+ command
|
26
27
|
|
27
|
-
file.write "
|
28
|
+
file.write "Hello world!"
|
28
29
|
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
+
tmp.some_file_name do |file|
|
33
|
+
puts file.gets.inspect #> "Hello world!"
|
34
|
+
end
|
35
|
+
|
36
|
+
puts tmp.some_file_name__path__
|
37
|
+
|
38
|
+
puts tmp.some_file_name.inspect #> it's a string from the file we made
|
data/lib/tmp/core.rb
CHANGED
@@ -67,18 +67,33 @@ module TMP
|
|
67
67
|
|
68
68
|
end
|
69
69
|
|
70
|
+
def block variable_name, *args, &block_obj
|
71
|
+
|
72
|
+
if File.exist? File.join( tmp_folder_path,variable_name.to_s )
|
73
|
+
args[0] ||= "r+"
|
74
|
+
else
|
75
|
+
args[0] ||= "w+"
|
76
|
+
end
|
77
|
+
|
78
|
+
return File.open( File.join( tmp_folder_path,variable_name.to_s ), args[0], &block_obj)
|
79
|
+
|
80
|
+
end
|
81
|
+
|
70
82
|
def read variable_name
|
71
83
|
|
72
|
-
unless File.exist?(File.join(tmp_folder_path,variable_name.to_s))
|
84
|
+
unless File.exist?(File.join( tmp_folder_path,variable_name.to_s))
|
73
85
|
return nil
|
74
86
|
end
|
75
87
|
|
76
|
-
File.open( File.join(tmp_folder_path,variable_name.to_s) ,"r") do |file|
|
88
|
+
File.open( File.join( tmp_folder_path,variable_name.to_s ) ,"r+") do |file|
|
89
|
+
|
90
|
+
var= file.read
|
77
91
|
begin
|
78
|
-
return ::Marshal.load
|
92
|
+
return ::Marshal.load var
|
79
93
|
rescue
|
80
|
-
return
|
94
|
+
return var
|
81
95
|
end
|
96
|
+
|
82
97
|
end
|
83
98
|
|
84
99
|
end
|
data/lib/tmp/dsl.rb
CHANGED
@@ -13,19 +13,15 @@ module TMP
|
|
13
13
|
def method_missing( method, *args, &block )
|
14
14
|
|
15
15
|
if method.to_s.reverse[0] == '='
|
16
|
+
|
16
17
|
target_obj.__send__ :write, method.to_s.reverse.sub('=','').reverse, args.first
|
17
18
|
return args.first
|
19
|
+
|
18
20
|
else
|
19
21
|
|
20
22
|
unless block.nil?
|
21
23
|
|
22
|
-
|
23
|
-
args[0] ||= "r+"
|
24
|
-
else
|
25
|
-
args[0] ||= "w+"
|
26
|
-
end
|
27
|
-
|
28
|
-
File.open( File.join( target_obj.folder_path, method.to_s ), args[0] ,&block)
|
24
|
+
return target_obj.__send__ :block, method, *args, &block
|
29
25
|
|
30
26
|
else
|
31
27
|
|
@@ -35,7 +31,6 @@ module TMP
|
|
35
31
|
return target_obj.__send__ :read, method
|
36
32
|
end
|
37
33
|
|
38
|
-
|
39
34
|
end
|
40
35
|
|
41
36
|
end
|