Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/noah/hosts.rb | 54 | 46 | 75.93%
|
71.74%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 class Host < Ohm::Model |
2 include Ohm::Typecast |
3 include Ohm::Timestamping |
4 include Ohm::Callbacks |
5 include Ohm::ExtraValidations |
6 |
7 attribute :name |
8 attribute :status |
9 collection :services, Service |
10 |
11 index :name |
12 index :status |
13 |
14 def validate |
15 assert_present :name |
16 assert_present :status |
17 assert_unique :name |
18 assert_member :status, ["up","down","pending"] |
19 end |
20 |
21 def to_hash |
22 arr = [] |
23 services.sort.each {|s| arr << s.to_hash} |
24 h = {:name => name, :status => status, :created_at => created_at, :updated_at => updated_at, :services => arr} |
25 super.merge(h) |
26 end |
27 |
28 def is_new? |
29 self.created_at == self.updated_at |
30 end |
31 |
32 class << self |
33 def find_or_create(opts = {}) |
34 begin |
35 # exclude requested status from lookup |
36 h = find(opts.reject{|key,value| key == :status}).first |
37 host = h.nil? ? create(opts) : h |
38 host.status = opts[:status] |
39 if host.valid? |
40 host.save |
41 end |
42 host |
43 rescue Exception => e |
44 e.message |
45 end |
46 end |
47 end |
48 end |
49 |
50 class Hosts |
51 def self.all(options = {}) |
52 options.empty? ? Host.all.sort : Host.find(options).sort |
53 end |
54 end |
Generated on 2011-02-08 01:54:21 -0500 with rcov 0.9.8