Class: Sparkplug::Cachers::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/sparkplug/cachers/abstract.rb

Overview

Reads sparkline data from CSV files. Only the first line of numbers are read. Requests for “/sparks/stats.csv” will pass a data_path of “stats.csv”

Direct Known Subclasses

Filesystem, Memory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAbstract

Returns a new instance of Abstract.



10
11
12
# File 'lib/sparkplug/cachers/abstract.rb', line 10

def initialize
  @size, @updated_at = nil
end

Instance Attribute Details

#png_pathObject

Returns the value of attribute png_path.



8
9
10
# File 'lib/sparkplug/cachers/abstract.rb', line 8

def png_path
  @png_path
end

Instance Method Details

#create_sparklines(data, options) ⇒ Object



34
35
36
# File 'lib/sparkplug/cachers/abstract.rb', line 34

def create_sparklines(data, options)
  Spark.plot(data, options)
end

#exists?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/sparkplug/cachers/abstract.rb', line 26

def exists?
  raise NotImplementedError
end

#save(data, options) ⇒ Object

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/sparkplug/cachers/abstract.rb', line 47

def save(data, options)
  raise NotImplementedError
end

#serve(app, headers = {}) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/sparkplug/cachers/abstract.rb', line 38

def serve(app, headers = {})
  headers = {
    "Last-Modified"  => updated_at.rfc822,
    "Content-Type"   => "image/png",
    "Content-Length" => size.to_s
  }.update(headers)
  [200, headers, app]
end

#set(png_path) ⇒ Object

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



16
17
18
19
20
# File 'lib/sparkplug/cachers/abstract.rb', line 16

def set(png_path)
  cacher = dup
  cacher.png_path = png_path
  cacher
end

#sizeObject

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/sparkplug/cachers/abstract.rb', line 22

def size
  raise NotImplementedError
end

#streamObject

Raises:

  • (NotImplementedError)


51
52
53
# File 'lib/sparkplug/cachers/abstract.rb', line 51

def stream
  raise NotImplementedError
end

#updated_atObject

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/sparkplug/cachers/abstract.rb', line 30

def updated_at
  raise NotImplementedError
end