sadie 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sadie/version.rb +1 -1
- data/lib/sadie.rb +43 -7
- metadata +3 -3
data/lib/sadie/version.rb
CHANGED
data/lib/sadie.rb
CHANGED
@@ -6,7 +6,7 @@ Bundler.require(:default)
|
|
6
6
|
#require 'ini'
|
7
7
|
|
8
8
|
|
9
|
-
# ==Description
|
9
|
+
# ==Description: Sadie
|
10
10
|
# Sadie is a data framework intended to ease the pain of constructing, accessing, and
|
11
11
|
# managing the resources required by large stores of inter-related data. It supports
|
12
12
|
# sessions, lazy on-demand, one-time evaluation and file-based storage/retrieval
|
@@ -19,15 +19,19 @@ Bundler.require(:default)
|
|
19
19
|
|
20
20
|
class Sadie
|
21
21
|
|
22
|
-
|
22
|
+
|
23
|
+
# ==method: constructor
|
23
24
|
# options can include any kay, value pairs but the following key values bear mention:
|
24
25
|
# REQUIRED
|
26
|
+
#
|
25
27
|
# sadie.sessions_dirpath
|
26
28
|
# or
|
27
29
|
# sadie.session_id
|
28
30
|
# or
|
29
31
|
# sadie.session_filepath <- this is probably a bad call, use with caution
|
30
32
|
#
|
33
|
+
# and
|
34
|
+
#
|
31
35
|
# sadie.primers_dirpath
|
32
36
|
def initialize( options )
|
33
37
|
|
@@ -73,10 +77,21 @@ class Sadie
|
|
73
77
|
|
74
78
|
end
|
75
79
|
|
80
|
+
# ==method: Sadie::getSadieInstance
|
81
|
+
#
|
82
|
+
# returns a new Sadie instance. Options match those of Sadie's constructor method
|
76
83
|
def self.getSadieInstance( options )
|
77
84
|
Sadie.new(options)
|
78
85
|
end
|
79
86
|
|
87
|
+
# ==method: Sadie::Prime
|
88
|
+
#
|
89
|
+
# called my the .res files to register the keys the .res will prime for
|
90
|
+
#
|
91
|
+
# accepts as an argument a hash and a block. The hash must include the key:
|
92
|
+
# 'provides' and it must define an array
|
93
|
+
# of keys that the calling resource (.res) file will have provided after the block is
|
94
|
+
# evaluated
|
80
95
|
def self.Prime ( primer_definition )
|
81
96
|
|
82
97
|
# validate params
|
@@ -103,7 +118,11 @@ class Sadie
|
|
103
118
|
end
|
104
119
|
end
|
105
120
|
end
|
106
|
-
|
121
|
+
|
122
|
+
# ==method: get
|
123
|
+
#
|
124
|
+
# a standard getter which primes the unprimed and recalls "expensive" facts from files
|
125
|
+
# completely behind-the-scenes as directed by the resource (.res) files
|
107
126
|
def get( k )
|
108
127
|
|
109
128
|
# prime if not yet primed
|
@@ -118,6 +137,10 @@ class Sadie
|
|
118
137
|
return _recallExpensive( k )
|
119
138
|
end
|
120
139
|
|
140
|
+
# ==method: setCheap
|
141
|
+
#
|
142
|
+
# the expensive setter. key, value pairs stored via this method are not kept in memory
|
143
|
+
# but are stored to file and recalled as needed
|
121
144
|
def setExpensive(k,v)
|
122
145
|
expensive_filepath = _computeExpensiveFilepath( k )
|
123
146
|
serialized_value = Marshal::dump( v )
|
@@ -128,11 +151,15 @@ class Sadie
|
|
128
151
|
_primed( k, true )
|
129
152
|
end
|
130
153
|
|
154
|
+
# ==method: set
|
131
155
|
# alias for setCheap(k,v)
|
132
156
|
def set( k, v )
|
133
157
|
setCheap( k, v )
|
134
158
|
end
|
135
159
|
|
160
|
+
# ==method: setCheap
|
161
|
+
#
|
162
|
+
# the cheap setter. key, value pairs stored via this method are kept in memory
|
136
163
|
def setCheap(k,v)
|
137
164
|
|
138
165
|
# set it, mark not expensive and primed
|
@@ -149,6 +176,9 @@ class Sadie
|
|
149
176
|
|
150
177
|
end
|
151
178
|
|
179
|
+
# ==method: save
|
180
|
+
#
|
181
|
+
# serialize to session file
|
152
182
|
def save
|
153
183
|
session_filepath = File.expand_path( "session."+value, get( "sadie.sessions_dirpath" ) )
|
154
184
|
serialized_value = Marshal::dump( [ @shortterm, @flag_primed, @flag_expensive ] )
|
@@ -157,7 +187,10 @@ class Sadie
|
|
157
187
|
}
|
158
188
|
end
|
159
189
|
|
160
|
-
#
|
190
|
+
# ==method: revert!
|
191
|
+
#
|
192
|
+
# return to last saved state
|
193
|
+
#
|
161
194
|
def revert!
|
162
195
|
|
163
196
|
@shortterm = {
|
@@ -168,6 +201,12 @@ class Sadie
|
|
168
201
|
_initializeWithSessionId( get( "sadie.session_id" ) )
|
169
202
|
end
|
170
203
|
|
204
|
+
private
|
205
|
+
|
206
|
+
|
207
|
+
# ==method: primed?
|
208
|
+
#
|
209
|
+
#
|
171
210
|
def primed?( k )
|
172
211
|
@flag_primed[:"#{k}"] \
|
173
212
|
and return true
|
@@ -180,9 +219,6 @@ class Sadie
|
|
180
219
|
return false
|
181
220
|
end
|
182
221
|
|
183
|
-
private
|
184
|
-
|
185
|
-
|
186
222
|
|
187
223
|
def _prime ( k )
|
188
224
|
primer_dirpath = _get("sadie.primers_dirpath")
|
metadata
CHANGED