Class: Service
- Inherits:
-
Ohm::Model
- Object
- Ohm::Model
- Service
- Includes:
- Ohm::Callbacks, Ohm::ExtraValidations, Ohm::Timestamping, Ohm::Typecast
- Defined in:
- lib/noah/services.rb
Class Method Summary (collapse)
Instance Method Summary (collapse)
Class Method Details
+ (Object) find_or_create(opts = {})
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/noah/services.rb', line 39 def find_or_create(opts = {}) begin # convert passed host object to host_id if passed if opts.has_key?(:host) opts.merge!({:host_id => opts[:host].id}) opts.reject!{|key, value| key == :host} end # exclude requested status from lookup s = find(opts.reject{|key,value| key == :status}).first service = s.nil? ? create(opts) : s service.status = opts[:status] if service.valid? service.save end service rescue Exception => e e. end end |
Instance Method Details
- (Boolean) is_new?
34 35 36 |
# File 'lib/noah/services.rb', line 34 def is_new? self.created_at == self.updated_at end |
- (Object) stash_name (protected)
61 62 63 |
# File 'lib/noah/services.rb', line 61 def stash_name @deleted_name = self.name end |
- (Object) to_hash
29 30 31 32 |
# File 'lib/noah/services.rb', line 29 def to_hash Host[host_id].nil? ? host_name=nil : host_name=Host[host_id].name super.merge(:name => name, :status => status, :updated_at => updated_at, :host => host_name) end |
- (Object) validate
20 21 22 23 24 25 26 27 |
# File 'lib/noah/services.rb', line 20 def validate super assert_present :name assert_present :status assert_present :host_id assert_unique [:name, :host_id] assert_member :status, ["up", "down", "pending"] end |