Class: Rack::Sparklines::Cachers::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-sparklines/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.



11
12
13
# File 'lib/rack-sparklines/cachers/abstract.rb', line 11

def initialize
  @size, @updated_at = nil
end

Instance Attribute Details

#png_pathObject

Returns the value of attribute png_path.



9
10
11
# File 'lib/rack-sparklines/cachers/abstract.rb', line 9

def png_path
  @png_path
end

Instance Method Details

#create_sparklines(data, options) ⇒ Object



35
36
37
# File 'lib/rack-sparklines/cachers/abstract.rb', line 35

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

#exists?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/rack-sparklines/cachers/abstract.rb', line 27

def exists?
  raise NotImplementedError
end

#save(data, options) ⇒ Object

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/rack-sparklines/cachers/abstract.rb', line 48

def save(data, options)
  raise NotImplementedError
end

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



39
40
41
42
43
44
45
46
# File 'lib/rack-sparklines/cachers/abstract.rb', line 39

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).



17
18
19
20
21
# File 'lib/rack-sparklines/cachers/abstract.rb', line 17

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

#sizeObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/rack-sparklines/cachers/abstract.rb', line 23

def size
  raise NotImplementedError
end

#streamObject

Raises:

  • (NotImplementedError)


52
53
54
# File 'lib/rack-sparklines/cachers/abstract.rb', line 52

def stream
  raise NotImplementedError
end

#updated_atObject

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/rack-sparklines/cachers/abstract.rb', line 31

def updated_at
  raise NotImplementedError
end