Class: Sparkplug::Handlers::StubbedData
- Inherits:
-
AbstractData
- Object
- AbstractData
- Sparkplug::Handlers::StubbedData
- Defined in:
- lib/sparkplug/handlers/stubbed_data.rb
Overview
Allows you to stub sparkline data in a global hash. Requests for “/sparks/stats.csv” will pass a data_path of “stats.csv”
Instance Attribute Summary collapse
-
#datasets ⇒ Object
A hash of hashes where the key is the filename.
Attributes inherited from AbstractData
Instance Method Summary collapse
- #data_path=(s) ⇒ Object
- #exists? ⇒ Boolean
- #fetch {|@data[:contents]| ... } ⇒ Object
-
#initialize(datasets = {}) ⇒ StubbedData
constructor
A new instance of StubbedData.
- #updated_at ⇒ Object
Methods inherited from AbstractData
Constructor Details
#initialize(datasets = {}) ⇒ StubbedData
Returns a new instance of StubbedData.
13 14 15 |
# File 'lib/sparkplug/handlers/stubbed_data.rb', line 13 def initialize(datasets = {}) @datasets = datasets end |
Instance Attribute Details
#datasets ⇒ Object
A hash of hashes where the key is the filename. The key points to a hash with :updated and :contents keys
StubbedData.datasets['stats.csv'] = {
:updated => Time.utc(2009, 10, 1),
:contents => [1, 2, 3, 4, 5]}
11 12 13 |
# File 'lib/sparkplug/handlers/stubbed_data.rb', line 11 def datasets @datasets end |
Instance Method Details
#data_path=(s) ⇒ Object
17 18 19 20 |
# File 'lib/sparkplug/handlers/stubbed_data.rb', line 17 def data_path=(s) @data = @datasets[s] @data_path = s end |
#exists? ⇒ Boolean
22 23 24 |
# File 'lib/sparkplug/handlers/stubbed_data.rb', line 22 def exists? @data end |
#fetch {|@data[:contents]| ... } ⇒ Object
30 31 32 |
# File 'lib/sparkplug/handlers/stubbed_data.rb', line 30 def fetch yield @data[:contents] if @data end |
#updated_at ⇒ Object
26 27 28 |
# File 'lib/sparkplug/handlers/stubbed_data.rb', line 26 def updated_at @data[:updated] end |