carbolic 0.1.0

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.
Files changed (2) hide show
  1. data/lib/carbolic.rb +89 -0
  2. metadata +55 -0
data/lib/carbolic.rb ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # file: carbolic.rb
4
+
5
+ require 'builder'
6
+
7
+ class Carbolic
8
+
9
+ def initialize(obj)
10
+ carbolic(obj)
11
+ end
12
+
13
+ private
14
+
15
+ def carbolic(obj)
16
+
17
+ a = [[:public_methods, (obj.public_methods - Object.public_methods)],
18
+ [:private_methods, ((obj.private_methods - Object.private_methods) - [:autoload, :autoload?])],
19
+ [:protected_methods, (obj.protected_methods - Object.protected_methods)],
20
+ [:singleton_methods, obj.singleton_methods],
21
+ [:class, obj.class],
22
+ [:object_id, obj.object_id],
23
+ [:instance_variables, obj.instance_variables]]
24
+
25
+ h = Hash[*a.flatten(1)]
26
+ File.open("class_#{h[:class]}.xml",'w'){|f| f.write store(a)}
27
+
28
+ obj.instance_eval(){
29
+
30
+ def x_inspect(x)
31
+ if x.respond_to? :to_s
32
+ (x.inspect.length < 150 ? x.inspect : x.inspect[0..145] + '...')
33
+ else
34
+ " "
35
+ end
36
+ end
37
+
38
+ def log_method(a=[], vars=[], args=[])
39
+ label_vars = vars.map{|x| "%s: %s" % [x,x_inspect(self.instance_variable_get(x))]}
40
+ line = "in, %s, " % (a + label_vars).flatten.join(', ')
41
+ basic_args = args.map do |x|
42
+ x.class.to_s[/Float|Fixnum|String|Array/] ? ("%s: %s" % [x.class, x_inspect(x)]) : nil
43
+ end
44
+ basic_args.compact!
45
+ $carbolic_log.debug line << basic_args.join(', ')
46
+ r = yield
47
+ label_vars = vars.map{|x| "%s: %s, " % [x,x_inspect(self.instance_variable_get(x))]}
48
+ line = "out, %s, " % ([a.first] + label_vars).flatten.join(', ')
49
+ line << "%s: %s" % [r.class, x_inspect(r)] if r.class.to_s[/Float|Fixnum|String|Array/]
50
+ $carbolic_log.debug line
51
+ r
52
+ end
53
+ }
54
+
55
+ methodx = []
56
+ method_names = %w(public_methods private_methods protected_methods singleton_methods)
57
+ methodx << method_names.map do |method_name|
58
+ h[method_name.to_sym].map do |x|
59
+ %Q(alias basic_#{x} #{x}
60
+ def #{x}(*args, &block)
61
+ a = caller(0)[0..1].map {|x| x[/[a-zA-Z\?\_\!0-9\+\-\=\*\\/]+(?=.$)/]}
62
+ vars = self.instance_variables
63
+ log_method(a,vars,args){basic_#{x}(*args,&block)}
64
+ end)
65
+ end
66
+ end
67
+ obj.instance_eval(methodx.join("\n"))
68
+
69
+ end
70
+
71
+ def store(a)
72
+
73
+ a.map!{|label, value| [label, value.is_a?(Array) ? value.sort.join(', ') : value.to_s]}
74
+
75
+ xml = Builder::XmlMarkup.new( :target => buffer='', :indent => 2 )
76
+ xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
77
+
78
+ xml.class_info do
79
+ xml.summary do
80
+ a.each {|label, val| xml.send(label.to_s + 'x', val) }
81
+ end
82
+ xml.records
83
+ end
84
+
85
+ buffer.gsub('x>','>')
86
+ end
87
+
88
+ end
89
+
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carbolic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors: []
7
+
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-06-19 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email:
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/carbolic.rb
26
+ has_rdoc: true
27
+ homepage:
28
+ licenses: []
29
+
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.3.5
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: carbolic
54
+ test_files: []
55
+