forked from michaelfeathers/repodepot-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_event.rb
52 lines (41 loc) · 1023 Bytes
/
code_event.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class CodeEvent
def initialize(hash = {})
hash.each_pair do |attr,value|
define_attribute(attr)
self.send(writer_for(attr), value)
end
end
# Considering moving this to code that populates
# events so that this class isn't making assumptions
# about what it will be populated with
def full_method_name
class_name + "#" + method_name
end
def to_s
date.to_s + " " + class_name + "#" + method_name + ": " + complexity.to_s
end
private
def define_attribute(attr)
singleton_class.send(:public)
singleton_class.send(:attr_accessor, attr)
end
def singleton_class
class << self; self; end
end
def reader_for(sym)
sym.to_s.end_with?('=') ? sym.to_s.chop.to_sym : sym
end
def writer_for(sym)
(sym.to_s + "=").to_sym
end
def method_missing(sym, *args, &block)
if sym.to_s.end_with?('=')
define_attribute(reader_for(sym))
self.send(sym,*args)
elsif args.count == 0
return nil
else
super
end
end
end