Class: Gumdrop::DataManager
Instance Attribute Summary collapse
Instance Method Summary
collapse
#parent, #site
#log
#clear_events, #event_block, #fire
Constructor Details
#initialize(data_dir = "./data") ⇒ DataManager
Returns a new instance of DataManager.
10
11
12
13
14
|
# File 'lib/gumdrop/data.rb', line 10
def initialize(data_dir="./data")
@dir= File.expand_path data_dir
@cache= Hash.new &method(:_cache_dataset)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, value = nil) ⇒ Object
20
21
22
|
# File 'lib/gumdrop/data.rb', line 20
def method_missing(key, value=nil)
@cache[key]
end
|
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
8
9
10
|
# File 'lib/gumdrop/data.rb', line 8
def cache
@cache
end
|
Instance Method Details
#contents(pattern = nil, opts = {}) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/gumdrop/data.rb', line 32
def contents(pattern=nil, opts={})
if pattern.nil?
site.contents.all
else
site.contents(pattern, opts)
end
end
|
#dir=(path) ⇒ Object
16
17
18
|
# File 'lib/gumdrop/data.rb', line 16
def dir=(path)
@dir= File.expand_path path
end
|
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/gumdrop/data.rb', line 40
def (key, opts={})
data= case key
when Symbol
@cache[key]
when Array
key
else
raise "pager_for requires a lookup symbol or array data."
end
base_path= opts.fetch(:base_path, 'page')
page_size= opts.fetch(:page_size, 5)
Util::Pager.new( data, base_path, page_size )
end
|
#reset ⇒ Object
28
29
30
|
# File 'lib/gumdrop/data.rb', line 28
def reset
@cache.clear
end
|
#set(key, value) ⇒ Object
24
25
26
|
# File 'lib/gumdrop/data.rb', line 24
def set(key, value)
@cache[key]= value
end
|