tmp 3.1.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +36 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +16 -1
- data/README.md +26 -154
- data/Rakefile +3 -0
- data/VERSION +1 -1
- data/bin/console +9 -0
- data/lib/tmp.rb +12 -5
- data/spec/spec_helper.rb +2 -0
- data/tmp.gemspec +11 -8
- metadata +23 -11
- data/examples/tmp_folder/hello +0 -3
- data/examples/tmp_folder/test +0 -2
- data/examples/tmp_folder/test_file +0 -1
- data/lib/tmp/core.rb +0 -176
- data/lib/tmp/dsl.rb +0 -62
- data/lib/tmp/init.rb +0 -49
- data/lib/tmp/sup.rb +0 -92
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 483eb950ab983710d8486dda03faa403671d3b68
|
4
|
+
data.tar.gz: a8028f1d1e5c48228216b3492376fdb209a54b55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 453c5af9abca249cc6a9a6045b980a1dc5a4ca7637ebdd614ef7718903c6e37838be55322215d180fa139d3a015f1f96e259c923f8d34146e5506ec6230fe2dd
|
7
|
+
data.tar.gz: 8585bdb016f1ec0e4a5e572e96a22cc732e5079701154f13ae775a57ca085d89948c2e3630618904eda9e67d43a4a7bb51f7f44d3178a8cf7f94fe58616c8384
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
/examples/tmp_folder
|
2
|
+
|
3
|
+
*.gem
|
4
|
+
*.rbc
|
5
|
+
/.config
|
6
|
+
/coverage/
|
7
|
+
/InstalledFiles
|
8
|
+
/pkg/
|
9
|
+
/spec/reports/
|
10
|
+
/test/tmp/
|
11
|
+
/test/version_tmp/
|
12
|
+
/tmp/
|
13
|
+
|
14
|
+
## Specific to RubyMotion:
|
15
|
+
.dat*
|
16
|
+
.repl_history
|
17
|
+
build/
|
18
|
+
|
19
|
+
## Documentation cache and generated files:
|
20
|
+
/.yardoc/
|
21
|
+
/_yardoc/
|
22
|
+
/doc/
|
23
|
+
/rdoc/
|
24
|
+
|
25
|
+
## Environment normalisation:
|
26
|
+
/.bundle/
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'http://rubygems.org'
|
2
2
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tmp (
|
4
|
+
tmp (4.0.0.alpha)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
+
diff-lcs (1.2.5)
|
9
10
|
rake (10.2.2)
|
11
|
+
rspec (3.2.0)
|
12
|
+
rspec-core (~> 3.2.0)
|
13
|
+
rspec-expectations (~> 3.2.0)
|
14
|
+
rspec-mocks (~> 3.2.0)
|
15
|
+
rspec-core (3.2.3)
|
16
|
+
rspec-support (~> 3.2.0)
|
17
|
+
rspec-expectations (3.2.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.2.0)
|
20
|
+
rspec-mocks (3.2.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.2.0)
|
23
|
+
rspec-support (3.2.2)
|
10
24
|
|
11
25
|
PLATFORMS
|
12
26
|
ruby
|
@@ -14,4 +28,5 @@ PLATFORMS
|
|
14
28
|
DEPENDENCIES
|
15
29
|
bundler
|
16
30
|
rake
|
31
|
+
rspec
|
17
32
|
tmp!
|
data/README.md
CHANGED
@@ -14,175 +14,48 @@ The goal is to provide dsl for easy tmp files making on the filesystem in the ob
|
|
14
14
|
|
15
15
|
By default i's always IO work and not memory,
|
16
16
|
everything you save with this will be IO command and not memory management
|
17
|
-
|
17
|
+
Every IO command handled by the systems File lock "mutex",
|
18
|
+
so there will be no different data in different proc threads.
|
18
19
|
|
19
20
|
### Example
|
20
21
|
|
21
|
-
In the Examples i will use most likely the 'tmp' name, what is a syntax sugar
|
22
|
-
The real object(module) being called all the time is the TMP::DSL
|
23
|
-
The DSL will make easy the job on you but you can use the default methods alike:
|
24
|
-
|
25
|
-
* TMP.write( file_name, object )
|
26
|
-
* object
|
27
|
-
* TMP.read( file_name )
|
28
|
-
* object
|
29
|
-
* TMP.path( file_name )
|
30
|
-
* string
|
31
|
-
|
32
22
|
```ruby
|
33
23
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
#
|
40
|
-
|
41
|
-
|
42
|
-
#
|
43
|
-
|
24
|
+
tmp = TMP.new
|
25
|
+
|
26
|
+
# get current tmpdir
|
27
|
+
tmp.tmpdir #> current tmp dir
|
28
|
+
|
29
|
+
# get 'cat' value
|
30
|
+
tmp['cat'] #> nil
|
31
|
+
|
32
|
+
# set 'cat' value
|
33
|
+
tmp['cat'] = {a:1}
|
34
|
+
|
35
|
+
# get 'cat' value and compare to an object
|
36
|
+
tmp['cat'] == {a:1} #> true
|
37
|
+
|
38
|
+
# this will also handled with system io mutex
|
39
|
+
tmp.open('something','w+') do |f|
|
40
|
+
|
41
|
+
p f.read
|
42
|
+
|
43
|
+
end
|
44
|
+
|
44
45
|
|
45
46
|
```
|
46
47
|
|
47
48
|
### Config
|
48
49
|
|
49
|
-
you can config the folder path for custom tmp folder use case if you dont want to use the systems default tmp folder/
|
50
|
-
|
51
|
-
```ruby
|
52
|
-
|
53
|
-
require 'tmp'
|
54
|
-
|
55
|
-
# set folder path if we dont want to use
|
56
|
-
# the default system_tmp/our_project_folder_name/
|
57
|
-
TMP.folder_path "/super/awesome/path/to/my/wished/folder"
|
58
|
-
|
59
|
-
# to check what is the default folder path just use this
|
60
|
-
TMP.default_folder_path #> return default path
|
61
|
-
|
62
|
-
# to check the current path use this
|
63
|
-
TMP.folder_path #> return the current path
|
64
|
-
|
65
|
-
```
|
66
|
-
|
67
|
-
### Get file path for the tmp object
|
50
|
+
you can config the folder path for custom tmp folder use case if you dont want to use the systems default tmp folder/
|
68
51
|
|
69
52
|
```ruby
|
70
53
|
|
71
54
|
require 'tmp'
|
72
|
-
|
73
|
-
puts __TMP__.random #> nil or empty string because never used or just freshly initialized file
|
74
|
-
puts __TMP__.random__path__ #> path to random named file,
|
75
|
-
# if not exist, make an empty one
|
55
|
+
tmp = TMP.new "/super/awesome/path/to/my/wished/folder"
|
76
56
|
|
77
57
|
```
|
78
58
|
|
79
|
-
### Remove tmp objects
|
80
|
-
|
81
|
-
you can remove tmp objects by purge them
|
82
|
-
|
83
|
-
```ruby
|
84
|
-
|
85
|
-
require 'tmp'
|
86
|
-
|
87
|
-
__tmp__.hello = { hello: 'world'}
|
88
|
-
|
89
|
-
__tmp__.hello #> { hello: 'world'} -> hash obj
|
90
|
-
|
91
|
-
TMP.purge!
|
92
|
-
|
93
|
-
# now it's nil
|
94
|
-
__tmp__.hello #> nil
|
95
|
-
|
96
|
-
```
|
97
|
-
|
98
|
-
### Instance use case for modules or separated tmp folders
|
99
|
-
|
100
|
-
if you want use as an instance for example for your very own module, than you can do this
|
101
|
-
|
102
|
-
```ruby
|
103
|
-
|
104
|
-
require 'tmp'
|
105
|
-
|
106
|
-
tmp_instance= TMP.new( File.expand_path(File.join(File.dirname(__FILE__),'tmp_folder')) )
|
107
|
-
|
108
|
-
# use the same as the TMP::DSL aka tmp method
|
109
|
-
|
110
|
-
# let's set a string for this one
|
111
|
-
tmp_instance.test= "hello"
|
112
|
-
|
113
|
-
# get the string what we just set now
|
114
|
-
tmp_instance.test #> "hello"
|
115
|
-
|
116
|
-
# you can get the tmp class instance obj like this:
|
117
|
-
tmp_instance.tmp_class_instance_object #> return the tmp_instance
|
118
|
-
|
119
|
-
# return the tmp folder path
|
120
|
-
tmp_instance.tmp_class_instance_object.folder_path
|
121
|
-
|
122
|
-
# Remember this instance use different folder thant the main TMP::DSL
|
123
|
-
__tmp__.test.inspect #> nil, because it was never used before
|
124
|
-
#> the tmp method is same like invoke the TMP::DSL module
|
125
|
-
|
126
|
-
|
127
|
-
```
|
128
|
-
|
129
|
-
### Blocks for file commands
|
130
|
-
|
131
|
-
using blocks is nothing like cupcake in Ruby, and just alike in this dsl
|
132
|
-
|
133
|
-
|
134
|
-
```ruby
|
135
|
-
|
136
|
-
require 'tmp'
|
137
|
-
|
138
|
-
# using blocks is simply as this
|
139
|
-
__tmp__.some_file_name do |file|
|
140
|
-
file.write Random.rand(100...1000)
|
141
|
-
end
|
142
|
-
|
143
|
-
# reopen the new file is also simple
|
144
|
-
__tmp__.some_file_name do |file|
|
145
|
-
|
146
|
-
while line = file.gets
|
147
|
-
puts line
|
148
|
-
end
|
149
|
-
|
150
|
-
file.write Random.rand(100...1000)
|
151
|
-
|
152
|
-
end
|
153
|
-
|
154
|
-
# you can set the file mod if you like, by default it's based on file e
|
155
|
-
__tmp__.some_file_name "w+" do |file|
|
156
|
-
|
157
|
-
while line = file.gets
|
158
|
-
puts line
|
159
|
-
end
|
160
|
-
# totaly nothing writed out to console because the "w+"
|
161
|
-
|
162
|
-
file.write "hello world!"
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
puts __tmp__.some_file_name #> it's a string from the file we made
|
167
|
-
|
168
|
-
```
|
169
|
-
|
170
|
-
### Miscs
|
171
|
-
|
172
|
-
```ruby
|
173
|
-
|
174
|
-
__tmp__.tmpdir #> system temp folder
|
175
|
-
|
176
|
-
__tmp__.project_folder #> folder name where the project is
|
177
|
-
#> alias: project_name
|
178
|
-
|
179
|
-
__tmp__.default_folder_path #> path to the default tmp folder
|
180
|
-
|
181
|
-
__tmp__.tmp_folder_path #> path to the now used tmp folder
|
182
|
-
#> it is resettable by passing a string to the method
|
183
|
-
#> alias: folder_path
|
184
|
-
|
185
|
-
```
|
186
59
|
|
187
60
|
### File mod cheat sheet
|
188
61
|
|
@@ -223,5 +96,4 @@ using blocks is nothing like cupcake in Ruby, and just alike in this dsl
|
|
223
96
|
### TODO
|
224
97
|
|
225
98
|
* make ssl encryption or chmod persm change for the tmp files protection as options
|
226
|
-
*
|
227
|
-
* find contributors
|
99
|
+
* create destructor upon tmp object destruction
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
4.0.0
|
data/bin/console
ADDED
data/lib/tmp.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
#encoding: UTF-8
|
2
|
+
module TMP
|
2
3
|
|
3
|
-
require '
|
4
|
+
require 'tmp/instance'
|
4
5
|
|
5
|
-
require 'tmp/core'
|
6
|
-
require 'tmp/sup'
|
6
|
+
require 'tmp/deprecated/core'
|
7
|
+
require 'tmp/deprecated/sup'
|
7
8
|
|
8
|
-
require 'tmp/dsl'
|
9
|
-
require 'tmp/init'
|
9
|
+
require 'tmp/deprecated/dsl'
|
10
|
+
require 'tmp/deprecated/init'
|
11
|
+
|
12
|
+
def self.new(*args)
|
13
|
+
Instance.new(*args)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tmp.gemspec
CHANGED
@@ -5,20 +5,23 @@ require File.expand_path(File.join(File.dirname(__FILE__),"files.rb"))
|
|
5
5
|
### Specification for the new Gem
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'tmp'
|
9
9
|
spec.version = File.open(File.join(File.dirname(__FILE__),"VERSION")).read.split("\n")[0].chomp.gsub(' ','')
|
10
|
-
|
11
|
-
spec.
|
12
|
-
spec.
|
10
|
+
|
11
|
+
spec.authors = ['Adam Luzsi']
|
12
|
+
spec.email = ['adamluzsi@gmail.com']
|
13
|
+
|
13
14
|
spec.summary = %q{ DSL for temporally files read/write in the object oriented way (system tmp) }
|
14
|
-
spec.
|
15
|
-
|
15
|
+
spec.description = %q{ DSL for temporally files read/write in the object oriented way (system tmp). Manage tmp files in the super easy way! This dsl let you have simply way to commands and create variables on file system by default in the actual systems (cross platform) tmp folder. Sometimes it can be useful for multi processing (forked processes), but the main goal is not made for shared memory management! The goal is to provide dsl for easy tmp files making on the filesystem in the object oriented way (real objects and not simply strings). By default i's always IO work and not memory, everything you save with this will be IO command and not memory }
|
16
|
+
|
17
|
+
spec.homepage = 'https://github.com/adamluzsi/tmp'
|
18
|
+
spec.license = 'MIT'
|
16
19
|
|
17
|
-
spec.files =
|
20
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
22
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
23
|
spec.require_paths = ["lib"]
|
21
24
|
|
22
|
-
%W[ rake bundler ].each{ |gem_name| spec.add_development_dependency(gem_name) }
|
25
|
+
%W[ rake bundler rspec ].each{ |gem_name| spec.add_development_dependency(gem_name) }
|
23
26
|
|
24
27
|
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:
|
4
|
+
version: 4.0.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:
|
11
|
+
date: 2015-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: " DSL for temporally files read/write in the object oriented way (system
|
42
56
|
tmp). Manage tmp files in the super easy way! This dsl let you have simply way to
|
43
57
|
commands and create variables on file system by default in the actual systems (cross
|
@@ -48,31 +62,28 @@ description: " DSL for temporally files read/write in the object oriented way (s
|
|
48
62
|
you save with this will be IO command and not memory "
|
49
63
|
email:
|
50
64
|
- adamluzsi@gmail.com
|
51
|
-
executables:
|
65
|
+
executables:
|
66
|
+
- console
|
52
67
|
extensions: []
|
53
68
|
extra_rdoc_files: []
|
54
69
|
files:
|
70
|
+
- ".gitignore"
|
55
71
|
- Gemfile
|
56
72
|
- Gemfile.lock
|
57
73
|
- LICENSE
|
58
74
|
- README.md
|
59
75
|
- Rakefile
|
60
76
|
- VERSION
|
77
|
+
- bin/console
|
61
78
|
- examples/blocks.rb
|
62
79
|
- examples/config_exmpl.rb
|
63
80
|
- examples/instance.rb
|
64
81
|
- examples/path.rb
|
65
82
|
- examples/sugar_use.rb
|
66
83
|
- examples/test.rb
|
67
|
-
- examples/tmp_folder/hello
|
68
|
-
- examples/tmp_folder/test
|
69
|
-
- examples/tmp_folder/test_file
|
70
84
|
- files.rb
|
71
85
|
- lib/tmp.rb
|
72
|
-
-
|
73
|
-
- lib/tmp/dsl.rb
|
74
|
-
- lib/tmp/init.rb
|
75
|
-
- lib/tmp/sup.rb
|
86
|
+
- spec/spec_helper.rb
|
76
87
|
- tmp.gemspec
|
77
88
|
homepage: https://github.com/adamluzsi/tmp
|
78
89
|
licenses:
|
@@ -98,4 +109,5 @@ rubygems_version: 2.2.2
|
|
98
109
|
signing_key:
|
99
110
|
specification_version: 4
|
100
111
|
summary: DSL for temporally files read/write in the object oriented way (system tmp)
|
101
|
-
test_files:
|
112
|
+
test_files:
|
113
|
+
- spec/spec_helper.rb
|
data/examples/tmp_folder/hello
DELETED
data/examples/tmp_folder/test
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
hello world!
|
data/lib/tmp/core.rb
DELETED
@@ -1,176 +0,0 @@
|
|
1
|
-
#encoding: UTF-8
|
2
|
-
module TMP
|
3
|
-
|
4
|
-
module CORE
|
5
|
-
|
6
|
-
def project_name name_string= nil
|
7
|
-
|
8
|
-
unless name_string.nil?
|
9
|
-
|
10
|
-
unless name_string.class <= String
|
11
|
-
raise ArgumentError,"invalid name string"
|
12
|
-
end
|
13
|
-
|
14
|
-
@project_name = name_string
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
@project_name || Dir.pwd.split(File::Separator).last.to_s
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
alias :project_folder :project_name
|
23
|
-
|
24
|
-
def tmpdir
|
25
|
-
::Dir.tmpdir
|
26
|
-
end
|
27
|
-
|
28
|
-
def default_folder_path
|
29
|
-
File.join( tmpdir , project_name )
|
30
|
-
end
|
31
|
-
|
32
|
-
@folder_path= nil
|
33
|
-
def tmp_folder_path path_string= nil
|
34
|
-
|
35
|
-
unless path_string.nil?
|
36
|
-
|
37
|
-
unless path_string.class <= String
|
38
|
-
raise ArgumentError,"invalid path class, must be string like"
|
39
|
-
end
|
40
|
-
|
41
|
-
@folder_path = File.absolute_path(path_string)
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
@folder_path || default_folder_path
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
alias :folder_path :tmp_folder_path
|
50
|
-
|
51
|
-
def tmp_folder_init
|
52
|
-
|
53
|
-
begin
|
54
|
-
|
55
|
-
Dir.mkdir tmp_folder_path
|
56
|
-
return true
|
57
|
-
|
58
|
-
rescue Errno::EEXIST
|
59
|
-
return false
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
alias :folder_init :tmp_folder_init
|
65
|
-
|
66
|
-
def write variable_name, data_object
|
67
|
-
|
68
|
-
tmp_folder_init
|
69
|
-
|
70
|
-
File.open( File.join(tmp_folder_path,variable_name.to_s) ,"w") do |file|
|
71
|
-
return file.write ::Marshal.dump(data_object)
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
def block variable_name, *args, &block_obj
|
77
|
-
|
78
|
-
tmp_folder_init
|
79
|
-
|
80
|
-
options = args.select{|e|(e.class <= ::Hash)}.reduce({},:merge!)
|
81
|
-
args.select!{|e|!(e.class <= ::Hash)}
|
82
|
-
|
83
|
-
options[:file_extension] ||= options[:extension] || options[:ext]
|
84
|
-
file_name = variable_name.to_s
|
85
|
-
options[:file_mod] ||= options[:mod] || args[0].class <= ::String ? args[0] : nil
|
86
|
-
|
87
|
-
unless options[:file_extension].nil?
|
88
|
-
|
89
|
-
while options[:file_extension][0] == '.'
|
90
|
-
options[:file_extension][0]= ''
|
91
|
-
end
|
92
|
-
|
93
|
-
file_name += ".#{options[:file_extension]}"
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
if File.exist?(File.join( tmp_folder_path, file_name ))
|
98
|
-
options[:file_mod] ||= "r+"
|
99
|
-
else
|
100
|
-
options[:file_mod] ||= "w+"
|
101
|
-
end
|
102
|
-
|
103
|
-
begin
|
104
|
-
return File.open( File.join( tmp_folder_path, file_name ), options[:file_mod], &block_obj )
|
105
|
-
rescue Errno::ENOENT
|
106
|
-
var_file= File.new( File.join( tmp_folder_path, file_name ), options[:file_mod])
|
107
|
-
block_obj.call(var_file) unless block_obj.nil?
|
108
|
-
var_file.close
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
def read variable_name
|
114
|
-
|
115
|
-
unless File.exist?(File.join( tmp_folder_path,variable_name.to_s))
|
116
|
-
return nil
|
117
|
-
end
|
118
|
-
|
119
|
-
File.open( File.join( tmp_folder_path,variable_name.to_s ) ,"r+") do |file|
|
120
|
-
|
121
|
-
var= file.read
|
122
|
-
begin
|
123
|
-
return ::Marshal.load var
|
124
|
-
rescue
|
125
|
-
return var
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
def path variable_name,*args
|
133
|
-
|
134
|
-
options = args.select{|e|(e.class <= ::Hash)}.reduce({},:merge!)
|
135
|
-
args.select!{|e|!(e.class <= ::Hash)}
|
136
|
-
|
137
|
-
variable_name = variable_name.to_s
|
138
|
-
options[:file_extension] ||= options[:extension] || options[:ext]
|
139
|
-
unless options[:file_extension].nil?
|
140
|
-
while options[:file_extension][0] == '.'
|
141
|
-
options[:file_extension][0]= ''
|
142
|
-
end
|
143
|
-
variable_name += ".#{options[:file_extension]}"
|
144
|
-
end
|
145
|
-
|
146
|
-
tmp_folder_init
|
147
|
-
path_to_file= File.join( tmp_folder_path, variable_name )
|
148
|
-
unless File.exist?(path_to_file)
|
149
|
-
File.open( path_to_file ,"w") {|f| f.write(""); f.close }
|
150
|
-
end
|
151
|
-
return path_to_file
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
def purge_files
|
156
|
-
|
157
|
-
Dir.glob( File.join( tmp_folder_path,'**','*' ) ).map do |file_path|
|
158
|
-
|
159
|
-
begin
|
160
|
-
File.delete file_path
|
161
|
-
rescue Errno::ENOENT => ex
|
162
|
-
ex
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
alias :purge! :purge_files
|
170
|
-
alias :purge :purge_files
|
171
|
-
|
172
|
-
end
|
173
|
-
|
174
|
-
extend CORE
|
175
|
-
|
176
|
-
end
|
data/lib/tmp/dsl.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
#encoding: UTF-8
|
2
|
-
module TMP
|
3
|
-
|
4
|
-
module DSLCore
|
5
|
-
|
6
|
-
def target_obj obj=nil
|
7
|
-
|
8
|
-
@target_obj= obj unless obj.nil?
|
9
|
-
@target_obj || ::TMP
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def method_missing( method, *args, &block )
|
14
|
-
|
15
|
-
if method.to_s.reverse[0] == '='
|
16
|
-
|
17
|
-
target_obj.__send__ :write, method.to_s.reverse.sub('=','').reverse, args.first
|
18
|
-
return args.first
|
19
|
-
|
20
|
-
else
|
21
|
-
|
22
|
-
unless block.nil?
|
23
|
-
|
24
|
-
return target_obj.__send__ :block, method, *args, &block
|
25
|
-
|
26
|
-
else
|
27
|
-
|
28
|
-
if method =~ /^\w+__path__$/
|
29
|
-
return target_obj.__send__ :path, method.to_s.sub!( /__path__$/,"" ),*args
|
30
|
-
else
|
31
|
-
return target_obj.__send__ :read, method
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
module DSL
|
43
|
-
|
44
|
-
extend ObjectExt
|
45
|
-
extend DSLCore
|
46
|
-
privatize
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
module SyntaxSugar
|
51
|
-
|
52
|
-
def __tmp__
|
53
|
-
::TMP::DSL
|
54
|
-
end
|
55
|
-
|
56
|
-
alias :__TMP__ :__tmp__
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
Object.__send__ :include, ::TMP::SyntaxSugar
|
data/lib/tmp/init.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
#encoding: UTF-8
|
2
|
-
module TMP
|
3
|
-
|
4
|
-
class InstanceCore
|
5
|
-
|
6
|
-
include CORE
|
7
|
-
|
8
|
-
def initialize path_string
|
9
|
-
|
10
|
-
unless path_string.class <= String
|
11
|
-
raise ArgumentError, "path must be a string like type"
|
12
|
-
end
|
13
|
-
|
14
|
-
folder_path path_string
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
class InstanceDSL
|
21
|
-
|
22
|
-
extend ObjectExt
|
23
|
-
include DSLCore
|
24
|
-
|
25
|
-
def initialize path_string
|
26
|
-
target_obj InstanceCore.new( path_string )
|
27
|
-
end
|
28
|
-
|
29
|
-
privatize t: 'instance'
|
30
|
-
|
31
|
-
public
|
32
|
-
|
33
|
-
|
34
|
-
def tmp_class_instance_object
|
35
|
-
target_obj
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
class << self
|
41
|
-
|
42
|
-
def new *args
|
43
|
-
InstanceDSL.new *args
|
44
|
-
end
|
45
|
-
alias :init :new
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
data/lib/tmp/sup.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
#encoding: UTF-8
|
2
|
-
module TMP
|
3
|
-
|
4
|
-
module ObjectExt
|
5
|
-
|
6
|
-
def privatize opts= {}
|
7
|
-
|
8
|
-
unless opts.class <= Hash
|
9
|
-
raise ArgumentError,"invalid input for options"
|
10
|
-
end
|
11
|
-
|
12
|
-
%W[ e ex exc ].each do |str_sym|
|
13
|
-
opts[:exclude] ||= opts[str_sym.to_sym]
|
14
|
-
end
|
15
|
-
|
16
|
-
%W[ i in inc only methods ].each do |str_sym|
|
17
|
-
opts[:include] ||= opts[str_sym.to_sym]
|
18
|
-
end
|
19
|
-
|
20
|
-
%W[ t target ].each do |str_sym|
|
21
|
-
opts[:target] ||= opts[str_sym.to_sym]
|
22
|
-
end
|
23
|
-
|
24
|
-
opts[:target] ||= 's'
|
25
|
-
opts[:target]= opts[:target].to_s.downcase
|
26
|
-
|
27
|
-
unless opts[:target][0] == "s" || opts[:target][0] == "i"
|
28
|
-
%W[ singleton instance ].include?(opts[:target].to_s)
|
29
|
-
raise ArgumentError, [
|
30
|
-
"invalid options for target, you should use the following: ",
|
31
|
-
"\n\tsingleton for targeting the singleton class what is de",
|
32
|
-
"fault\n\tinstance for targeting the object instance methods."
|
33
|
-
].join
|
34
|
-
end
|
35
|
-
|
36
|
-
opts[:exclude] ||= []
|
37
|
-
|
38
|
-
if opts[:target][0] == 'i' && self.class <= Module
|
39
|
-
opts[:include] ||= self.instance_methods.map{|e| e.to_s }
|
40
|
-
else
|
41
|
-
opts[:target]= 's'
|
42
|
-
opts[:include] ||= self.methods.map{|e| e.to_s }
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
[:include,:exclude].each do |array_name|
|
47
|
-
|
48
|
-
unless opts[array_name].class <= Array
|
49
|
-
opts[array_name]= [ opts[array_name] ]
|
50
|
-
end
|
51
|
-
|
52
|
-
opts[array_name].map!{ |element| ( element.class == String ? element : element.to_s ) }
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
opts[:exclude].push('__send__').push('object_id')
|
57
|
-
|
58
|
-
if opts[:target][0] == 's'
|
59
|
-
|
60
|
-
self.instance_eval do
|
61
|
-
|
62
|
-
opts[:include].each do |sym|
|
63
|
-
|
64
|
-
unless opts[:exclude].include?(sym)
|
65
|
-
(class << self; self; end).__send__ :private, sym
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
elsif opts[:target][0] == 'i'
|
72
|
-
|
73
|
-
opts[:include].each do |sym|
|
74
|
-
|
75
|
-
unless opts[:exclude].include?(sym)
|
76
|
-
self.__send__ :private, sym
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
else
|
82
|
-
STDERR.puts "invalid target definition"
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
end
|