Class: Livestatus::Base

Inherits:
Object
  • 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, 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

#dataObject (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_nameObject



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