tmp 1.1.0 → 1.2.0

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: c9cdcb7143213d0cc2358bc0ad3af6787abe4786
4
- data.tar.gz: 8e5ae50398fb70f6232d27a47a33b6ee9c14a0dd
3
+ metadata.gz: 7f2a68461818e0e518c1c70d060bc98c72882b45
4
+ data.tar.gz: e603aa012691e5b0bf991b9f4409ddd96e8c1ee6
5
5
  SHA512:
6
- metadata.gz: 9501958ca1cf1821a6fb3a2d5bb770a30ab481898582b2736cf7b87737335f57264a9250e2b536c38414e0c4865495c8513747a77ef325934ac95c6b030bef43
7
- data.tar.gz: 22c254e9e7f6c108bfa2018e68bda37a99d8fcc92e3e64d2744ba26ec188faa06f6c5c0c90a73abc3b1abb52d3559d48c142c70eeae1c22a9ead68df5458a3f2
6
+ metadata.gz: dd9ca18c8d93f99268bb5b48be214b517c70860ce181275d15a95045313acd27115f2c87a32d75a4f5c6803dad99cad05805d13c2db8853cc05eb7fec82642ff
7
+ data.tar.gz: 84376beb47f7190032e41982e22312a106cef4854618b8d3ca2fc1b26dc72f19dc731494a4eaf1d9e34d8f778b0dcbeb1c99612719b46b05a7c7fdf4475ef10d
@@ -1,16 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tmp (0.0.1.pre)
4
+ tmp (1.2.0)
5
5
  empty_object
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
10
  empty_object (1.0.0)
11
+ rake (10.2.2)
11
12
 
12
13
  PLATFORMS
13
14
  ruby
14
15
 
15
16
  DEPENDENCIES
17
+ bundler
18
+ rake
16
19
  tmp!
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.0
1
+ 1.2.0
@@ -0,0 +1,8 @@
1
+ require 'tmp'
2
+
3
+ tmp_instance= TMP::Instance.new( File.expand_path(File.join(File.dirname(__FILE__),'tmp_folder')) )
4
+
5
+ tmp_instance.write :test, {hello: 'world'}
6
+
7
+ puts tmp_instance.read :test
8
+ puts TMP.read(:test) #> must be nil
File without changes
data/lib/tmp.rb CHANGED
@@ -5,4 +5,6 @@ require 'empty_object'
5
5
 
6
6
  require 'tmp/config'
7
7
  require 'tmp/function'
8
- require 'tmp/dsl'
8
+ require 'tmp/dsl'
9
+
10
+ require 'tmp/instance'
@@ -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
- @@config_path= nil
11
- def folder_path path= nil
4
+ module ConfigCore
12
5
 
13
- unless path.nil?
6
+ def default_folder_path
7
+ File.join( Dir.tmpdir, ( Dir.pwd.split(File::Separator).last.to_s ) )
8
+ end
14
9
 
15
- unless path.class <= String
16
- raise ArgumentError,"invalid path class"
17
- end
10
+ @config_path= nil
11
+ def folder_path path= nil
18
12
 
19
- @@config_path = File.absolute_path(path)
13
+ unless path.nil?
20
14
 
15
+ unless path.class <= String
16
+ raise ArgumentError,"invalid path class"
21
17
  end
22
18
 
23
- @@config_path || default_folder_path
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
@@ -1,79 +1,79 @@
1
1
  #encoding: UTF-8
2
2
  module TMP
3
3
 
4
- module Support
5
-
6
- class << self
4
+ module SupportCore
7
5
 
8
- def tmp_folder_path
9
- ::TMP::Config.folder_path
10
- end
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
- alias :folder_path :tmp_folder_path
11
+ alias :folder_path :tmp_folder_path
13
12
 
14
- def tmp_folder_init
13
+ def tmp_folder_init
15
14
 
16
- begin
15
+ begin
17
16
 
18
- Dir.mkdir tmp_folder_path
19
- return true
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
- def read_buffer path
24
+ end
28
25
 
29
- comm_line= File.open(path,"r")
26
+ def read_buffer path
30
27
 
31
- read_buffer = ::Thread.new do
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
- def write variable_name, data_object
36
+ end
40
37
 
41
- tmp_folder_init
38
+ def write variable_name, data_object
42
39
 
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
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
- def read variable_name
46
+ end
50
47
 
51
- unless File.exist?(File.join(tmp_folder_path,variable_name.to_s))
52
- return nil
53
- end
48
+ def read variable_name
54
49
 
55
- File.open( File.join(tmp_folder_path,variable_name.to_s) ,"r") do |file|
56
- return ::Marshal.load file.read
57
- end
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
- def purge_files
58
+ end
62
59
 
63
- Dir.glob( File.join( tmp_folder_path,'**','*' ) ).each do |file_path|
60
+ def purge_files
64
61
 
65
- begin
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
- end
75
+ module Support
76
+ extend SupportCore
77
77
  end
78
78
 
79
79
  class << self
@@ -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.1.0
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-08 00:00:00.000000000 Z
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/hello
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: