Class: Hostmon::Models::Base
- Inherits:
-
Object
- Object
- Hostmon::Models::Base
- Defined in:
- lib/hostmon/models/base.rb
Overview
fixme define [] for find
Constant Summary collapse
- @@objects =
Hash.new { |h, k| h[k] = Hash.new }
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #[](key) ⇒ Object
-
#initialize(name, params = {}) ⇒ Base
constructor
A new instance of Base.
- #to_s ⇒ Object
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
#name ⇒ Object (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
.all ⇒ Object
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_s ⇒ Object
30 31 32 |
# File 'lib/hostmon/models/base.rb', line 30 def to_s return @name end |