procemon 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +361 -0
- data/VERSION +1 -1
- data/files.rb +24 -0
- data/lib/procemon/mpatch/array.rb +0 -1
- data/lib/procemon/mpatch/integer.rb +12 -0
- data/lib/procemon/mpatch/object.rb +1 -2
- data/lib/procemon/mpatch/random.rb +1 -1
- data/procemon.gemspec +3 -24
- data/scripts/doc_gen.rb +55 -0
- data/scripts/test.txt +442 -0
- data/test/test.rb +20 -9
- metadata +11 -8
data/README.md
CHANGED
@@ -9,3 +9,364 @@ This is including Tons of monkey_patch for new features to classes,
|
|
9
9
|
meta-programing tricks, terminal argument controls, daemonise trick,
|
10
10
|
tmp folder helpers, Application centralized datas, folder structure logic ,
|
11
11
|
meta data control, dynamic lib read etc
|
12
|
+
|
13
|
+
|
14
|
+
short lazy doc
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
in Str2duck
|
19
|
+
|
20
|
+
# convert string object to something what is it looks to be as duck type mean to do
|
21
|
+
# useful for RESTfull aps when data sent as string
|
22
|
+
duck
|
23
|
+
|
24
|
+
|
25
|
+
in Tmp_dir
|
26
|
+
|
27
|
+
# init a tmpdir in the OS tmp folder with the application name
|
28
|
+
# (by default this is the root folder name)
|
29
|
+
tmpdir_init
|
30
|
+
|
31
|
+
|
32
|
+
in Name
|
33
|
+
|
34
|
+
# what it looks to be
|
35
|
+
set_app_name_by_root_folder
|
36
|
+
|
37
|
+
|
38
|
+
in Argv
|
39
|
+
|
40
|
+
# what it looks to be
|
41
|
+
process_parameters
|
42
|
+
|
43
|
+
|
44
|
+
in Daemon
|
45
|
+
|
46
|
+
# Checks to see if the current process is the child process and if not
|
47
|
+
# will update the pid file with the child pid.
|
48
|
+
self.start pid, pidfile, outfile, errfile
|
49
|
+
|
50
|
+
# Attempts to write the pid of the forked process to the pid file.
|
51
|
+
self.write pid, pidfile
|
52
|
+
|
53
|
+
# Try and read the existing pid from the pid file and signal the
|
54
|
+
# process. Returns true for a non blocking status.
|
55
|
+
self.kill(pidfile)
|
56
|
+
|
57
|
+
# Send stdout and stderr to log files for the child process
|
58
|
+
self.redirect outfile, errfile
|
59
|
+
self.daemonize
|
60
|
+
self.kill_with_pid
|
61
|
+
self.terminate
|
62
|
+
self.kill_by_name(*args)
|
63
|
+
self.stop
|
64
|
+
self.init
|
65
|
+
|
66
|
+
|
67
|
+
in Inject_methods
|
68
|
+
|
69
|
+
# this will inject a code block to a target instance method
|
70
|
+
# by default the before or after sym is not required
|
71
|
+
# default => before
|
72
|
+
#
|
73
|
+
# Test.inject_singleton_method :hello do |*args|
|
74
|
+
# puts "singleton extra, so#{args[0]}"
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
inject_singleton_method(method,options=:before,&block)
|
78
|
+
|
79
|
+
#Singleton.methods[self.object_id]= self.method(method)
|
80
|
+
# this will inject a code block to a target singleton method
|
81
|
+
# by default the before or after sym is not required
|
82
|
+
# default => before
|
83
|
+
#
|
84
|
+
# Test.inject_instance_method :hello, :before do |*args|
|
85
|
+
# puts "singleton on a instance method and "+args[0]
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
inject_instance_method(method,options=:before,&block)
|
89
|
+
|
90
|
+
|
91
|
+
in Require
|
92
|
+
|
93
|
+
# load meta-s
|
94
|
+
meta_load(app_folder= Dir.pwd)
|
95
|
+
|
96
|
+
# find elements
|
97
|
+
get_meta_config(app_folder= Dir.pwd)
|
98
|
+
|
99
|
+
# defaults
|
100
|
+
# find elements
|
101
|
+
# defaults
|
102
|
+
# processing
|
103
|
+
# return data
|
104
|
+
# mount libs
|
105
|
+
mount_libs(app_folder= Dir.pwd)
|
106
|
+
|
107
|
+
# load lib files
|
108
|
+
# Offline repo activate
|
109
|
+
mount_modules(app_folder= Dir.pwd)
|
110
|
+
|
111
|
+
#Return File_name => File_path
|
112
|
+
get_files(folder)
|
113
|
+
|
114
|
+
# Validation
|
115
|
+
# Check that does the folder is absolute or not
|
116
|
+
# Get Files list
|
117
|
+
# Return file_name:folder
|
118
|
+
# require by absolute path directory's files
|
119
|
+
require_directory(folder)
|
120
|
+
|
121
|
+
# require sender relative directory's files
|
122
|
+
require_relative_directory(folder)
|
123
|
+
|
124
|
+
# generate config from yaml (default is app_root/config folder)
|
125
|
+
generate_config(target_config_hash= Application.config,app_folder= Dir.pwd)
|
126
|
+
|
127
|
+
# try load all the ruby files marked with "generate" in they name from app_root/docs
|
128
|
+
generate_documentation(boolean= false,keyword= "generate",app_folder= Dir.pwd)
|
129
|
+
|
130
|
+
|
131
|
+
in Port
|
132
|
+
|
133
|
+
get_port(mint_port,max_port,host="0.0.0.0")
|
134
|
+
port_open?(port,host="0.0.0.0")
|
135
|
+
|
136
|
+
|
137
|
+
in Eval
|
138
|
+
|
139
|
+
# NOT working yet, need to rework the exclude method
|
140
|
+
# safe_eval(string [, binding [, filename [,lineno]]] *allowed_class/module_names ) -> obj
|
141
|
+
#
|
142
|
+
# Evaluates the Ruby expression(s) in <em>string</em>. If
|
143
|
+
# <em>binding</em> is given, which must be a <code>Binding</code>
|
144
|
+
# object, the evaluation is performed in its context. If the
|
145
|
+
# optional <em>filename</em> and <em>lineno</em> parameters are
|
146
|
+
# present, they will be used when reporting syntax errors.
|
147
|
+
#
|
148
|
+
# def get_binding(str)
|
149
|
+
# return binding
|
150
|
+
# end
|
151
|
+
# str = "hello"
|
152
|
+
# safe_eval "str + ' Fred'" ,Kernel#=> "hello Fred"
|
153
|
+
# safe_eval "str + ' Fred'", get_binding("bye") ,Kernel#=> "bye Fred"
|
154
|
+
safe_eval(*args)
|
155
|
+
|
156
|
+
|
157
|
+
in Process
|
158
|
+
|
159
|
+
self.daemonize
|
160
|
+
self.stop
|
161
|
+
|
162
|
+
|
163
|
+
in String
|
164
|
+
|
165
|
+
# Find string in othere string
|
166
|
+
positions(oth_string)
|
167
|
+
|
168
|
+
# return value
|
169
|
+
# Standard in rails. See official documentation
|
170
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
171
|
+
camelize(first_letter = :upper)
|
172
|
+
|
173
|
+
# Standard in rails. See official documentation
|
174
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
175
|
+
dasherize
|
176
|
+
|
177
|
+
# Standard in rails. See official documentation
|
178
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
179
|
+
demodulize
|
180
|
+
|
181
|
+
# Standard in rails. See official documentation
|
182
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
183
|
+
underscore
|
184
|
+
|
185
|
+
# Check that instance of String is start with an upper case or not
|
186
|
+
capitalized?
|
187
|
+
|
188
|
+
|
189
|
+
in Yml
|
190
|
+
|
191
|
+
self.save_file(file_path,config_hash)
|
192
|
+
|
193
|
+
self.load_file(file_path)
|
194
|
+
|
195
|
+
|
196
|
+
in Object
|
197
|
+
|
198
|
+
# The hidden singleton lurks behind everyone
|
199
|
+
metaclass; class << self; self; end; end
|
200
|
+
|
201
|
+
# extend the metaclass with an instance eval
|
202
|
+
meta_eval &blk; metaclass.instance_eval &blk; end
|
203
|
+
|
204
|
+
# Adds methods to a metaclass
|
205
|
+
meta_name, &blk
|
206
|
+
|
207
|
+
# Defines an instance method within a class
|
208
|
+
class_name, &blk
|
209
|
+
|
210
|
+
# constantize object
|
211
|
+
constantize
|
212
|
+
|
213
|
+
# find and replace object in object
|
214
|
+
find_and_replace(input,*params)
|
215
|
+
|
216
|
+
# it was made only for fun to make same each to array and hash and everything
|
217
|
+
each_universal(&block)
|
218
|
+
|
219
|
+
# map an object => experiment
|
220
|
+
map_object(symbol_key="$type")
|
221
|
+
|
222
|
+
# is class?
|
223
|
+
class?
|
224
|
+
|
225
|
+
# convert class instance instance variables into a hash object
|
226
|
+
convert_to_hash
|
227
|
+
|
228
|
+
# this will check that the class is
|
229
|
+
# defined or not in the runtime memory
|
230
|
+
class_exists?
|
231
|
+
|
232
|
+
# This will convert a symbol or string and format to be a valid
|
233
|
+
# constant name and create from it a class with instance attribute accessors
|
234
|
+
# Best use is when you get raw data in string from external source
|
235
|
+
# and you want make them class objects
|
236
|
+
#
|
237
|
+
# :hello_world.to_class(:test)
|
238
|
+
# HelloWorld.to_class(:sup)
|
239
|
+
# hw_var = HelloWorld.new
|
240
|
+
# hw_var.sup = "Fine thanks!"
|
241
|
+
# hw_var.test = 5
|
242
|
+
#
|
243
|
+
# puts hw_var.test
|
244
|
+
#
|
245
|
+
#> produce 5 :Integer
|
246
|
+
#
|
247
|
+
# you can also use this formats
|
248
|
+
# :HelloWorld , "hello.world",
|
249
|
+
# "hello/world", "Hello::World",
|
250
|
+
# "hello:world"...
|
251
|
+
to_class(*attributes)
|
252
|
+
or
|
253
|
+
create_attributes(*attributes)
|
254
|
+
|
255
|
+
in File
|
256
|
+
|
257
|
+
self.create(route_name ,filemod="w",string_data=String.new)
|
258
|
+
|
259
|
+
|
260
|
+
in Array
|
261
|
+
|
262
|
+
# remove arguments or array of
|
263
|
+
# parameters from the main array
|
264
|
+
trim(*args)
|
265
|
+
|
266
|
+
# return index of the target element
|
267
|
+
index_of(target_element)
|
268
|
+
|
269
|
+
# remove n. element from the end
|
270
|
+
# and return a new object
|
271
|
+
pinch n=1
|
272
|
+
|
273
|
+
# remove n. element from the end
|
274
|
+
# and return the original object
|
275
|
+
pinch! n=1
|
276
|
+
|
277
|
+
# return boolean by other array
|
278
|
+
# all element included or
|
279
|
+
# not in the target array
|
280
|
+
contain?(oth_array)#anothere array
|
281
|
+
|
282
|
+
# do safe transpose
|
283
|
+
safe_transpose
|
284
|
+
|
285
|
+
|
286
|
+
in Class
|
287
|
+
|
288
|
+
# get singleton methods to target class without super class methods
|
289
|
+
class_methods
|
290
|
+
|
291
|
+
# bind a singleton method to a class object
|
292
|
+
create_class_method(method,&block)
|
293
|
+
|
294
|
+
# create an instance method
|
295
|
+
create_instance_method(method,&block)
|
296
|
+
|
297
|
+
# Iterates over all subclasses (direct and indirect)
|
298
|
+
each_subclass
|
299
|
+
|
300
|
+
# Returns an Array of subclasses (direct and indirect)
|
301
|
+
subclasses
|
302
|
+
|
303
|
+
# Returns an Array of direct subclasses
|
304
|
+
direct_subclasses
|
305
|
+
|
306
|
+
# create singleton attribute
|
307
|
+
class_attr_accessor(name)
|
308
|
+
|
309
|
+
# GET
|
310
|
+
# SET
|
311
|
+
# create class instance attribute
|
312
|
+
instance_attr_accessor(name)
|
313
|
+
|
314
|
+
|
315
|
+
in Integer
|
316
|
+
|
317
|
+
# because for i in integer/fixnum not working,
|
318
|
+
# here is a little patch
|
319
|
+
each &block
|
320
|
+
|
321
|
+
|
322
|
+
in Random
|
323
|
+
|
324
|
+
string(length= 7,amount=1)
|
325
|
+
|
326
|
+
integer(length= 3)
|
327
|
+
|
328
|
+
boolean
|
329
|
+
|
330
|
+
time from = Time.at(1114924812), to = Time.now
|
331
|
+
|
332
|
+
date from = Time.at(1114924812), to = Time.now
|
333
|
+
|
334
|
+
datetime from = Time.at(1114924812), to = Time.now
|
335
|
+
|
336
|
+
|
337
|
+
in Hash
|
338
|
+
|
339
|
+
# remove elements by keys,
|
340
|
+
# array of keys,
|
341
|
+
# hashTags,
|
342
|
+
# strings
|
343
|
+
trim(*args)
|
344
|
+
|
345
|
+
#pass single or array of keys, which will be removed, returning the remaining hash
|
346
|
+
remove!(*keys)
|
347
|
+
|
348
|
+
#non-destructive version
|
349
|
+
remove(*keys)
|
350
|
+
|
351
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
352
|
+
#
|
353
|
+
# h1 = {:x => {:y => [4,5,6]}, :z => [7,8,9]}
|
354
|
+
# h2 = {:x => {:y => [7,8,9]}, :z => "xyz"}
|
355
|
+
#
|
356
|
+
# h1.deep_merge(h2#=> { :x => {:y => [7, 8, 9]}, :z => "xyz" }
|
357
|
+
# h2.deep_merge(h1#=> { :x => {:y => [4, 5, 6]}, :z => [7, 8, 9] }
|
358
|
+
deep_merge(other_hash)
|
359
|
+
|
360
|
+
# Same as +deep_merge+, but modifies +self+.
|
361
|
+
deep_merge!(other_hash)
|
362
|
+
|
363
|
+
# return bool that does the sub hash all element include the hash who call this or not
|
364
|
+
deep_include?(sub_hash)
|
365
|
+
|
366
|
+
|
367
|
+
in Kernel
|
368
|
+
|
369
|
+
# eats puts like formated printf method
|
370
|
+
# just use an integer what will be the distance
|
371
|
+
# between elements and the elements next to it
|
372
|
+
putsf(integer,*args)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/files.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
### Get Files from dir
|
2
|
+
begin
|
3
|
+
|
4
|
+
files_to_be_loaded = %w[version.rb]
|
5
|
+
|
6
|
+
SpecFiles= Array.new
|
7
|
+
|
8
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),"**","*"))].sort.uniq.each do |one_file_name|
|
9
|
+
one_file_name = File.expand_path one_file_name
|
10
|
+
file_name = one_file_name[(File.expand_path(File.dirname(__FILE__)).to_s.length+1)..(one_file_name.length-1)]
|
11
|
+
|
12
|
+
if !one_file_name.include?("pkg")
|
13
|
+
if !File.directory? file_name
|
14
|
+
SpecFiles.push file_name
|
15
|
+
STDOUT.puts file_name if $DEBUG
|
16
|
+
if files_to_be_loaded.include? one_file_name.split(File::SEPARATOR).last
|
17
|
+
load one_file_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -193,7 +193,7 @@ class Object
|
|
193
193
|
# :HelloWorld , "hello.world",
|
194
194
|
# "hello/world", "Hello::World",
|
195
195
|
# "hello:world"...
|
196
|
-
def to_class(*attributes)
|
196
|
+
def to_class(*attributes)
|
197
197
|
|
198
198
|
unless self.class == Symbol || self.class == String || self.class == Class
|
199
199
|
raise ArgumentError, "object must be symbol or string to make able build class to it"
|
@@ -206,7 +206,6 @@ class Object
|
|
206
206
|
class_name= class_name[0].upcase+class_name[1..class_name.length]
|
207
207
|
%w[ _ . : / ].each do |one_sym|
|
208
208
|
|
209
|
-
#sym_length= one_sym.length
|
210
209
|
loop do
|
211
210
|
index_nmb= class_name.index(one_sym)
|
212
211
|
break if index_nmb.nil?
|
@@ -7,7 +7,7 @@ class RND
|
|
7
7
|
a_string = Random.rand(length)
|
8
8
|
a_string == 0 ? a_string += 1 : a_string
|
9
9
|
mrg_prt = (0...a_string).map{ ('a'..'z').to_a[rand(26)] }.join
|
10
|
-
first_string ? mrg += mrg_prt : mrg+= " #{mrg_prt}"
|
10
|
+
first_string ? mrg += mrg_prt : mrg+= " " + "#{mrg_prt}"
|
11
11
|
first_string = false
|
12
12
|
end
|
13
13
|
return mrg
|
data/procemon.gemspec
CHANGED
@@ -1,27 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
begin
|
5
|
-
|
6
|
-
files_to_be_loaded = %w[version.rb]
|
7
|
-
spec_files = Array.new
|
8
|
-
Dir[File.expand_path(File.join(File.dirname(__FILE__),"**","*"))].sort.uniq.each do |one_file_name|
|
9
|
-
one_file_name = File.expand_path one_file_name
|
10
|
-
file_name = one_file_name[(File.expand_path(File.dirname(__FILE__)).to_s.length+1)..(one_file_name.length-1)]
|
11
|
-
|
12
|
-
if !one_file_name.include?("pkg")
|
13
|
-
if !File.directory? file_name
|
14
|
-
spec_files.push file_name
|
15
|
-
STDOUT.puts file_name if $DEBUG
|
16
|
-
if files_to_be_loaded.include? one_file_name.split(File::SEPARATOR).last
|
17
|
-
load one_file_name
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__),"files.rb"))
|
25
4
|
|
26
5
|
### Specification for the new Gem
|
27
6
|
Gem::Specification.new do |spec|
|
@@ -30,12 +9,12 @@ Gem::Specification.new do |spec|
|
|
30
9
|
spec.version = File.open(File.join(File.dirname(__FILE__),"VERSION")).read.split("\n")[0].chomp.gsub(' ','')
|
31
10
|
spec.authors = ["Adam Luzsi"]
|
32
11
|
spec.email = ["adamluzsi@gmail.com"]
|
33
|
-
spec.description = %q{This is a collection of my Ruby Procs in the adventure of becoming the best!
|
12
|
+
spec.description = %q{This is a collection of my Ruby Procs in the adventure of becoming the best! In short this provides extra tools in Application configs, argumens processing,daemonise, eval,port check, require relative files, or directories, string to duck parsing, system tmp_dir using, meta-programing, and a lot of monkey patch for extra functionality }
|
34
13
|
spec.summary = %q{Gotta catch em all!}
|
35
14
|
spec.homepage = "https://github.com/adamluzsi/procemon"
|
36
15
|
spec.license = "MIT"
|
37
16
|
|
38
|
-
spec.files =
|
17
|
+
spec.files = SpecFiles
|
39
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
40
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
41
20
|
spec.require_paths = ["lib"]
|
data/scripts/doc_gen.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative "../files.rb"
|
2
|
+
|
3
|
+
class Array
|
4
|
+
def sum ary
|
5
|
+
ary.each do |one_element|
|
6
|
+
self.push one_element
|
7
|
+
end
|
8
|
+
return self
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
DOC_DATA = Hash.new
|
14
|
+
|
15
|
+
Dir.glob(File.join(File.dirname(__FILE__),"..","lib","procemon","**","*.{rb,ru}")).uniq.each do |one_file_path|
|
16
|
+
|
17
|
+
comment = Array.new
|
18
|
+
comment.push String.new
|
19
|
+
|
20
|
+
File.open(File.expand_path(one_file_path)).read.split("\n").each do |one_line_per_file|
|
21
|
+
|
22
|
+
if one_line_per_file =~ /\W* #/
|
23
|
+
comment.push one_line_per_file.gsub(/\W*#/,"#")
|
24
|
+
end
|
25
|
+
|
26
|
+
if one_line_per_file =~ /\W*def\W/
|
27
|
+
|
28
|
+
if DOC_DATA[one_file_path.split(File::Separator).last.split('.')[0]].nil?
|
29
|
+
DOC_DATA[one_file_path.split(File::Separator).last.split('.')[0]]= Array.new
|
30
|
+
end
|
31
|
+
|
32
|
+
DOC_DATA[one_file_path.split(File::Separator).last.split('.')[0]].sum comment
|
33
|
+
|
34
|
+
comment.clear
|
35
|
+
comment.push String.new
|
36
|
+
|
37
|
+
|
38
|
+
DOC_DATA[one_file_path.split(File::Separator).last.split('.')[0]].push one_line_per_file.gsub(/\W*def\W/,"")
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
END_DATA= Array.new
|
48
|
+
DOC_DATA.each do |key,value|
|
49
|
+
END_DATA.push "\n\nin #{key.to_s.capitalize}"
|
50
|
+
value.each do |one_element|
|
51
|
+
END_DATA.push one_element
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
File.new(File.expand_path(File.join(File.dirname(__FILE__),"test.txt")),"w").write END_DATA.join("\n")
|
data/scripts/test.txt
ADDED
@@ -0,0 +1,442 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
in Systemu
|
4
|
+
|
5
|
+
systemu(*a, &b) SystemUniversal.new(*a, &b).systemu end
|
6
|
+
|
7
|
+
SystemUniversal.version() SystemUniversal::VERSION end
|
8
|
+
|
9
|
+
version() SystemUniversal::VERSION end
|
10
|
+
|
11
|
+
quote(*words)
|
12
|
+
|
13
|
+
initialize argv, opts = {}, &block
|
14
|
+
|
15
|
+
systemu
|
16
|
+
|
17
|
+
IO.popen#{ quote(@ruby#{ quote(c['program']) }", 'r+' do |pipe|
|
18
|
+
quote *args, &block
|
19
|
+
|
20
|
+
new_thread cid, block
|
21
|
+
|
22
|
+
child_setup tmp
|
23
|
+
|
24
|
+
quietly
|
25
|
+
|
26
|
+
child_program config
|
27
|
+
|
28
|
+
# encoding: utf-8
|
29
|
+
PIPE.flush# the process is ready yo!
|
30
|
+
relay srcdst
|
31
|
+
|
32
|
+
tmpdir d = Dir.tmpdir, max = 42, &b
|
33
|
+
|
34
|
+
getopts opts = {}
|
35
|
+
|
36
|
+
systemu
|
37
|
+
|
38
|
+
initialize(stream)
|
39
|
+
|
40
|
+
join
|
41
|
+
|
42
|
+
|
43
|
+
in Str2duck
|
44
|
+
|
45
|
+
duck
|
46
|
+
|
47
|
+
|
48
|
+
in Tmp_dir
|
49
|
+
|
50
|
+
tmpdir_init
|
51
|
+
|
52
|
+
|
53
|
+
in Documentation
|
54
|
+
|
55
|
+
find_doc_part(oth_str)
|
56
|
+
|
57
|
+
|
58
|
+
in Name
|
59
|
+
|
60
|
+
set_app_name_by_root_folder
|
61
|
+
|
62
|
+
|
63
|
+
in Argv
|
64
|
+
|
65
|
+
process_parameters
|
66
|
+
|
67
|
+
|
68
|
+
in Daemon
|
69
|
+
|
70
|
+
# Checks to see if the current process is the child process and if not
|
71
|
+
# will update the pid file with the child pid.
|
72
|
+
self.start pid, pidfile, outfile, errfile
|
73
|
+
|
74
|
+
write pid, pidfile#if kill pidfile
|
75
|
+
# Attempts to write the pid of the forked process to the pid file.
|
76
|
+
self.write pid, pidfile
|
77
|
+
|
78
|
+
$stderr.puts "While writing the PID to file, unexpected#{e.class#{e}"
|
79
|
+
# Try and read the existing pid from the pid file and signal the
|
80
|
+
# process. Returns true for a non blocking status.
|
81
|
+
self.kill(pidfile)
|
82
|
+
|
83
|
+
$stdout.puts "The process#{opid} did not exist: Errno::ESRCH" if $DEBUG
|
84
|
+
$stderr.puts "Lack of privileges to manage the process#{opid}: Errno::EPERM" if $DEBUG
|
85
|
+
$stderr.puts "While signaling the PID, unexpected#{e.class#{e}" if $DEBUG
|
86
|
+
# Send stdout and stderr to log files for the child process
|
87
|
+
self.redirect outfile, errfile
|
88
|
+
|
89
|
+
self.daemonize
|
90
|
+
|
91
|
+
self.kill_with_pid
|
92
|
+
|
93
|
+
puts "terminated process at#{row.chomp}" if $DEBUG
|
94
|
+
puts "At process#{row.chomp#{ex}" if $DEBUG
|
95
|
+
system "ps -ef | grep#{$0}"
|
96
|
+
#system "netstat --listen"
|
97
|
+
#puts "\nLepton is around 10300-10399"
|
98
|
+
puts "Exception has occured#{ex}"
|
99
|
+
self.terminate
|
100
|
+
|
101
|
+
self.kill_by_name(*args)
|
102
|
+
|
103
|
+
# name switch
|
104
|
+
while `ps aux | grep#{target_name}`.split(' ')[1] != "" ||(Time.now - start_time) < 6
|
105
|
+
Process.kill "TERM",`ps aux | grep#{target_name}`.split(' ')[1].to_i
|
106
|
+
$stdout.puts "The process#{target_name} did not exist: Errno::ESRCH" if debug_mod
|
107
|
+
$stderr.puts "Lack of privileges to manage the process#{target_name}: Errno::EPERM" if debug_mod
|
108
|
+
$stderr.puts "While signaling the PID, unexpected#{e.class#{e}" if debug_mod
|
109
|
+
# name switch back
|
110
|
+
self.stop
|
111
|
+
|
112
|
+
# kill methods
|
113
|
+
self.init
|
114
|
+
|
115
|
+
|
116
|
+
in Inject_methods
|
117
|
+
|
118
|
+
#TODO refacotr to binding logic because this is useless now to me in hardcore use
|
119
|
+
# this will inject a code block to a target instance method
|
120
|
+
# by default the before or after sym is not required
|
121
|
+
# default => before
|
122
|
+
#
|
123
|
+
# Test.inject_singleton_method :hello do |*args|
|
124
|
+
# puts "singleton extra, so#{args[0]}"
|
125
|
+
# end
|
126
|
+
#
|
127
|
+
inject_singleton_method(method,options=:before,&block)
|
128
|
+
|
129
|
+
#Singleton.methods[self.object_id]= self.method(method)
|
130
|
+
# this will inject a code block to a target singleton method
|
131
|
+
# by default the before or after sym is not required
|
132
|
+
# default => before
|
133
|
+
#
|
134
|
+
# Test.inject_instance_method :hello, :before do |*args|
|
135
|
+
# puts "singleton on a instance method and "+args[0]
|
136
|
+
# end
|
137
|
+
#
|
138
|
+
inject_instance_method(method,options=:before,&block)
|
139
|
+
|
140
|
+
|
141
|
+
in Require
|
142
|
+
|
143
|
+
# load meta-s
|
144
|
+
meta_load(app_folder= Dir.pwd)
|
145
|
+
|
146
|
+
# find elements
|
147
|
+
get_meta_config(app_folder= Dir.pwd)
|
148
|
+
|
149
|
+
# defaults
|
150
|
+
# find elements
|
151
|
+
# defaults
|
152
|
+
# processing
|
153
|
+
# return data
|
154
|
+
# mount libs
|
155
|
+
mount_libs(app_folder= Dir.pwd)
|
156
|
+
|
157
|
+
# load lib files
|
158
|
+
# Offline repo activate
|
159
|
+
mount_modules(app_folder= Dir.pwd)
|
160
|
+
|
161
|
+
#Return File_name:File_path
|
162
|
+
get_files(folder)
|
163
|
+
|
164
|
+
# Pre def. variables
|
165
|
+
# Pre variables
|
166
|
+
|
167
|
+
# Validation
|
168
|
+
# Check that does the folder is absolute or not
|
169
|
+
# Get Files list
|
170
|
+
# Return file_name:folder
|
171
|
+
# require by absolute path directory's files
|
172
|
+
require_directory(folder)
|
173
|
+
|
174
|
+
puts "file will be loaded#{file_name} from\n\t#{file_path}" if $DEBUG
|
175
|
+
# require sender relative directory's files
|
176
|
+
require_relative_directory(folder)
|
177
|
+
|
178
|
+
# pre format
|
179
|
+
# find elements
|
180
|
+
# after format
|
181
|
+
# generate config from yaml
|
182
|
+
generate_config(target_config_hash= Application.config,app_folder= Dir.pwd)
|
183
|
+
|
184
|
+
# defaults
|
185
|
+
# find elements
|
186
|
+
# defaults
|
187
|
+
# processing
|
188
|
+
# update by config
|
189
|
+
# get config files
|
190
|
+
# params config load
|
191
|
+
# load to last lvl environment
|
192
|
+
generate_documentation(boolean= false,keyword= "generate",app_folder= Dir.pwd)
|
193
|
+
|
194
|
+
|
195
|
+
in Port
|
196
|
+
|
197
|
+
get_port(mint_port,max_port,host="0.0.0.0")
|
198
|
+
|
199
|
+
port_open?(port,host="0.0.0.0")
|
200
|
+
|
201
|
+
|
202
|
+
in Eval
|
203
|
+
|
204
|
+
# safe_eval(string [, binding [, filename [,lineno]]] *allowed_class/module_names ) -> obj
|
205
|
+
#
|
206
|
+
# Evaluates the Ruby expression(s) in <em>string</em>. If
|
207
|
+
# <em>binding</em> is given, which must be a <code>Binding</code>
|
208
|
+
# object, the evaluation is performed in its context. If the
|
209
|
+
# optional <em>filename</em> and <em>lineno</em> parameters are
|
210
|
+
# present, they will be used when reporting syntax errors.
|
211
|
+
#
|
212
|
+
# def get_binding(str)
|
213
|
+
get_binding(str)
|
214
|
+
|
215
|
+
# return binding
|
216
|
+
# end
|
217
|
+
# str = "hello"
|
218
|
+
# safe_eval "str + ' Fred'" ,Kernel#=> "hello Fred"
|
219
|
+
# safe_eval "str + ' Fred'", get_binding("bye") ,Kernel#=> "bye Fred"
|
220
|
+
safe_eval(*args)
|
221
|
+
|
222
|
+
|
223
|
+
in Process
|
224
|
+
|
225
|
+
self.daemonize
|
226
|
+
|
227
|
+
self.stop
|
228
|
+
|
229
|
+
|
230
|
+
in String
|
231
|
+
|
232
|
+
# Find string in othere string
|
233
|
+
positions(oth_string)
|
234
|
+
|
235
|
+
# return value
|
236
|
+
# Standard in rails. See official documentation
|
237
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
238
|
+
camelize(first_letter = :upper)
|
239
|
+
|
240
|
+
# Standard in rails. See official documentation
|
241
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
242
|
+
dasherize
|
243
|
+
|
244
|
+
# Standard in rails. See official documentation
|
245
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
246
|
+
demodulize
|
247
|
+
|
248
|
+
# Standard in rails. See official documentation
|
249
|
+
# [http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html]
|
250
|
+
underscore
|
251
|
+
|
252
|
+
# Check that instance of String is start with an upper case or not
|
253
|
+
capitalized?
|
254
|
+
|
255
|
+
|
256
|
+
in Yml
|
257
|
+
|
258
|
+
self.save_file(file_path,config_hash)
|
259
|
+
|
260
|
+
self.load_file(file_path)
|
261
|
+
|
262
|
+
|
263
|
+
in Object
|
264
|
+
|
265
|
+
# The hidden singleton lurks behind everyone
|
266
|
+
metaclass; class << self; self; end; end
|
267
|
+
|
268
|
+
# extend the metaclass with an instance eval
|
269
|
+
meta_eval &blk; metaclass.instance_eval &blk; end
|
270
|
+
|
271
|
+
# Adds methods to a metaclass
|
272
|
+
meta_name, &blk
|
273
|
+
|
274
|
+
# Defines an instance method within a class
|
275
|
+
class_name, &blk
|
276
|
+
|
277
|
+
# constantize object
|
278
|
+
constantize
|
279
|
+
|
280
|
+
# find and replace object in object
|
281
|
+
find_and_replace(input,*params)
|
282
|
+
|
283
|
+
# some default values
|
284
|
+
#None!
|
285
|
+
# Do the find and replace
|
286
|
+
# return value
|
287
|
+
# each for any object
|
288
|
+
each_universal(&block)
|
289
|
+
|
290
|
+
# map an object => experiment
|
291
|
+
map_object(symbol_key="$type")
|
292
|
+
|
293
|
+
# processing
|
294
|
+
# finish
|
295
|
+
# is class?
|
296
|
+
class?
|
297
|
+
|
298
|
+
# convert class instance instance variables into a hash object
|
299
|
+
convert_to_hash
|
300
|
+
|
301
|
+
raise NoMethodError, "undefined method `to_hash' for#{self.inspect}"
|
302
|
+
# this will check that the class is
|
303
|
+
# defined or not in the runtime memory
|
304
|
+
class_exists?
|
305
|
+
|
306
|
+
# This will convert a symbol or string and format to be a valid
|
307
|
+
# constant name and create from it a class with instance attribute accessors
|
308
|
+
# Best use is when you get raw data in string from external source
|
309
|
+
# and you want make them class objects
|
310
|
+
#
|
311
|
+
# :hello_world.to_class(:test)
|
312
|
+
# HelloWorld.to_class(:sup)
|
313
|
+
# hw_var = HelloWorld.new
|
314
|
+
# hw_var.sup = "Fine thanks!"
|
315
|
+
# hw_var.test = 5
|
316
|
+
#
|
317
|
+
# puts hw_var.test
|
318
|
+
#
|
319
|
+
#> produce 5 :Integer
|
320
|
+
#
|
321
|
+
# you can also use this formats
|
322
|
+
# :HelloWorld , "hello.world",
|
323
|
+
# "hello/world", "Hello::World",
|
324
|
+
# "hello:world"...
|
325
|
+
to_class(*attributes)
|
326
|
+
|
327
|
+
|
328
|
+
in File
|
329
|
+
|
330
|
+
self.create(route_name ,filemod="w",string_data=String.new)
|
331
|
+
|
332
|
+
|
333
|
+
in Array
|
334
|
+
|
335
|
+
# remove arguments or array of
|
336
|
+
# parameters from the main array
|
337
|
+
trim(*args)
|
338
|
+
|
339
|
+
# return index of the target element
|
340
|
+
index_of(target_element)
|
341
|
+
|
342
|
+
# remove n. element from the end
|
343
|
+
# and return a new object
|
344
|
+
pinch n=1
|
345
|
+
|
346
|
+
# remove n. element from the end
|
347
|
+
# and return the original object
|
348
|
+
pinch! n=1
|
349
|
+
|
350
|
+
# return boolean by other array
|
351
|
+
# all element included or
|
352
|
+
# not in the target array
|
353
|
+
contain?(oth_array)#anothere array
|
354
|
+
|
355
|
+
# do safe transpose
|
356
|
+
safe_transpose
|
357
|
+
|
358
|
+
|
359
|
+
in Class
|
360
|
+
|
361
|
+
# get singleton methods to target class without super class methods
|
362
|
+
class_methods
|
363
|
+
|
364
|
+
# bind a singleton method to a class object
|
365
|
+
create_class_method(method,&block)
|
366
|
+
|
367
|
+
# create an instance method
|
368
|
+
create_instance_method(method,&block)
|
369
|
+
|
370
|
+
# Iterates over all subclasses (direct and indirect)
|
371
|
+
each_subclass
|
372
|
+
|
373
|
+
# Returns an Array of subclasses (direct and indirect)
|
374
|
+
subclasses
|
375
|
+
|
376
|
+
# Returns an Array of direct subclasses
|
377
|
+
direct_subclasses
|
378
|
+
|
379
|
+
# create singleton attribute
|
380
|
+
class_attr_accessor(name)
|
381
|
+
|
382
|
+
# GET
|
383
|
+
# SET
|
384
|
+
# create class instance attribute
|
385
|
+
instance_attr_accessor(name)
|
386
|
+
|
387
|
+
|
388
|
+
in Integer
|
389
|
+
|
390
|
+
# because for i in integer/fixnum not working,
|
391
|
+
# here is a little patch
|
392
|
+
each &block
|
393
|
+
|
394
|
+
|
395
|
+
in Random
|
396
|
+
|
397
|
+
string(length= 7,amount=1)
|
398
|
+
|
399
|
+
integer(length= 3)
|
400
|
+
|
401
|
+
boolean
|
402
|
+
|
403
|
+
time from = Time.at(1114924812), to = Time.now
|
404
|
+
|
405
|
+
date from = Time.at(1114924812), to = Time.now
|
406
|
+
|
407
|
+
datetime from = Time.at(1114924812), to = Time.now
|
408
|
+
|
409
|
+
|
410
|
+
in Hash
|
411
|
+
|
412
|
+
# remove elements by keys,
|
413
|
+
# array of keys,
|
414
|
+
# hashTags,
|
415
|
+
# strings
|
416
|
+
trim(*args)
|
417
|
+
|
418
|
+
#pass single or array of keys, which will be removed, returning the remaining hash
|
419
|
+
remove!(*keys)
|
420
|
+
|
421
|
+
#non-destructive version
|
422
|
+
remove(*keys)
|
423
|
+
|
424
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
425
|
+
#
|
426
|
+
# h1 = {:x => {:y => [4,5,6]}, :z => [7,8,9]}
|
427
|
+
# h2 = {:x => {:y => [7,8,9]}, :z => "xyz"}
|
428
|
+
#
|
429
|
+
# h1.deep_merge(h2#=> { :x => {:y => [7, 8, 9]}, :z => "xyz" }
|
430
|
+
# h2.deep_merge(h1#=> { :x => {:y => [4, 5, 6]}, :z => [7, 8, 9] }
|
431
|
+
deep_merge(other_hash)
|
432
|
+
|
433
|
+
# Same as +deep_merge+, but modifies +self+.
|
434
|
+
deep_merge!(other_hash)
|
435
|
+
|
436
|
+
# return bool that does the sub hash all element include the hash who call this or not
|
437
|
+
deep_include?(sub_hash)
|
438
|
+
|
439
|
+
|
440
|
+
in Kernel
|
441
|
+
|
442
|
+
putsf(integer,*args)
|
data/test/test.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
#number_at = 0
|
2
|
+
#loop do
|
3
|
+
#
|
4
|
+
# number_at += 1
|
5
|
+
# break if number_at > 100
|
6
|
+
#
|
7
|
+
# if number_at % 3 == 0 && number_at % 5
|
8
|
+
# puts "FizzBuzz #{number_at}"
|
9
|
+
# next
|
10
|
+
# elsif number_at % 3 == 0
|
11
|
+
# puts "Fizz #{number_at}"
|
12
|
+
# next
|
13
|
+
# elsif number_at % 5
|
14
|
+
# puts "Buzz #{number_at}"
|
15
|
+
# next
|
16
|
+
# else
|
17
|
+
# puts number_at
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
#end
|
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.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,13 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: This is a collection of my Ruby Procs in the adventure of becoming
|
15
|
-
best!
|
16
|
-
|
17
|
-
|
18
|
-
etc
|
14
|
+
description: ! 'This is a collection of my Ruby Procs in the adventure of becoming
|
15
|
+
the best! In short this provides extra tools in Application configs, argumens processing,daemonise,
|
16
|
+
eval,port check, require relative files, or directories, string to duck parsing,
|
17
|
+
system tmp_dir using, meta-programing, and a lot of monkey patch for extra functionality '
|
19
18
|
email:
|
20
19
|
- adamluzsi@gmail.com
|
21
20
|
executables: []
|
@@ -30,6 +29,7 @@ files:
|
|
30
29
|
- VERSION
|
31
30
|
- dump/macaddr.rb
|
32
31
|
- dump/uuid.rb
|
32
|
+
- files.rb
|
33
33
|
- lib/procemon.rb
|
34
34
|
- lib/procemon/function/application.rb
|
35
35
|
- lib/procemon/function/argv.rb
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/procemon/mpatch/exception.rb
|
49
49
|
- lib/procemon/mpatch/file.rb
|
50
50
|
- lib/procemon/mpatch/hash.rb
|
51
|
+
- lib/procemon/mpatch/integer.rb
|
51
52
|
- lib/procemon/mpatch/kernel.rb
|
52
53
|
- lib/procemon/mpatch/object.rb
|
53
54
|
- lib/procemon/mpatch/process.rb
|
@@ -55,6 +56,8 @@ files:
|
|
55
56
|
- lib/procemon/mpatch/string.rb
|
56
57
|
- lib/procemon/mpatch/yml.rb
|
57
58
|
- procemon.gemspec
|
59
|
+
- scripts/doc_gen.rb
|
60
|
+
- scripts/test.txt
|
58
61
|
- test/bump/test2.rb
|
59
62
|
- test/test.rb
|
60
63
|
homepage: https://github.com/adamluzsi/procemon
|
@@ -72,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
75
|
version: '0'
|
73
76
|
segments:
|
74
77
|
- 0
|
75
|
-
hash:
|
78
|
+
hash: -3727777530014269830
|
76
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
80
|
none: false
|
78
81
|
requirements:
|