Skip to content
Newer
Older
100644 53 lines (41 sloc) 1023 Bytes
e9c1c0a @michaelfeathers initial commit
authored May 14, 2011
1
2 class CodeEvent
3
4 def initialize(hash = {})
5 hash.each_pair do |attr,value|
6 define_attribute(attr)
7 self.send(writer_for(attr), value)
8 end
9 end
10
255e1a1 @michaelfeathers general refactoring and addition of methods collection to rrepository.
authored May 15, 2011
11 # Considering moving this to code that populates
12 # events so that this class isn't making assumptions
13 # about what it will be populated with
14 def full_method_name
15 class_name + "#" + method_name
e9c1c0a @michaelfeathers initial commit
authored May 14, 2011
16 end
17
6d39918 @michaelfeathers added to_s to prevent recursive object references in the default from…
authored Jul 1, 2011
18 def to_s
19 date.to_s + " " + class_name + "#" + method_name + ": " + complexity.to_s
20 end
21
e9c1c0a @michaelfeathers initial commit
authored May 14, 2011
22 private
23 def define_attribute(attr)
24 singleton_class.send(:public)
25 singleton_class.send(:attr_accessor, attr)
26 end
27
28 def singleton_class
29 class << self; self; end
30 end
31
32 def reader_for(sym)
33 sym.to_s.end_with?('=') ? sym.to_s.chop.to_sym : sym
34 end
35
36 def writer_for(sym)
37 (sym.to_s + "=").to_sym
38 end
39
40 def method_missing(sym, *args, &block)
41 if sym.to_s.end_with?('=')
42 define_attribute(reader_for(sym))
43 self.send(sym,*args)
44 elsif args.count == 0
b9b9545 @michaelfeathers introduced assert_date_sorted and altered affected tests.
authored May 19, 2011
45 return nil
e9c1c0a @michaelfeathers initial commit
authored May 14, 2011
46 else
47 super
48 end
49 end
50
51 end
52
Something went wrong with that request. Please try again.