procemon 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/procemon/function/meta/binding/binding.rb +5 -1
- data/lib/procemon/mpatch/file.rb +23 -0
- data/lib/procemon/mpatch/proc.rb +36 -0
- data/lib/procemon/mpatch/string.rb +26 -4
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/procemon/mpatch/file.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class File
|
2
|
+
|
3
|
+
# create a file, if not exsist create file, and dir if needed
|
2
4
|
def self.create(route_name ,filemod="w",string_data=String.new)
|
3
5
|
begin
|
4
6
|
|
@@ -45,4 +47,25 @@ class File
|
|
45
47
|
puts ex
|
46
48
|
end
|
47
49
|
end
|
50
|
+
|
51
|
+
# start read the file object on each line
|
52
|
+
# optionable an integer value to start read line at
|
53
|
+
# compatible with mac (i am linux user, so not tested)
|
54
|
+
def each_line_from(start_at=1,&block)
|
55
|
+
unless [Integer,Fixnum,Bignum].include?(start_at.class)
|
56
|
+
raise ArgumentError, "invalid line index"
|
57
|
+
end
|
58
|
+
begin
|
59
|
+
line_num= 1
|
60
|
+
text= self.read
|
61
|
+
text.gsub!(/\r\n?/, "\n")
|
62
|
+
text.each_line do |*line|
|
63
|
+
if line_num >= start_at
|
64
|
+
block.call *line
|
65
|
+
end
|
66
|
+
line_num += 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
48
71
|
end
|
data/lib/procemon/mpatch/proc.rb
CHANGED
@@ -9,4 +9,40 @@ class Proc
|
|
9
9
|
Proc.new { |*args| self[*other[*args]] }
|
10
10
|
end unless method_defined? :*
|
11
11
|
|
12
|
+
|
13
|
+
# create a raw eval-able process source, so you can set
|
14
|
+
# the right bindings using the .to_proc call from String methods
|
15
|
+
@@source_cache= Hash.new
|
16
|
+
def source
|
17
|
+
|
18
|
+
# defaults
|
19
|
+
begin
|
20
|
+
return_string= String.new
|
21
|
+
block= 0
|
22
|
+
end
|
23
|
+
|
24
|
+
if @@source_cache.keys.include? self.object_id
|
25
|
+
return @@source_cache[self.object_id]
|
26
|
+
else
|
27
|
+
File.open(Dir.pwd.dup.concat(File::Separator).concat(self.source_location[0])
|
28
|
+
).each_line_from self.source_location[1] do |line|
|
29
|
+
|
30
|
+
line.gsub!(/\bdo\b/,'{')
|
31
|
+
line.gsub!(/\bend\b/,'}')
|
32
|
+
|
33
|
+
block += line.frequency /{/
|
34
|
+
block -= line.frequency /}/
|
35
|
+
|
36
|
+
return_string.concat(line)
|
37
|
+
break if block == 0
|
38
|
+
end
|
39
|
+
|
40
|
+
return_string.sub!(/^[\w\W]*Proc.new\s*{/,'Proc.new{')
|
41
|
+
return_string.sub!(/}[^}]*$/,"}")
|
42
|
+
@@source_cache[self.object_id]= return_string
|
43
|
+
return return_string
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
12
48
|
end
|
@@ -64,10 +64,32 @@ class String
|
|
64
64
|
self.match(/^[[:upper:]]/) ? true : false
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
# return the number how often the str is with in the self
|
68
|
+
# by default with \b regex border
|
69
|
+
def frequency(str)
|
70
|
+
begin
|
71
|
+
if str.class == String
|
72
|
+
str= '\b'+str+'\b'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
self.scan(/#{str}/).count
|
76
|
+
end
|
77
|
+
|
78
|
+
# create process object from valid process string
|
79
|
+
def to_proc(binding=nil)
|
80
|
+
begin
|
81
|
+
|
82
|
+
if !self.include?('Proc.new') && !self.include?('lambda')
|
83
|
+
raise ArgumentError, "string obj is not a valid process source"
|
84
|
+
end
|
68
85
|
|
69
|
-
|
86
|
+
if binding.nil?
|
87
|
+
return eval(self)
|
88
|
+
else
|
89
|
+
return eval(self,binding)
|
90
|
+
end
|
70
91
|
|
71
|
-
|
92
|
+
end
|
93
|
+
end
|
72
94
|
|
73
|
-
|
95
|
+
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.1.
|
4
|
+
version: 0.1.3
|
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-12-
|
12
|
+
date: 2013-12-20 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,
|