Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/noah/services.rb | 57 | 48 | 73.68%
|
70.83%
|
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 Service < 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 reference :host, Host |
10 |
11 index :name |
12 index :status |
13 |
14 def validate |
15 assert_present :name |
16 assert_present :status |
17 assert_present :host_id |
18 assert_unique [:name, :host_id] |
19 assert_member :status, ["up", "down", "pending"] |
20 end |
21 |
22 def to_hash |
23 super.merge(:name => name, :status => status, :updated_at => updated_at, :host => Host[host_id].name) |
24 end |
25 |
26 def is_new? |
27 self.created_at == self.updated_at |
28 end |
29 |
30 class << self |
31 def find_or_create(opts = {}) |
32 begin |
33 # convert passed host object to host_id if passed |
34 if opts.has_key?(:host) |
35 opts.merge!({:host_id => opts[:host].id}) |
36 opts.reject!{|key, value| key == :host} |
37 end |
38 # exclude requested status from lookup |
39 s = find(opts.reject{|key,value| key == :status}).first |
40 service = s.nil? ? create(opts) : s |
41 service.status = opts[:status] |
42 if service.valid? |
43 service.save |
44 end |
45 service |
46 rescue Exception => e |
47 e.message |
48 end |
49 end |
50 end |
51 end |
52 |
53 class Services |
54 def self.all(options = {}) |
55 options.empty? ? Service.all.sort : Service.find(options).sort |
56 end |
57 end |
Generated on 2011-02-08 01:54:20 -0500 with rcov 0.9.8