Class: Livestatus::Base
- Inherits:
-
Object
- Object
- Livestatus::Base
- Defined in:
- lib/livestatus/models.rb
Direct Known Subclasses
Command, Comment, Contact, Contactgroup, Downtime, Host, Hostgroup, Service, Servicegroup, Timeperiod
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data, connection = nil) ⇒ Base
constructor
A new instance of Base.
- #method_missing(name, *args) ⇒ Object
Constructor Details
#initialize(data, connection = nil) ⇒ Base
Returns a new instance of Base.
10 11 12 13 |
# File 'lib/livestatus/models.rb', line 10 def initialize(data, connection = nil) @data = data.symbolize_keys! @connection = connection end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
15 16 17 |
# File 'lib/livestatus/models.rb', line 15 def method_missing(name, *args) data[name.to_sym] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/livestatus/models.rb', line 8 def data @data end |
Class Method Details
.boolean_attributes(*accessors) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/livestatus/models.rb', line 24 def boolean_attributes(*accessors) accessors.each do |m| define_method(m) do data[m] == 1 end end end |
.table_name ⇒ Object
20 21 22 |
# File 'lib/livestatus/models.rb', line 20 def table_name to_s.demodulize.tableize.downcase.pluralize end |
.time_attributes(*accessors) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/livestatus/models.rb', line 32 def time_attributes(*accessors) accessors.each do |m| define_method(m) do Time.at(data[m].to_i) end end end |