Class: Livestatus::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/livestatus/models.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data) ⇒ Base
Returns a new instance of Base.
10
11
12
|
# File 'lib/livestatus/models.rb', line 10
def initialize(data)
@data = data.symbolize_keys!
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
14
15
16
|
# File 'lib/livestatus/models.rb', line 14
def method_missing(name, *args)
data[name.to_sym]
end
|
Instance Attribute Details
#data ⇒ Object
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
29
30
31
32
33
34
35
|
# File 'lib/livestatus/models.rb', line 29
def boolean_attributes(*accessors)
accessors.each do |m|
define_method(m) do
data[m] == 1
end
end
end
|
.find(options = {}) ⇒ Object
19
20
21
22
23
|
# File 'lib/livestatus/models.rb', line 19
def find(options = {})
Livestatus.get(table_name, options).map do |data|
new(data)
end
end
|
.table_name ⇒ Object
25
26
27
|
# File 'lib/livestatus/models.rb', line 25
def table_name
to_s.demodulize.tableize.downcase.pluralize
end
|
.time_attributes(*accessors) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/livestatus/models.rb', line 37
def time_attributes(*accessors)
accessors.each do |m|
define_method(m) do
Time.at(data[m].to_i)
end
end
end
|