Class: Gumdrop::DataManager
- Inherits:
-
Object
- Object
- Gumdrop::DataManager
show all
- Defined in:
- lib/gumdrop/data_manager.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(site, data_dir = "./data") ⇒ DataManager
Returns a new instance of DataManager.
12
13
14
15
16
|
# File 'lib/gumdrop/data_manager.rb', line 12
def initialize(site, data_dir="./data")
@site= site
@dir= File.expand_path data_dir
@cache= {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, value = nil) ⇒ Object
18
19
20
21
|
# File 'lib/gumdrop/data_manager.rb', line 18
def method_missing(key, value=nil)
cache_dataset(key)
@cache[key]
end
|
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
10
11
12
|
# File 'lib/gumdrop/data_manager.rb', line 10
def cache
@cache
end
|
Instance Method Details
#load_from_file(filename) ⇒ Object
Exposing these publicly because, well, they’re useful:
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/gumdrop/data_manager.rb', line 48
def load_from_file( filename )
ext=File.extname(filename)
if ext == '.yamldoc' or ext == '.ymldoc'
load_from_yamldoc filename
elsif ext == '.yamldb' or ext == '.ymldb'
load_from_yamldb filename
elsif ext == '.yaml' or ext == '.yml' or ext == '.json'
hashes2ostruct( YAML.load_file(filename) )
else
Gumdrop.report "Unknown data type (#{ext}) for #{filename}", :warning
nil
end
end
|
#load_yamldoc(filename, source = nil) ⇒ Object
62
63
64
|
# File 'lib/gumdrop/data_manager.rb', line 62
def load_yamldoc(filename, source=nil)
load_from_yamldoc filename, source
end
|
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/gumdrop/data_manager.rb', line 35
def (key, opts={})
base_path= opts.fetch(:base_path, 'page')
page_size= opts.fetch(:page_size, 5)
data= if key.is_a? Symbol
cache_dataset(key)
@cache[key]
else
key
end
Pager.new( data, base_path, page_size )
end
|
#reset ⇒ Object
27
28
29
|
# File 'lib/gumdrop/data_manager.rb', line 27
def reset
@cache={}
end
|
#set(key, value) ⇒ Object
23
24
25
|
# File 'lib/gumdrop/data_manager.rb', line 23
def set(key, value)
@cache[key]= value
end
|
#site(pattern = nil, opts = {}) ⇒ Object
31
32
33
|
# File 'lib/gumdrop/data_manager.rb', line 31
def site(pattern=nil, opts={})
@site.contents(pattern, opts)
end
|