Class: Hostmon::Models::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hostmon/models/base.rb

Overview

fixme define [] for find

Direct Known Subclasses

Check, Host, Report

Constant Summary collapse

@@objects =
Hash.new { |h, k| h[k] = Hash.new }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, params = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/hostmon/models/base.rb', line 7

def initialize(name, params={})
  @name = name
  @params = params
  @@objects[self.class.to_s][name] = self
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/hostmon/models/base.rb', line 5

def name
  @name
end

Class Method Details

.allObject



22
23
24
# File 'lib/hostmon/models/base.rb', line 22

def self.all
  return @@objects[self.name].values.sort
end

.each(&block) ⇒ Object



17
18
19
20
# File 'lib/hostmon/models/base.rb', line 17

def self.each(&block)
  h = @@objects[self.name] rescue {}
  h.sort.each { |k, v| yield(k, v) }
end

.find(name) ⇒ Object



13
14
15
# File 'lib/hostmon/models/base.rb', line 13

def self.find(name)
  return @@objects[self.name][name] rescue []
end

Instance Method Details

#<=>(other) ⇒ Object



34
35
36
# File 'lib/hostmon/models/base.rb', line 34

def <=>(other)
  return to_s <=> other.to_s
end

#[](key) ⇒ Object



26
27
28
# File 'lib/hostmon/models/base.rb', line 26

def [](key)
  return @params[key] rescue []
end

#to_sObject



30
31
32
# File 'lib/hostmon/models/base.rb', line 30

def to_s
  return @name
end