Class: Sparkplug::Handlers::AbstractData

Inherits:
Object
  • Object
show all
Defined in:
lib/sparkplug/handlers/abstract_data.rb

Overview

Abstract class for retrieving the data and determining whether the cache needs to be refreshed.

Direct Known Subclasses

CsvData, StubbedData

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#data_pathObject

Returns the value of attribute data_path.



6
7
8
# File 'lib/sparkplug/handlers/abstract_data.rb', line 6

def data_path
  @data_path
end

Instance Method Details

#already_cached?(cacher) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/sparkplug/handlers/abstract_data.rb', line 16

def already_cached?(cacher)
  if cache_time = cacher.exists? && cacher.updated_at
    cache_time > updated_at
  end
end

#exists?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/sparkplug/handlers/abstract_data.rb', line 22

def exists?
  false
end

#fetchObject

Yield an array of numbers for sparkline datapoints.

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/sparkplug/handlers/abstract_data.rb', line 31

def fetch
  raise NotImplementedError
end

#set(data_path) ⇒ Object

Setting the data_path returns a duplicate of this object that has any custom instance variables (configuration settings, for example).



10
11
12
13
14
# File 'lib/sparkplug/handlers/abstract_data.rb', line 10

def set(data_path)
  data = dup
  data.data_path = data_path
  data
end

#updated_atObject

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/sparkplug/handlers/abstract_data.rb', line 26

def updated_at
  raise NotImplementedError
end