Class: Heathrow::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/heathrow/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Source

Returns a new instance of Source.



6
7
8
9
10
11
12
13
14
# File 'lib/heathrow/source.rb', line 6

def initialize(attrs = {})
  @id = attrs[:id] || generate_id
  @type = attrs[:type]
  @name = attrs[:name]
  @config = attrs[:config] || {}
  @enabled = attrs[:enabled] != false
  @poll_interval = attrs[:poll_interval] || 60
  @last_poll = attrs[:last_poll]
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/heathrow/source.rb', line 4

def config
  @config
end

#enabledObject

Returns the value of attribute enabled.



4
5
6
# File 'lib/heathrow/source.rb', line 4

def enabled
  @enabled
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/heathrow/source.rb', line 4

def id
  @id
end

#last_pollObject

Returns the value of attribute last_poll.



4
5
6
# File 'lib/heathrow/source.rb', line 4

def last_poll
  @last_poll
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/heathrow/source.rb', line 4

def name
  @name
end

#poll_intervalObject

Returns the value of attribute poll_interval.



4
5
6
# File 'lib/heathrow/source.rb', line 4

def poll_interval
  @poll_interval
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/heathrow/source.rb', line 4

def type
  @type
end

Instance Method Details

#generate_idObject



16
17
18
# File 'lib/heathrow/source.rb', line 16

def generate_id
  "#{@type}_#{Time.now.to_i}_#{rand(1000)}"
end

#should_poll?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
# File 'lib/heathrow/source.rb', line 32

def should_poll?
  return false unless @enabled
  return true if @last_poll.nil?
  
  Time.now - Time.parse(@last_poll) >= @poll_interval
end

#to_hObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/heathrow/source.rb', line 20

def to_h
  {
    id: @id,
    type: @type,
    name: @name,
    config: @config.to_json,
    enabled: @enabled ? 1 : 0,
    poll_interval: @poll_interval,
    last_poll: @last_poll
  }
end