procemon 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -107,60 +107,54 @@ module Kernel
107
107
 
108
108
  # require by absolute path directory's files
109
109
  def require_directory(folder)
110
- get_files(folder).each do |file_name,file_path|
111
- if file_path.split('.').last == 'rb'
112
- load file_path
113
- end
110
+ Dir.glob(File.join(folder,"**","*.{rb,ru}")).each do |file_path|
111
+ require file_path
114
112
  end
115
113
  end
116
114
 
117
115
  # require sender relative directory's files
116
+ # return the directory and the sub directories file names (rb/ru)
118
117
  def require_relative_directory(folder)
119
118
 
120
119
  # pre format
121
120
  begin
122
121
 
123
- path= caller[0].split('.{rb,ru}:').first.split(File::SEPARATOR)
124
- path= path[0..(path.count-2)]
125
-
126
- if !File.directory?(path.join(File::SEPARATOR))
127
- path.pop
122
+ # path create from caller
123
+ begin
124
+ path= caller[0].split(".{rb,ru}:").first.split(File::SEPARATOR)
125
+ path= path[0..(path.count-2)]
128
126
  end
129
127
 
130
- path= File.join(path.join(File::SEPARATOR))
128
+ # after formatting
129
+ begin
131
130
 
132
- if path != File.expand_path(path)
133
- path= File.expand_path(path)
134
- end
131
+ if !File.directory?(path.join(File::SEPARATOR))
132
+ path.pop
133
+ end
134
+ path= File.join(path.join(File::SEPARATOR))
135
+ if path != File.expand_path(path)
136
+ path= File.expand_path(path)
137
+ end
135
138
 
136
- path= File.join(path,folder)
139
+ end
137
140
 
138
141
  end
139
142
 
140
143
  # find elements
141
144
  begin
142
- tmp_array = Array.new
143
- get_files(path).sort.each do |file_name,file_path|
144
- if file_path.split('.').last == 'rb'
145
- tmp_array.push file_path
146
- end
147
- end
148
- end
149
-
150
- # after format
151
- begin
152
- tmp_array.uniq!
153
- tmp_array.sort!
154
- tmp_array.each do |full_path_to_file|
155
- require full_path_to_file
145
+ return Dir.glob(File.join(path,folder,"**","*.{rb,ru}")).each do |one_path|
146
+ require one_path
156
147
  end
157
148
  end
158
149
 
159
150
  end
160
151
 
161
152
  # generate config from yaml
162
- def generate_config(target_folder= File.join(Dir.pwd,"lib", "**","meta"),
163
- target_config_hash= Application.config)
153
+ def generate_config(
154
+ target_folder= File.join(Dir.pwd,"lib", "**","meta"),
155
+ override= true,
156
+ target_config_hash= Application.config
157
+ )
164
158
 
165
159
  # defaults
166
160
  begin
@@ -172,7 +166,6 @@ module Kernel
172
166
 
173
167
  # find elements
174
168
  begin
175
-
176
169
  Dir.glob(File.join(target_folder,"*.{yaml,yml}")).each do |config_object|
177
170
 
178
171
  # defaults
@@ -190,14 +183,16 @@ module Kernel
190
183
  if target_config_hash[category].nil?
191
184
  target_config_hash[category]= { type => yaml_data }
192
185
  else
193
- target_config_hash[category][type]= yaml_data
186
+ unless override == false
187
+ target_config_hash[category][type]= yaml_data
188
+ end
194
189
  end
195
190
  end
196
191
 
197
192
  end
198
-
199
193
  end
200
194
 
195
+
201
196
  # update by config
202
197
  begin
203
198
 
@@ -0,0 +1 @@
1
+ puts "sup"
@@ -1,5 +1,6 @@
1
1
  require_relative "../lib/procemon.rb"
2
2
 
3
+ puts require_relative_directory( "hello").inspect
3
4
 
4
5
 
5
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-25 00:00:00.000000000 Z
12
+ date: 2013-11-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'This is a collection of my Ruby Procs in the adventure of becoming
15
15
  the best! In short this provides extra tools in Application configs, argumens processing,daemonise,
@@ -27,7 +27,6 @@ files:
27
27
  - README.md
28
28
  - Rakefile
29
29
  - VERSION
30
- - dump/uuid.rb
31
30
  - files.rb
32
31
  - lib/procemon.rb
33
32
  - lib/procemon/function/application.rb
@@ -63,6 +62,7 @@ files:
63
62
  - procemon.gemspec
64
63
  - scripts/doc_gen.rb
65
64
  - scripts/test.txt
65
+ - test/hello/world/file.rb
66
66
  - test/lab.rb
67
67
  - test/test.rb
68
68
  homepage: https://github.com/adamluzsi/procemon
@@ -78,9 +78,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  - - ! '>='
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
- segments:
82
- - 0
83
- hash: -1780409337957780611
84
81
  required_rubygems_version: !ruby/object:Gem::Requirement
85
82
  none: false
86
83
  requirements:
@@ -94,5 +91,7 @@ signing_key:
94
91
  specification_version: 3
95
92
  summary: Gotta catch em all!
96
93
  test_files:
94
+ - test/hello/world/file.rb
97
95
  - test/lab.rb
98
96
  - test/test.rb
97
+ has_rdoc:
@@ -1,324 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Copyright(c) 2005 URABE, Shyouhei.
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this code, to deal in the code without restriction, including without
7
- # limitation the rights to use, copy, modify, merge, publish, distribute,
8
- # sublicense, and/or sell copies of the code, and to permit persons to whom the
9
- # code is furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be
12
- # included in all copies or substantial portions of the code.
13
- #
14
- # THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE CODE OR THE USE OR OTHER DEALINGS IN THE
20
- # CODE.
21
-
22
- [
23
- File.join("digest","md5"),
24
- File.join("digest","sha1"),
25
- "tmpdir"
26
- ].each do |f|
27
- require f
28
- end
29
-
30
- # Pure ruby UUID generator, which is compatible with RFC4122
31
- class UUID
32
- # UUID epoch is 15th Oct. 1582
33
- UNIXEpoch = 0x01B21DD213814000 # in 100-nanoseconds resolution
34
-
35
- private_class_method :new
36
-
37
- private
38
- def initialize str
39
- tmp = str.unpack "C*"
40
- @num = tmp.inject do |r, i|
41
- r * 256 | i
42
- end
43
- @num.freeze
44
- self.freeze
45
- end
46
-
47
- public
48
-
49
- def raw_bytes
50
- ret = String.new
51
- tmp = @num
52
- 16.times do |i|
53
- x, y = tmp.divmod 256
54
- ret << y
55
- tmp = x
56
- end
57
- ret.reverse!
58
- ret
59
- end
60
-
61
- class << self
62
- def mask ver, str # :nodoc:
63
- ver = ver & 15
64
- v = str[6].ord
65
- v &= 0b0000_1111
66
- v |= ver << 4
67
- str[6] = v.chr
68
- r = str[8].ord
69
- r &= 0b0011_1111
70
- r |= 0b1000_0000
71
- str[8] = r.chr
72
- str
73
- end
74
-
75
- def prand # :nodoc:
76
- rand 0x100000000
77
- end
78
-
79
- private :mask, :prand
80
-
81
- # UUID generation using SHA1. Recommended over create_md5.
82
- # Namespace object is another UUID, some of them are pre-defined below.
83
- def create_sha1 str, namespace
84
- sha1 = Digest::SHA1.new
85
- sha1.update namespace.raw_bytes
86
- sha1.update str
87
- sum = sha1.digest
88
- raw = mask 5, sum[0..15]
89
- new raw
90
- end
91
-
92
- # UUID generation using MD5 (for backward compat.)
93
- def create_md5 str, namespace
94
- md5 = Digest::MD5.new
95
- md5.update namespace.raw_bytes
96
- md5.update str
97
- sum = md5.digest
98
- raw = mask 3, sum[0..16]
99
- new raw
100
- end
101
-
102
- # UUID generation using random-number generator. From it's random
103
- # nature, there's no warranty that the created ID is really universaly
104
- # unique.
105
- def create_random
106
- rnd = [prand, prand, prand, prand].pack "N4"
107
- raw = mask 4, rnd
108
- new raw
109
- end
110
-
111
- def read_state fp # :nodoc:
112
- fp.rewind
113
- Marshal.load fp.read
114
- end
115
-
116
- def write_state fp, c, m # :nodoc:
117
- fp.rewind
118
- str = Marshal.dump [c, m]
119
- fp.write str
120
- end
121
-
122
- private :read_state, :write_state
123
- STATE_FILE = 'ruby-uuid'
124
-
125
- # create the "version 1" UUID with current system clock, current UTC
126
- # timestamp, and the IEEE 802 address (so-called MAC address).
127
- #
128
- # Speed notice: it's slow. It writes some data into hard drive on every
129
- # invokation. If you want to speed this up, try remounting tmpdir with a
130
- # memory based filesystem (such as tmpfs). STILL slow? then no way but
131
- # rewrite it with c :)
132
- def create *args
133
-
134
- if args[0].class.to_s == "Hash"
135
- args= Hash[*args]
136
- clock = args[:clock] || nil
137
- time = args[:time] || Time.now
138
- mac_addr= args[:mac] || nil
139
- else
140
- clock = args[0] || nil
141
- time = args[1] || Time.now
142
- mac_addr= args[2] || nil
143
- end
144
-
145
- c = t = m = nil
146
- Dir.chdir Dir.tmpdir do
147
- unless FileTest.exist? STATE_FILE then
148
- # Generate a pseudo MAC address because we have no pure-ruby way
149
- # to know the MAC address of the NIC this system uses. Note
150
- # that cheating with pseudo arresses here is completely legal:
151
- # see Section 4.5 of RFC4122 for details.
152
- sha1 = Digest::SHA1.new
153
- 256.times do
154
- r = [prand].pack "N"
155
- sha1.update r
156
- end
157
- ary = sha1.digest.bytes.to_a
158
- node = ary.last 6
159
- node[0] |= 0x01 # multicast bit
160
- node = node.pack "C*"
161
- k = rand 0x40000
162
- open STATE_FILE, 'w' do |fp|
163
- fp.flock IO::LOCK_EX
164
- write_state fp, k, node
165
- fp.chmod 0o777 # must be world writable
166
- end
167
- end
168
- open STATE_FILE, 'r+' do |fp|
169
- fp.flock IO::LOCK_EX
170
- c, m = read_state fp
171
- c += 1 # important; increment here
172
- write_state fp, c, m
173
- end
174
- end
175
- c = clock & 0b11_1111_1111_1111 if clock
176
- m = mac_addr if mac_addr
177
- time = Time.at time if time.is_a? Float
178
- case time
179
- when Time
180
- t = time.to_i * 10_000_000 + time.tv_usec * 10 + UNIXEpoch
181
- when Integer
182
- t = time + UNIXEpoch
183
- else
184
- raise TypeError, "cannot convert ``#{time}'' into Time."
185
- end
186
-
187
- tl = t & 0xFFFF_FFFF
188
- tm = t >> 32
189
- tm = tm & 0xFFFF
190
- th = t >> 48
191
- th = th & 0b0000_1111_1111_1111
192
- th = th | 0b0001_0000_0000_0000
193
- cl = c & 0b0000_0000_1111_1111
194
- ch = c & 0b0011_1111_0000_0000
195
- ch = ch >> 8
196
- ch = ch | 0b1000_0000
197
- pack tl, tm, th, ch, cl, m
198
- end
199
-
200
- # A simple GUID parser: just ignores unknown characters and convert
201
- # hexadecimal dump into 16-octet object.
202
- def parse obj
203
- str = obj.to_s.sub %r/\Aurn:uuid:/, ''
204
- str.gsub! %r/[^0-9A-Fa-f]/, ''
205
- raw = [str[0..31]].pack 'H*'
206
- new raw
207
- end
208
-
209
- # The 'primitive constructor' of this class
210
- # Note UUID.pack(uuid.unpack) == uuid
211
- def pack tl, tm, th, ch, cl, n
212
- raw = [tl, tm, th, ch, cl, n].pack "NnnCCa6"
213
- new raw
214
- end
215
- end
216
-
217
- # The 'primitive deconstructor', or the dual to pack.
218
- # Note UUID.pack(uuid.unpack) == uuid
219
- def unpack
220
- raw_bytes.unpack "NnnCCa6"
221
- end
222
-
223
- # The timestamp of this UUID.
224
- # Throws RageError if that time exceeds UNIX time range
225
- def time
226
- a = unpack
227
- tl = a[0]
228
- tm = a[1]
229
- th = a[2] & 0x0FFF
230
- t = tl
231
- t += tm << 32
232
- t += th << 48
233
- t -= UNIXEpoch
234
- tv_sec = t / 10_000_000
235
- t -= tv_sec * 10_000_000
236
- tv_usec = t / 10
237
- Time.at tv_sec, tv_usec
238
- end
239
-
240
- # The version of this UUID
241
- def version
242
- v = unpack[2] & 0b1111_0000_0000_0000
243
- v >> 12
244
- end
245
-
246
- # The clock sequence of this UUID
247
- def clock
248
- a = unpack
249
- ch = a[3] & 0b0001_1111
250
- cl = a[4]
251
- c = cl
252
- c += ch << 8
253
- c
254
- end
255
-
256
- # The IEEE 802 address in a hexadecimal format
257
- def node
258
- m = unpack[5].unpack 'C*'
259
- '%02x%02x%02x%02x%02x%02x' % m
260
- end
261
- alias mac_address node
262
- alias ieee802 node
263
-
264
- # Generate the string representation (a.k.a GUID) of this UUID
265
- def to_s
266
- a = unpack
267
- a[-1] = mac_address
268
- "%08x-%04x-%04x-%02x%02x-%s" % a
269
- end
270
- alias guid to_s
271
-
272
- # Convert into a RFC4122-comforming URN representation
273
- def to_uri
274
- "urn:uuid:" + self.to_s
275
- end
276
- alias urn to_uri
277
- alias inspect to_uri
278
-
279
- # Convert into 128-bit unsigned integer
280
- # Typically a Bignum instance, but can be a Fixnum.
281
- def to_int
282
- @num
283
- end
284
- alias to_i to_int
285
-
286
- # Two UUIDs are said to be equal if and only if their (byte-order
287
- # canonicalized) integer representations are equivallent. Refer RFC4122 for
288
- # details.
289
- def == other
290
- to_i == other.to_i
291
- end
292
- alias eql? ==
293
-
294
- # Two identical UUIDs should have same hash
295
- def hash
296
- to_i
297
- end
298
-
299
- include Comparable
300
- # UUIDs are comparable (don't know what benefits are there, though).
301
- def <=> other
302
- to_s <=> other.to_s
303
- end
304
-
305
- # Pre-defined UUID Namespaces described in RFC4122 Appendix C.
306
- NameSpace_DNS = parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
307
- NameSpace_URL = parse "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
308
- NameSpace_OID = parse "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
309
- NameSpace_X500 = parse "6ba7b814-9dad-11d1-80b4-00c04fd430c8"
310
-
311
- # The Nil UUID in RFC4122 Section 4.1.7
312
- Nil = parse "00000000-0000-0000-0000-000000000000"
313
- end
314
-
315
- # Local Variables:
316
- # mode: ruby
317
- # coding: utf-8
318
- # indent-tabs-mode: t
319
- # tab-width: 3
320
- # ruby-indent-level: 3
321
- # fill-column: 79
322
- # default-justification: full
323
- # End:
324
- # vi: ts=3 sw=3