tmp 1.1.0 → 1.2.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 +4 -4
- data/Gemfile.lock +4 -1
- data/README.md +18 -0
- data/VERSION +1 -1
- data/examples/instance.rb +8 -0
- data/examples/tmp_folder/{hello → test} +0 -0
- data/lib/tmp.rb +3 -1
- data/lib/tmp/config.rb +17 -14
- data/lib/tmp/function.rb +41 -41
- data/lib/tmp/instance.rb +21 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f2a68461818e0e518c1c70d060bc98c72882b45
|
4
|
+
data.tar.gz: e603aa012691e5b0bf991b9f4409ddd96e8c1ee6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd9ca18c8d93f99268bb5b48be214b517c70860ce181275d15a95045313acd27115f2c87a32d75a4f5c6803dad99cad05805d13c2db8853cc05eb7fec82642ff
|
7
|
+
data.tar.gz: 84376beb47f7190032e41982e22312a106cef4854618b8d3ca2fc1b26dc72f19dc731494a4eaf1d9e34d8f778b0dcbeb1c99612719b46b05a7c7fdf4475ef10d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -60,6 +60,24 @@ you can remove tmp objects by purge them
|
|
60
60
|
puts tmp.hello #> nil
|
61
61
|
```
|
62
62
|
|
63
|
+
### Instance use case
|
64
|
+
|
65
|
+
if you want use as an instance for example for your very own module, than you can do this
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
|
69
|
+
require 'tmp'
|
70
|
+
|
71
|
+
# set the folder path at initialize
|
72
|
+
tmp_instance= TMP::Instance.new( File.expand_path(File.join(File.dirname(__FILE__),'tmp_folder')) )
|
73
|
+
|
74
|
+
tmp_instance.write :test, {hello: 'world'}
|
75
|
+
|
76
|
+
puts tmp_instance.read :test
|
77
|
+
puts TMP.read(:test) #> must be nil
|
78
|
+
|
79
|
+
```
|
80
|
+
|
63
81
|
### TODO
|
64
82
|
|
65
83
|
* make ssl encryption for the tmp files opt able
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
File without changes
|
data/lib/tmp.rb
CHANGED
data/lib/tmp/config.rb
CHANGED
@@ -1,30 +1,33 @@
|
|
1
1
|
#encoding: UTF-8
|
2
2
|
module TMP
|
3
|
-
module Config
|
4
|
-
class << self
|
5
|
-
|
6
|
-
def default_folder_path
|
7
|
-
File.join( Dir.tmpdir, ( Dir.pwd.split(File::Separator).last.to_s ) )
|
8
|
-
end
|
9
3
|
|
10
|
-
|
11
|
-
def folder_path path= nil
|
4
|
+
module ConfigCore
|
12
5
|
|
13
|
-
|
6
|
+
def default_folder_path
|
7
|
+
File.join( Dir.tmpdir, ( Dir.pwd.split(File::Separator).last.to_s ) )
|
8
|
+
end
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
10
|
+
@config_path= nil
|
11
|
+
def folder_path path= nil
|
18
12
|
|
19
|
-
|
13
|
+
unless path.nil?
|
20
14
|
|
15
|
+
unless path.class <= String
|
16
|
+
raise ArgumentError,"invalid path class"
|
21
17
|
end
|
22
18
|
|
23
|
-
|
19
|
+
@config_path = File.absolute_path(path)
|
24
20
|
|
25
21
|
end
|
26
22
|
|
23
|
+
@config_path || default_folder_path
|
24
|
+
|
27
25
|
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
module Config
|
30
|
+
extend ConfigCore
|
28
31
|
end
|
29
32
|
|
30
33
|
def self.folder_path obj
|
data/lib/tmp/function.rb
CHANGED
@@ -1,79 +1,79 @@
|
|
1
1
|
#encoding: UTF-8
|
2
2
|
module TMP
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
class << self
|
4
|
+
module SupportCore
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
def tmp_folder_path obj=nil
|
7
|
+
@tmp_folder_path ||= obj
|
8
|
+
@tmp_folder_path || ::TMP::Config.folder_path
|
9
|
+
end
|
11
10
|
|
12
|
-
|
11
|
+
alias :folder_path :tmp_folder_path
|
13
12
|
|
14
|
-
|
13
|
+
def tmp_folder_init
|
15
14
|
|
16
|
-
|
15
|
+
begin
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
rescue Errno::EEXIST
|
22
|
-
return false
|
23
|
-
end
|
17
|
+
Dir.mkdir tmp_folder_path
|
18
|
+
return true
|
24
19
|
|
20
|
+
rescue Errno::EEXIST
|
21
|
+
return false
|
25
22
|
end
|
26
23
|
|
27
|
-
|
24
|
+
end
|
28
25
|
|
29
|
-
|
26
|
+
def read_buffer path
|
30
27
|
|
31
|
-
|
32
|
-
while !comm_line.eof?
|
33
|
-
@value = ::Marshal.load( comm_line )
|
34
|
-
end
|
35
|
-
end
|
28
|
+
comm_line= File.open(path,"r")
|
36
29
|
|
30
|
+
read_buffer = ::Thread.new do
|
31
|
+
while !comm_line.eof?
|
32
|
+
@value = ::Marshal.load( comm_line )
|
33
|
+
end
|
37
34
|
end
|
38
35
|
|
39
|
-
|
36
|
+
end
|
40
37
|
|
41
|
-
|
38
|
+
def write variable_name, data_object
|
42
39
|
|
43
|
-
|
44
|
-
return file.write ::Marshal.dump(data_object)
|
45
|
-
end
|
40
|
+
tmp_folder_init
|
46
41
|
|
42
|
+
File.open( File.join(tmp_folder_path,variable_name.to_s) ,"w") do |file|
|
43
|
+
return file.write ::Marshal.dump(data_object)
|
47
44
|
end
|
48
45
|
|
49
|
-
|
46
|
+
end
|
50
47
|
|
51
|
-
|
52
|
-
return nil
|
53
|
-
end
|
48
|
+
def read variable_name
|
54
49
|
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
unless File.exist?(File.join(tmp_folder_path,variable_name.to_s))
|
51
|
+
return nil
|
52
|
+
end
|
58
53
|
|
54
|
+
File.open( File.join(tmp_folder_path,variable_name.to_s) ,"r") do |file|
|
55
|
+
return ::Marshal.load file.read
|
59
56
|
end
|
60
57
|
|
61
|
-
|
58
|
+
end
|
62
59
|
|
63
|
-
|
60
|
+
def purge_files
|
64
61
|
|
65
|
-
|
66
|
-
File.delete file_path
|
67
|
-
rescue Errno::ENOENT
|
68
|
-
end
|
62
|
+
Dir.glob( File.join( tmp_folder_path,'**','*' ) ).each do |file_path|
|
69
63
|
|
64
|
+
begin
|
65
|
+
File.delete file_path
|
66
|
+
rescue Errno::ENOENT
|
70
67
|
end
|
71
68
|
|
72
69
|
end
|
73
70
|
|
71
|
+
end
|
74
72
|
|
73
|
+
end
|
75
74
|
|
76
|
-
|
75
|
+
module Support
|
76
|
+
extend SupportCore
|
77
77
|
end
|
78
78
|
|
79
79
|
class << self
|
data/lib/tmp/instance.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
module TMP
|
3
|
+
|
4
|
+
class Instance
|
5
|
+
|
6
|
+
include ConfigCore
|
7
|
+
include SupportCore
|
8
|
+
|
9
|
+
def initialize path_string
|
10
|
+
|
11
|
+
unless path_string.class <= String
|
12
|
+
raise ArgumentError, "path must be a string like type"
|
13
|
+
end
|
14
|
+
|
15
|
+
tmp_folder_path path_string
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tmp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: empty_object
|
@@ -69,13 +69,15 @@ files:
|
|
69
69
|
- Rakefile
|
70
70
|
- VERSION
|
71
71
|
- examples/config_exmpl.rb
|
72
|
+
- examples/instance.rb
|
72
73
|
- examples/test.rb
|
73
|
-
- examples/tmp_folder/
|
74
|
+
- examples/tmp_folder/test
|
74
75
|
- files.rb
|
75
76
|
- lib/tmp.rb
|
76
77
|
- lib/tmp/config.rb
|
77
78
|
- lib/tmp/dsl.rb
|
78
79
|
- lib/tmp/function.rb
|
80
|
+
- lib/tmp/instance.rb
|
79
81
|
- tmp.gemspec
|
80
82
|
homepage: https://github.com/adamluzsi/tmp
|
81
83
|
licenses:
|