procemon 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +1 -0
- data/VERSION +1 -1
- data/lib/procemon.rb +2 -0
- data/lib/procemon/mpatch/file.rb +1 -1
- data/procemon.gemspec +2 -5
- metadata +16 -9
- data/examples/fun_with_procs_and_methods.rb +0 -78
- data/lib/procemon/function/proc_source/method.rb +0 -71
- data/lib/procemon/function/proc_source/proc.rb +0 -44
- data/lib/procemon/function/proc_source/proc_source.rb +0 -101
- data/lib/procemon/function/proc_source/proc_source_body.rb +0 -12
- data/lib/procemon/function/proc_source/proc_source_params.rb +0 -35
- data/lib/procemon/function/proc_source/string.rb +0 -14
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZWQ5YTU2MGNhNzg5MTRlMTUzNzJjMmM0ZjQzYzhlZjBkMjMzOGI0NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzEwYjk4NjZiZGJjN2YwMmNmOGQ5YmM3ZGNjMjlmMjE4ZDg2Y2IxMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmEzMGE5NjcyMWE3YTNlOWM2ZWIwYTNiYTIyYzdiNGU1YjA3NWNhYTI0YjJm
|
10
|
+
YzdhMjI0MTMzMTBkMWVjYTI5OGMwZDQyZjNkNTUyMDAzOWE5NWE0NzM2Mjc4
|
11
|
+
M2FkYTYwNDRmNDlkODdjOGQ2OGFlNTk5MGI0NTU2NjI4NjBmYzQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2M4ZjJlOThmNjE3ZWJkNzk3NDM5MTAxMzZjN2ZmYmQ4YTEzY2Y0ZTc5ZDMx
|
14
|
+
MDIwZjI2NjE5MTY3ZjY5Mzk3NGJkYTk0YTZiOGNkYWUzMGQ2NjZhNjY0NGZi
|
15
|
+
ZDQ1MjhjMmRhMDczMGVkMzI5OTNmYWIyZmY0YmI2Zjc3YTYwZTg=
|
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/lib/procemon.rb
CHANGED
data/lib/procemon/mpatch/file.rb
CHANGED
data/procemon.gemspec
CHANGED
@@ -19,10 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
|
23
|
-
spec.
|
24
|
-
|
25
|
-
##=======Development-ENV============##
|
26
|
-
#spec.add_development_dependency "asynchronous"#,['~>4.1.3']
|
22
|
+
spec.add_dependency "asynchronous"
|
23
|
+
spec.add_dependency "sourcerer"
|
27
24
|
|
28
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: procemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.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-01-
|
11
|
+
date: 2014-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asynchronous
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sourcerer
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: ! 'This is a collection of my Ruby Procs in the adventure of becoming
|
28
42
|
the best! In short this provides extra tools in Application configs, argumens processing,daemonise,eval,
|
29
43
|
getting source of a block,method,process and work with it, or even fuse them into
|
@@ -44,7 +58,6 @@ files:
|
|
44
58
|
- README.md
|
45
59
|
- Rakefile
|
46
60
|
- VERSION
|
47
|
-
- examples/fun_with_procs_and_methods.rb
|
48
61
|
- examples/how_to_inject_with_extra_process_a_method.rb
|
49
62
|
- examples/require_files.rb
|
50
63
|
- examples/simple_async_processing.rb
|
@@ -63,12 +76,6 @@ files:
|
|
63
76
|
- lib/procemon/function/meta/inject_methods.rb
|
64
77
|
- lib/procemon/function/name.rb
|
65
78
|
- lib/procemon/function/port.rb
|
66
|
-
- lib/procemon/function/proc_source/method.rb
|
67
|
-
- lib/procemon/function/proc_source/proc.rb
|
68
|
-
- lib/procemon/function/proc_source/proc_source.rb
|
69
|
-
- lib/procemon/function/proc_source/proc_source_body.rb
|
70
|
-
- lib/procemon/function/proc_source/proc_source_params.rb
|
71
|
-
- lib/procemon/function/proc_source/string.rb
|
72
79
|
- lib/procemon/function/require.rb
|
73
80
|
- lib/procemon/function/sender.rb
|
74
81
|
- lib/procemon/function/systemu.rb
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require_relative "../lib/procemon.rb"
|
2
|
-
|
3
|
-
test= Proc.new do |*params|
|
4
|
-
|
5
|
-
puts "some awsome code here"
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def hello_this sup,yo,lazy=nil
|
10
|
-
|
11
|
-
puts "this is the Body!"
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
method_source= method(:hello_this).source
|
17
|
-
#Proc.new{ |sup,yo,lazy=nil,*params|
|
18
|
-
#
|
19
|
-
# puts "this is the Body!"
|
20
|
-
#
|
21
|
-
#}
|
22
|
-
|
23
|
-
proc_source= test.source
|
24
|
-
#Proc.new{ |*params|
|
25
|
-
#
|
26
|
-
# puts "some awsome code here"
|
27
|
-
#
|
28
|
-
#}
|
29
|
-
|
30
|
-
puts Proc.new{|e| puts e }.source.body
|
31
|
-
|
32
|
-
Process.exit
|
33
|
-
|
34
|
-
# example for terminal run
|
35
|
-
puts method_source
|
36
|
-
puts method_source.body,"---------"
|
37
|
-
puts method_source.params,"---------"
|
38
|
-
puts method_source.parameters.inspect,"---------"
|
39
|
-
puts method_source.params.inspect,"---------"
|
40
|
-
|
41
|
-
puts "\n"
|
42
|
-
|
43
|
-
merged_proc= ( method_source.body +
|
44
|
-
proc_source.body
|
45
|
-
).build(*(method_source.params+proc_source.params))
|
46
|
-
puts merged_proc
|
47
|
-
puts merged_proc.to_proc
|
48
|
-
puts merged_proc.to_proc.source
|
49
|
-
|
50
|
-
|
51
|
-
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
52
|
-
|
53
|
-
class A
|
54
|
-
|
55
|
-
class << self
|
56
|
-
|
57
|
-
def hello test=nil
|
58
|
-
puts "world!"
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.singleton test=nil
|
64
|
-
puts "singleton"
|
65
|
-
end
|
66
|
-
|
67
|
-
def instance hello= "wolrd"
|
68
|
-
puts "instance"
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
puts A.instance_method(:instance).source
|
74
|
-
|
75
|
-
puts A.method(:singleton).source
|
76
|
-
|
77
|
-
|
78
|
-
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
@@ -1,71 +0,0 @@
|
|
1
|
-
module MethodToProcSource
|
2
|
-
|
3
|
-
# creatue a raw eval-able process source, so you can set
|
4
|
-
# the right bindings using the .to_proc call from String methods
|
5
|
-
def source
|
6
|
-
|
7
|
-
# defaults
|
8
|
-
begin
|
9
|
-
return_string= ProcSource.new
|
10
|
-
block= 0
|
11
|
-
end
|
12
|
-
|
13
|
-
unless ProcSource.source_cache[self.inspect].nil?
|
14
|
-
return ProcSource.source_cache[self.inspect]
|
15
|
-
else
|
16
|
-
|
17
|
-
if self.source_location.nil?
|
18
|
-
return nil
|
19
|
-
end
|
20
|
-
|
21
|
-
File.open(File.expand_path(self.source_location[0])
|
22
|
-
).each_line_from self.source_location[1] do |line|
|
23
|
-
block += line.source_formater_for_line_sub
|
24
|
-
return_string.concat(line)
|
25
|
-
break if block == 0
|
26
|
-
end
|
27
|
-
|
28
|
-
begin
|
29
|
-
|
30
|
-
if return_string.split("\n")[0].include? '('
|
31
|
-
return_string.sub!('(',' ')
|
32
|
-
return_string.sub!(')',' ')
|
33
|
-
end
|
34
|
-
|
35
|
-
args_to_replace = return_string.split("\n")[0].match(/\s*def\s*\S*\s*(.*)/).captures[0]
|
36
|
-
|
37
|
-
if args_to_replace != String.new
|
38
|
-
return_string.sub!(args_to_replace,"|#{args_to_replace}|")
|
39
|
-
end
|
40
|
-
|
41
|
-
rescue TypeError,NoMethodError
|
42
|
-
return nil
|
43
|
-
end
|
44
|
-
|
45
|
-
return_string.sub!(/\s*\bdef\s*[\w\S]*/,'Proc.new{')
|
46
|
-
return_string.sub!(/}[^}]*$/,"}")
|
47
|
-
|
48
|
-
if !return_string.include?('Proc.new')
|
49
|
-
return_string.sub!(/^[^{]*(?!={)/,'Proc.new')
|
50
|
-
end
|
51
|
-
|
52
|
-
if !self.source_location.nil?
|
53
|
-
ProcSource.source_cache[self.inspect]= return_string
|
54
|
-
end
|
55
|
-
|
56
|
-
return return_string
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
alias :source_string :source
|
61
|
-
alias :proc_source :source
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
class Method
|
66
|
-
include MethodToProcSource
|
67
|
-
end
|
68
|
-
|
69
|
-
class UnboundMethod
|
70
|
-
include MethodToProcSource
|
71
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
class Proc
|
2
|
-
|
3
|
-
# create a raw eval-able process source, so you can set
|
4
|
-
# the right bindings using the .to_proc call from String methods
|
5
|
-
def source
|
6
|
-
|
7
|
-
# defaults
|
8
|
-
begin
|
9
|
-
return_string= ProcSource.new
|
10
|
-
block= 0
|
11
|
-
end
|
12
|
-
|
13
|
-
unless ProcSource.source_cache[self.inspect].nil?
|
14
|
-
return ProcSource.source_cache[self.inspect]
|
15
|
-
else
|
16
|
-
|
17
|
-
if self.source_location.nil?
|
18
|
-
return "Proc.new { }"
|
19
|
-
end
|
20
|
-
|
21
|
-
File.open(File.expand_path(self.source_location[0])
|
22
|
-
).each_line_from self.source_location[1] do |line|
|
23
|
-
block += line.source_formater_for_line_sub
|
24
|
-
return_string.concat(line)
|
25
|
-
break if block == 0
|
26
|
-
end
|
27
|
-
|
28
|
-
return_string.sub!(/^[\w\W]*Proc.new\s*{/,'Proc.new{')
|
29
|
-
return_string.sub!(/}[^}]*$/,"}")
|
30
|
-
|
31
|
-
if !return_string.include?('Proc.new')
|
32
|
-
return_string.sub!(/^[^{]*(?!={)/,'Proc.new')
|
33
|
-
end
|
34
|
-
|
35
|
-
if !self.source_location.nil?
|
36
|
-
ProcSource.source_cache[self.inspect]= return_string
|
37
|
-
end
|
38
|
-
|
39
|
-
return return_string
|
40
|
-
end
|
41
|
-
end
|
42
|
-
alias :source_string :source
|
43
|
-
|
44
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
class ProcSource < String
|
2
|
-
|
3
|
-
class << self
|
4
|
-
attr_accessor :source_cache
|
5
|
-
attr_accessor :eval_keys
|
6
|
-
end
|
7
|
-
self.source_cache= Hash.new
|
8
|
-
self.eval_keys= Array.new
|
9
|
-
|
10
|
-
|
11
|
-
def self.build(source_code_to_be_wrappered,*params_obj_array)
|
12
|
-
self.new(source_code_to_be_wrappered).wrapper_around!(*params_obj_array)
|
13
|
-
end
|
14
|
-
|
15
|
-
def wrapper_around!(*params)
|
16
|
-
if !params.nil?
|
17
|
-
params= params.join(',')
|
18
|
-
params.prepend(' |')
|
19
|
-
params.concat('|')
|
20
|
-
end
|
21
|
-
self.prepend("Proc.new{#{params}\n")
|
22
|
-
self.concat("\n}")
|
23
|
-
end
|
24
|
-
|
25
|
-
# create process object from valid process string
|
26
|
-
def to_proc(binding=nil)
|
27
|
-
begin
|
28
|
-
|
29
|
-
unless self.split("\n")[0].include?('Proc.new')
|
30
|
-
raise ArgumentError, "string obj is not a valid process source"
|
31
|
-
end
|
32
|
-
|
33
|
-
return_proc= nil
|
34
|
-
if binding.nil?
|
35
|
-
return_proc= eval(self)
|
36
|
-
else
|
37
|
-
return_proc= eval(self,binding)
|
38
|
-
end
|
39
|
-
|
40
|
-
if ProcSource.eval_keys.count > 1000
|
41
|
-
ProcSource.eval_keys.each {|e| ProcSource.source_cache.delete(e) }
|
42
|
-
ProcSource.eval_keys.clear
|
43
|
-
end
|
44
|
-
ProcSource.source_cache[return_proc.inspect]= self
|
45
|
-
ProcSource.eval_keys.push return_proc.inspect
|
46
|
-
|
47
|
-
return return_proc
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def body
|
52
|
-
|
53
|
-
body= ProcSourceBody.new(self.dup.to_s)
|
54
|
-
body.sub!(/.*Proc\.new *{ *(\|.*\|)?/,String.new)
|
55
|
-
body.gsub!(/^$\n/, String.new)
|
56
|
-
body.sub!(/\s*}\s*$/,String.new)
|
57
|
-
|
58
|
-
return body
|
59
|
-
end
|
60
|
-
|
61
|
-
def params
|
62
|
-
#SystemStackError
|
63
|
-
params= self.dup
|
64
|
-
params.sub!(params.split("\n")[0].scan(/\s*Proc.new\s*{/)[0],String.new)
|
65
|
-
params.sub!(' ','')
|
66
|
-
params= params.split("\n")[0].scan(/^\s*{?\s*(.*)/)[0][0].gsub!('|','')
|
67
|
-
if params.nil?
|
68
|
-
return nil
|
69
|
-
end
|
70
|
-
return ProcSourceParams[*params.split(',')]
|
71
|
-
end
|
72
|
-
|
73
|
-
def parameters
|
74
|
-
|
75
|
-
return_array= Array.new
|
76
|
-
params= self.params
|
77
|
-
params.each do |one_raw_parameter|
|
78
|
-
case true
|
79
|
-
when one_raw_parameter.include?('=')
|
80
|
-
begin
|
81
|
-
return_array.push Array.new.push(:opt).push(
|
82
|
-
one_raw_parameter.split('=')[0].to_sym)
|
83
|
-
end
|
84
|
-
when one_raw_parameter[0] == '*'
|
85
|
-
begin
|
86
|
-
one_raw_parameter[0]= ''
|
87
|
-
return_array.push Array.new.push(:rest).push(
|
88
|
-
one_raw_parameter.to_sym)
|
89
|
-
end
|
90
|
-
else
|
91
|
-
begin
|
92
|
-
return_array.push Array.new.push(:req).push(
|
93
|
-
one_raw_parameter.to_sym)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
return return_array
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
class ProcSourceParams < Array
|
2
|
-
|
3
|
-
# merge two proc params obj
|
4
|
-
# if multiple rest obj found
|
5
|
-
# it will remove and make an *args obj as last element
|
6
|
-
# if they are not equal ,
|
7
|
-
# else it makes it the last element only
|
8
|
-
def +(oth_ary)
|
9
|
-
|
10
|
-
merged_array= (Array[*self]+Array[*oth_ary])
|
11
|
-
|
12
|
-
rest_state= nil
|
13
|
-
rest_elements= Array.new
|
14
|
-
merged_array.dup.each do |element|
|
15
|
-
if element.include? '*'
|
16
|
-
merged_array.delete(element)
|
17
|
-
rest_state ||= true
|
18
|
-
rest_elements.push(element)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
rest_elements.uniq!
|
23
|
-
if rest_elements.count == 1 && !rest_elements.empty?
|
24
|
-
merged_array.push(rest_elements[0])
|
25
|
-
rest_state= nil
|
26
|
-
end
|
27
|
-
|
28
|
-
unless rest_state.nil?
|
29
|
-
merged_array.push('*args')
|
30
|
-
end
|
31
|
-
|
32
|
-
return ProcSourceParams[*merged_array]
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
# this is a helper to create source strings from procs
|
4
|
-
def source_formater_for_line_sub
|
5
|
-
self.gsub!(';',"\n")
|
6
|
-
self.gsub!(/\bdo\b/,'{')
|
7
|
-
self.gsub!(/\bend\b/,'}')
|
8
|
-
|
9
|
-
self.frequency(/{/)+
|
10
|
-
self.frequency(/def/)-
|
11
|
-
self.frequency(/}/)
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|