Class: PRRD::Database::Datasource

Inherits:
Entity
  • Object
show all
Defined in:
lib/prrd/database/datasource.rb

Overview

PRRD Database Datasource class

Instance Attribute Summary

Attributes inherited from Entity

#data, #keys

Instance Method Summary collapse

Methods inherited from Entity

#method_missing, #validate_presence

Constructor Details

#initialize(values = nil) ⇒ Datasource

Constructor



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/prrd/database/datasource.rb', line 11

def initialize(values = nil)
  @keys = [
    :name,
    :type,
    :heartbeat,
    :min,
    :max
  ]

  super values
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PRRD::Entity

Instance Method Details

#to_sObject

Transform to a DS formatted string



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/prrd/database/datasource.rb', line 24

def to_s
  fail 'Empty datasource object' if @data.empty?

  validate_presence :name, :type, :heartbeat, :min, :max

  chunks = ['DS']

  @keys.each do |k|
    next unless @data.key?(k)
    chunks << @data[k]
  end

  chunks.join ':'
end