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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e66a42b973054f5d571c6e8732470f943fe5f005
4
- data.tar.gz: 9dc2be715eec51546ddbb6d4cdfe4720c61a3580
3
+ metadata.gz: 1e10614c8749f3942598c9d559b2480bff634f60
4
+ data.tar.gz: 930e5474223903a4e981df6d5adac55794fdbf33
5
5
  SHA512:
6
- metadata.gz: f8ac7b605356c620670439776686854ab917c80223270619efaa88dc40bf642627e67a33ca6dba923f012b526c52350715711b623af3a9af31a31026b0105b8e
7
- data.tar.gz: c54e7a1ed989f95dce5aa018323c0286ac394c892d3485b6e83b295f61953b8069e9119e4141d6c20e1bdd0a94ce61e8f1b3689b23d37bb097a4475b43d2c79f
6
+ metadata.gz: 5dcab98b0ca139c615c3249544032f05ca8ef4416fb8579c81251bd0319c4a251ac8a75af9220ada97e3e6ff0fe18a51c209b6fdfec266dbec5622264931cbb9
7
+ data.tar.gz: 8d9a38ec424dc5a282a19bd4a712851901dbf216e005559b61ec574bd0d6a9d0aabc8754172dd9bbf223bad64146c8738f0c67c1943a1cc7b90545a0cf340a32
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tmp (2.2.0)
4
+ tmp (2.2.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
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.0
1
+ 2.2.1
@@ -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.write Random.rand(100...1000)
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
- while line = file.gets
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 "hello world!"
28
+ file.write "Hello world!"
28
29
 
29
30
  end
30
31
 
31
- puts tmp.some_file_name #> it's a string from the file we made
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
@@ -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 file.read
92
+ return ::Marshal.load var
79
93
  rescue
80
- return file.read
94
+ return var
81
95
  end
96
+
82
97
  end
83
98
 
84
99
  end
@@ -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
- if File.exist? File.join( target_obj.folder_path, method.to_s )
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
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: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi