carbolic 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/carbolic.rb +97 -14
- metadata +8 -7
data/lib/carbolic.rb
CHANGED
@@ -2,13 +2,42 @@
|
|
2
2
|
|
3
3
|
# file: carbolic.rb
|
4
4
|
|
5
|
-
require 'builder'
|
5
|
+
require 'rexle-builder'
|
6
|
+
require 'rexle'
|
7
|
+
|
8
|
+
class Items
|
9
|
+
|
10
|
+
attr_reader :names
|
11
|
+
|
12
|
+
def initialize()
|
13
|
+
@names = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def trace(name)
|
17
|
+
@names << name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
6
21
|
|
7
22
|
class Carbolic
|
8
23
|
|
9
24
|
def initialize(obj)
|
10
25
|
carbolic(obj)
|
11
26
|
end
|
27
|
+
|
28
|
+
def self.log(log="this_daily.log")
|
29
|
+
$carbolic_log = Logger.new(log, 'daily')
|
30
|
+
$carbolic_log2 = File.open('trace.txt','w')
|
31
|
+
|
32
|
+
items = Items.new
|
33
|
+
yield items
|
34
|
+
a = items.names
|
35
|
+
c = "def initialize() \
|
36
|
+
Carbolic.new(self) if #{a.inspect}.include? self.class.to_s end
|
37
|
+
def self.empty?() end"
|
38
|
+
Object.class_eval c
|
39
|
+
end
|
40
|
+
|
12
41
|
|
13
42
|
private
|
14
43
|
|
@@ -24,9 +53,12 @@ class Carbolic
|
|
24
53
|
|
25
54
|
h = Hash[*a.flatten(1)]
|
26
55
|
File.open("class_#{h[:class]}.xml",'w'){|f| f.write store(a)}
|
27
|
-
|
56
|
+
|
57
|
+
|
28
58
|
obj.instance_eval(){
|
29
59
|
|
60
|
+
require 'rexle-builder'
|
61
|
+
|
30
62
|
def x_inspect(x)
|
31
63
|
if x.respond_to? :to_s
|
32
64
|
(x.inspect.length < 150 ? x.inspect : x.inspect[0..145] + '...')
|
@@ -35,21 +67,74 @@ class Carbolic
|
|
35
67
|
end
|
36
68
|
end
|
37
69
|
|
38
|
-
def log_method(a=[], vars=[],
|
39
|
-
|
70
|
+
def log_method(a=[], vars=[], raw_args=[])
|
71
|
+
instance_vars = vars.map{|x| [x,x_inspect(self.instance_variable_get(x))]}
|
72
|
+
label_vars = instance_vars.map{|x| "%s: %s" % x}
|
40
73
|
line = "%s, in, %s, " % [self.class, (a + label_vars).flatten.join(', ')]
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
basic_args.
|
74
|
+
|
75
|
+
ffsa_args = raw_args.select {|x| x.class.to_s[/Float|Fixnum|String|Array|TrueClass|FalseClass/] }
|
76
|
+
args = ffsa_args.map{|x| [x.class.to_s, x_inspect(x)]}
|
77
|
+
basic_args = args.map {|x| "%s: %s" % x}
|
78
|
+
|
45
79
|
$carbolic_log.debug line << basic_args.join(', ')
|
80
|
+
$carbolic_log2.write ",['call','',{},"
|
81
|
+
$carbolic_log2.write info_in(self.class, a, instance_vars, args)
|
82
|
+
#$carbolic_log2.add Rexle.new()
|
83
|
+
$carbolic_log2.write ", ['calls', '', {}"
|
46
84
|
r = yield
|
85
|
+
$carbolic_log2.write "],"
|
47
86
|
label_vars = vars.map{|x| "%s: %s, " % [x,x_inspect(self.instance_variable_get(x))]}
|
48
87
|
line = "%s, out, %s, " % [self.class, ([a.first] + label_vars).flatten.join(', ')]
|
49
|
-
|
88
|
+
rval = r.class.to_s[/Float|Fixnum|String|Array|TrueClass|FalseClass/] ? [r.class.to_s, x_inspect(r)] : nil
|
89
|
+
line << "%s: %s" % rval if rval
|
50
90
|
$carbolic_log.debug line
|
91
|
+
|
92
|
+
$carbolic_log2.write info_out(self.class, a.first, instance_vars, rval)
|
93
|
+
$carbolic_log2.write "]"
|
94
|
+
|
51
95
|
r
|
52
96
|
end
|
97
|
+
|
98
|
+
def info_in(class_name, origins=[], instance_vars=[], args=[])
|
99
|
+
|
100
|
+
xml = RexleBuilder.new
|
101
|
+
a = xml.in do
|
102
|
+
xml.class_name class_name.to_s
|
103
|
+
xml.origins do
|
104
|
+
origins.each do |x|
|
105
|
+
xml.origin x
|
106
|
+
end
|
107
|
+
end
|
108
|
+
xml.instance_vars do
|
109
|
+
instance_vars.each do |x|
|
110
|
+
xml.send x[0].to_s.sub('@',''), x[1].to_s.gsub('"','')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
xml.args do
|
114
|
+
args.each do |x|
|
115
|
+
xml.send x[0].downcase.sub(/:"/,''), x[1].to_s.gsub('"','')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
a
|
121
|
+
end
|
122
|
+
|
123
|
+
def info_out(class_name, origin, instance_vars=[], r)
|
124
|
+
xml = RexleBuilder.new
|
125
|
+
a = xml.out do
|
126
|
+
xml.class_name class_name.to_s
|
127
|
+
xml.origin origin
|
128
|
+
xml.instance_vars do
|
129
|
+
instance_vars.each do |x|
|
130
|
+
xml.send x[0].to_s.sub('@',''), x[1].to_s.gsub('"','')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
xml.send r[0].downcase.sub(':',''), r[1].to_s.gsub('"','') if r
|
134
|
+
end
|
135
|
+
|
136
|
+
a
|
137
|
+
end
|
53
138
|
}
|
54
139
|
|
55
140
|
methodx = []
|
@@ -66,15 +151,13 @@ class Carbolic
|
|
66
151
|
end
|
67
152
|
obj.instance_eval(methodx.join("\n"))
|
68
153
|
|
69
|
-
end
|
154
|
+
end
|
70
155
|
|
71
156
|
def store(a)
|
72
157
|
|
73
158
|
a.map!{|label, value| [label, value.is_a?(Array) ? value.sort.join(', ') : value.to_s]}
|
74
159
|
|
75
|
-
xml =
|
76
|
-
xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
|
77
|
-
|
160
|
+
xml = RexleBuilder.new
|
78
161
|
xml.class_info do
|
79
162
|
xml.summary do
|
80
163
|
a.each {|label, val| xml.send(label.to_s + 'x', val) }
|
@@ -82,7 +165,7 @@ class Carbolic
|
|
82
165
|
xml.records
|
83
166
|
end
|
84
167
|
|
85
|
-
|
168
|
+
Rexle.new(xml.to_a).xml pretty: true
|
86
169
|
end
|
87
170
|
|
88
171
|
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carbolic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.2
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
|
7
|
+
authors:
|
8
|
+
- James Robertson
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date:
|
13
|
+
date: 2011-09-14 00:00:00 +01:00
|
13
14
|
default_executable:
|
14
15
|
dependencies: []
|
15
16
|
|
@@ -33,21 +34,21 @@ rdoc_options: []
|
|
33
34
|
require_paths:
|
34
35
|
- lib
|
35
36
|
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
36
38
|
requirements:
|
37
39
|
- - ">="
|
38
40
|
- !ruby/object:Gem::Version
|
39
41
|
version: "0"
|
40
|
-
version:
|
41
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
42
44
|
requirements:
|
43
45
|
- - ">="
|
44
46
|
- !ruby/object:Gem::Version
|
45
47
|
version: "0"
|
46
|
-
version:
|
47
48
|
requirements: []
|
48
49
|
|
49
50
|
rubyforge_project:
|
50
|
-
rubygems_version: 1.
|
51
|
+
rubygems_version: 1.5.2
|
51
52
|
signing_key:
|
52
53
|
specification_version: 3
|
53
54
|
summary: carbolic
|