Noah C0 Coverage Information - RCov

lib/models.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/models.rb 231 191
90.91%
89.01%

Key

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.

Coverage Details

1 require 'ohm/contrib'
2 
3 class Host < Ohm::Model
4   include Ohm::Typecast
5   include Ohm::Timestamping
6   include Ohm::Callbacks
7   include Ohm::ExtraValidations
8 
9   attribute :name
10   attribute :status
11   collection :services, Service
12 
13   index :name
14   index :status
15 
16   def validate
17     assert_present :name
18     assert_present :status
19     assert_unique :name
20     assert_member :status, ["up","down","pending"]
21   end
22 
23   def to_hash
24     arr = []
25     services.sort.each {|s| arr << s.to_hash}
26     h = {:name => name, :status => status, :created_at => created_at, :updated_at => updated_at, :services => arr}
27     super.merge(h)
28   end
29 
30   def is_new?
31     self.created_at == self.updated_at
32   end
33 
34   class << self
35   def find_or_create(opts = {})
36     begin
37       # exclude requested status from lookup
38       h = find(opts.reject{|key,value| key == :status}).first
39       host = h.nil? ? create(opts) : h
40       host.status = opts[:status]
41       if host.valid?
42         host.save
43       end
44       host
45     rescue Exception => e
46       e.message
47     end
48   end
49   end
50 end
51 
52 class Service < Ohm::Model
53   include Ohm::Typecast
54   include Ohm::Timestamping
55   include Ohm::Callbacks
56   include Ohm::ExtraValidations
57 
58   attribute :name
59   attribute :status
60   reference :host, Host
61 
62   index :name
63   index :status
64 
65   def validate
66     assert_present :name
67     assert_present :status
68     assert_present :host_id
69     assert_unique [:name, :host_id]
70     assert_member :status, ["up", "down", "pending"]
71   end
72 
73   def to_hash
74     super.merge(:name => name, :status => status, :updated_at => updated_at, :host => Host[host_id].name)
75   end
76 
77   def is_new?
78     self.created_at == self.updated_at
79   end
80 
81   class << self
82   def find_or_create(opts = {})
83     begin
84       # convert passed host object to host_id if passed
85       if opts.has_key?(:host)
86         opts.merge!({:host_id => opts[:host].id})
87         opts.reject!{|key, value| key == :host}
88       end  
89       # exclude requested status from lookup
90       s = find(opts.reject{|key,value| key == :status}).first
91       service = s.nil? ? create(opts) : s
92       service.status = opts[:status]
93       if service.valid?
94         service.save
95       end
96       service
97     rescue Exception => e
98       e.message
99     end
100   end
101   end
102 end
103 
104 class Configuration < Ohm::Model
105   include Ohm::Typecast
106   include Ohm::Timestamping
107   include Ohm::Callbacks
108   include Ohm::ExtraValidations
109 
110   attribute :name
111   attribute :format
112   attribute :body
113   attribute :new_record
114   reference :application, Application
115 
116   index :name
117 
118   def validate
119     assert_present :name
120     assert_present :format
121     assert_present :body
122     assert_unique [:name, :application_id]
123   end
124 
125   def to_hash
126     super.merge(:name => name, :format => format, :body => body, :update_at => updated_at, :application => Application[application_id].name)
127   end
128 
129   def is_new?
130     self.created_at == self.updated_at
131   end
132 
133   class << self
134   def find_or_create(opts={})
135     begin
136       if find(opts).first.nil?
137         conf = create(opts)
138       else  
139         conf = find(opts).first
140       end  
141     rescue Exception => e
142       e.message
143     end
144   end
145   end
146 end
147 
148 class Application < Ohm::Model
149   include Ohm::Typecast
150   include Ohm::Timestamping
151   include Ohm::Callbacks
152   include Ohm::ExtraValidations
153 
154   attribute :name
155   collection :configurations, Configuration
156 
157   index :name
158 
159   def validate
160     assert_present :name
161     assert_unique :name
162   end
163 
164   def to_hash
165     arr = []
166     configurations.sort.each {|c| arr << c.to_hash}
167     super.merge(:name => name, :updated_at => updated_at, :configurations => arr)
168   end
169 
170   def is_new?
171     self.created_at == self.updated_at
172   end
173 
174   class << self
175   def find_or_create(opts = {})
176     begin
177       find(opts).first.nil? ? (app = create(opts)) : (app = find(opts).first)
178       if app.valid?
179         app.save
180       end
181       app
182     rescue Exception => e
183       e.message
184     end
185   end
186   end
187 end
188 
189 class Watcher < Ohm::Model #NYI
190   include Ohm::Typecast
191   include Ohm::Timestamping
192   include Ohm::Callbacks
193 
194   attribute :client
195   attribute :endpoint
196   attribute :event
197   attribute :action 
198 
199   index :client
200   index :event
201 
202   def validate
203     assert_present :client, :endpoint, :event, :action
204     assert_unique [:client, :endpoint, :event, :action]
205   end
206 end
207 
208 # Some pluralized helper models
209 class Hosts
210   def self.all(options = {})
211     options.empty? ? Host.all.sort : Host.find(options).sort
212   end
213 end
214 
215 class Services
216   def self.all(options = {})
217     options.empty? ? Service.all.sort : Service.find(options).sort
218   end
219 end
220 
221 class Applications
222   def self.all(options = {})
223     options.empty? ? Application.all.sort : Application.find(options).sort
224   end
225 end
226 
227 class Configurations
228   def self.all(options = {})
229     options.empty? ? Configuration.all.sort : Configuration.find(options).sort
230   end
231 end  

Generated on 2011-01-31 05:03:32 -0500 with rcov 0.9.8