sadie 0.0.45 → 0.0.46

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -17,4 +17,5 @@
17
17
  [0.0.40] removed over-debugging
18
18
  [0.0.41] minor bugfix
19
19
  [0.0.42,0.0.43] minor bugfix (hopefully), file now closing before method exit (a punt)
20
- [0.0.45] bugfix (punt worked!) in templated file handling
20
+ [0.0.45] bugfix (punt worked!) in templated file handling
21
+ [0.0.46] massive code cleanup. moved lots of things to private. documented all public methods.
@@ -0,0 +1 @@
1
+ #
@@ -32,10 +32,19 @@ Sadie::registerPrimerPlugin( { "match" => /\.dbi\.conx$/,
32
32
 
33
33
  # call connect with block
34
34
  require 'rubygems'
35
- require 'mysql'
35
+ #require 'mysql'
36
+ #require 'pg'
36
37
  require 'dbi'
38
+ #require "dbd-mysql"
37
39
 
38
- dbh = DBI.connect( dbparams['dbistr'], user, pass )
40
+ begin
41
+ dbh = DBI.connect( dbparams['dbistr'], user, pass )
42
+ rescue DBI::DatabaseError => e
43
+ puts "A database connection error occurred..."
44
+ puts " Error code: #{e.err}"
45
+ puts " Error message: #{e.errstr}"
46
+ exit
47
+ end
39
48
 
40
49
  # determine key
41
50
  #sadie_key = key_prefix+'.'+File.basename( primer_file_filepath )
@@ -9,10 +9,12 @@ Sadie::registerPrimerPlugin( { "match" => /\.ini$/,
9
9
 
10
10
  if inihash = Sadie::iniFileToHash( primer_file_filepath )
11
11
  inihash.each do |section, section_hash|
12
+ key_to_set = key_prefix + "." + ini_file_root + "." + section
13
+ key_to_set = key_to_set.gsub(/^\./,"")
14
+ sadie.set key_to_set, section_hash
12
15
  section_hash.each do |key, value|
13
- key_to_set = key_prefix + "." + ini_file_root + "." + section + "." + key
14
- key_to_set = key_to_set.gsub(/^\./,"")
15
- sadie.set( key_to_set, value )
16
+ kvkey_to_set = key_to_set + "." + key
17
+ sadie.set( kvkey_to_set, value )
16
18
 
17
19
  end
18
20
  end
@@ -1,22 +1,29 @@
1
1
  Sadie::registerPrimerPlugin( { "match" => /\.sql2ar$/,
2
2
  "accepts-block" => false,
3
3
  "prime-on-init" => false } ) do |sadie, key_prefix, primer_file_filepath|
4
+
4
5
  primer_file_basename = File.basename( primer_file_filepath )
5
6
  sadie_key = key_prefix + '.' + primer_file_basename
6
7
  sadie_key = sadie_key.gsub(/^\./,"")
8
+
9
+ #sadie.debug! 10, "registersql2ar[#{sadie_key},#{primer_file_basename}]"
10
+
7
11
  Sadie::prime( { "provides" => [ sadie_key ] }) do |sadie|
12
+ #puts "priming sql2ar: #{sadie_key}"
8
13
  if ( matches = primer_file_basename.match( /^(.*)\.([^\.]+)\.sql2ar$/ ) )
9
14
  dbi_sadie_key = key_prefix + '.' + matches[2] + ".dbi.conx"
10
- dbconx = sadie.get( dbi_sadie_key )
15
+ #puts "dbi_sadie_key: #{dbi_sadie_key}"
16
+ #dbconx = sadie.get( dbi_sadie_key )
11
17
  if ( dbconx = sadie.get( dbi_sadie_key ) )
12
18
  if sql_query = Sadie::templatedFileToString( primer_file_filepath )
13
-
19
+ sadie.debug! 5, "sql2ar: querying database: #{sql_query}"
14
20
  sth = dbconx.prepare(sql_query)
15
21
  sth.execute
16
22
 
17
23
  result = Array.new
18
24
  while row = sth.fetch
19
25
  row_as_array = row.to_a
26
+ sadie.debug! 10, "row_as_array: #{row_as_array}"
20
27
  Sadie::eacherFrame sadie_key, Sadie::EACH, row_as_array
21
28
  result.push row_as_array
22
29
  end
data/lib/sadie/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Sadie
2
- VERSION = "0.0.45"
2
+ VERSION = "0.0.46"
3
3
  end
data/lib/sadie.rb CHANGED
@@ -24,6 +24,7 @@ end
24
24
 
25
25
  class Sadie
26
26
 
27
+
27
28
  BEFORE = 1
28
29
  AFTER = 2
29
30
  EACH = 3
@@ -40,19 +41,19 @@ class Sadie
40
41
  # this is called just prior to calling a primer plugin to handle a primer to provide
41
42
  # a current sadie instance for Sadie::getCurrentSadieInstance to return
42
43
  def self.setCurrentSadieInstance ( instance )
43
- @@current_sadie_instance = instance
44
+ @current_sadie_instance = instance
44
45
  end
45
46
 
46
- # ==method: Sadie::setCurrentSadieInstance
47
+ # ==method: Sadie::getCurrentSadieInstance
47
48
  #
48
49
  # called by plugin handlers to get access to the current Sadie instance
49
50
  def self.getCurrentSadieInstance
50
- @@current_sadie_instance
51
+ @current_sadie_instance
51
52
  end
52
53
 
53
54
  # ==method: Sadie::Prime
54
55
  #
55
- # called my the .res files to register the keys the .res will prime for
56
+ # called by the .res files to register the keys the .res will prime for
56
57
  #
57
58
  # accepts as an argument a hash and a block. The hash must include the key:
58
59
  # 'provides' and it must define an array
@@ -62,224 +63,32 @@ class Sadie
62
63
  current_sadie_instance = Sadie::getCurrentSadieInstance
63
64
  current_sadie_instance.prime( primer_definition, &block )
64
65
  end
65
-
66
- def memorizeEacherFileLocation( sadiekey, filepath )
67
-
68
- # store the file path
69
- defined? @eacher_filepaths or @eacher_filepaths = Hash.new
70
- if ! @eacher_filepaths.has_key? sadiekey
71
- @eacher_filepaths[sadiekey] = [filepath]
72
- elsif ! @eacher_filepaths[sadiekey].include? filepath
73
- @eacher_filepaths[sadiekey].push filepath
74
- end
75
- end
76
-
77
- def eacherFilepaths( sadiekey )
78
- defined? @eacher_filepaths or return nil
79
- @eacher_filepaths.has_key? sadiekey or return nil
80
- @eacher_filepaths[sadiekey]
81
- end
82
-
83
- def midEacherInit?
84
- defined? @eacher_init or return false
85
- @eacher_init or return false
86
- true
87
- end
88
-
89
- def setEacherInit
90
- @eacher_init = true
91
- end
92
-
93
- def clearEacherInit
94
- @eacher_init = nil
95
- end
96
66
 
97
-
98
- def eacher( params, &block )
99
- filepath = getCurrentPrimerFilepath
100
- key_prefix = getCurrentPrimerKeyPrefix
101
- occur_at = params[:when]
102
-
103
- # gen sadie key
104
- basefilename = filepath.gsub(/^.*\//,"")
105
- sadiekey = key_prefix + "." + basefilename.gsub(/\.each(?:\..*)*$/,"")
106
- if params.has_key? "sadiekey"
107
- sadiekey = params["sadiekey"]
108
- end
109
-
110
- if midEacherInit?
111
- memorizeEacherFileLocation( sadiekey, filepath )
112
-
113
- if params.has_key? :provides
114
- #puts "> got provides!"
115
- provide_array = params[:provides]
116
- provide_array.respond_to? "each" or provide_array = [provide_array]
117
-
118
- # tell sadie that the sadiekey primer also provides everything in the provide array
119
- setEachersProvidedByPrimer( sadiekey, provide_array )
120
-
121
-
122
- end
123
-
124
- elsif whichEacherFrame == occur_at
125
- if block.arity == 0
126
- yield self
127
- else
128
- yield self, getEacherParam
129
- end
130
- end
131
- end
132
-
133
- def setEachersProvidedByPrimer( sadiekey, providers )
134
-
135
- # record reverse map for use by eacherFrame
136
- defined? @eacher_frame_redirect \
137
- or @eacher_frame_redirect = Hash.new
138
- providers.each do |provider|
139
- @eacher_frame_redirect[provider] = sadiekey
140
- end
141
-
142
- defined? @eachers_provided or @eachers_provided = Hash.new
143
- if @eachers_provided.has_key? sadiekey
144
- @eachers_provided[sadiekey] = @eachers_provided[sadiekey].concat( providers )
145
- else
146
- @eachers_provided[sadiekey] = providers
147
- end
148
- end
149
-
150
- def isEacherKey?( key )
151
- defined? @eacher_frame_redirect or return false
152
- @eacher_frame_redirect.has_key? key or return false
153
- true
154
- end
155
-
156
- def getEacherDependency( key )
157
- defined? @eacher_frame_redirect or return nil
158
- @eacher_frame_redirect.has_key? key or return nil
159
- @eacher_frame_redirect[key]
160
- end
161
-
162
- def getEachersProvidedByPrimer( sadiekey )
163
- defined? @eachers_provided or return nil
164
- @eachers_provided.has_key? sadiekey or return nil
165
- @eachers_provided[sadiekey]
166
- end
167
-
168
67
  # ==method: Sadie::eacher
169
68
  #
170
- # called by eacher files to hook into priming operations
69
+ # called by eacher files to hook into priming operations and calls to set method
171
70
  def self.eacher( eacher_params, &block )
172
71
  current_sadie_instance = Sadie::getCurrentSadieInstance
173
72
  current_sadie_instance.eacher( eacher_params, &block )
174
73
  end
175
74
 
176
-
75
+ # ==method: Sadie::eacherFrame
76
+ #
77
+ # eacherFrame is called by get and set methods and is available to primer plugins
78
+ # as well. when eacher primer files call eacher, they are registering code to
79
+ # be run either BEFORE or AFTER the key/value store is set. Note that the BEFORE
80
+ # eacherFrame runs just before priming when a primer exists and just before set
81
+ # for keys set without primers. EACH eacherFrames are called as the data is being
82
+ # assembled, if such a thing makes sense. The included SQLQueryTo2DArray plugin
83
+ # tries to call any eacherFrame with an EACH occurAt parameter with each row and
84
+ # the registering an EACH eacher might make sense for any number of incrementally
85
+ # built data types
86
+ #
177
87
  def self.eacherFrame( sadiekey, occur_at, param=nil )
178
88
  current_sadie_instance = Sadie::getCurrentSadieInstance
179
89
  current_sadie_instance.eacherFrame( sadiekey, occur_at, param )
180
90
  end
181
91
 
182
- def eacherFrame( sadiekey, occur_at, param=nil )
183
-
184
- key = sadiekey
185
- if defined? @eacher_frame_redirect
186
- if @eacher_frame_redirect.has_key? key
187
- key = @eacher_frame_redirect[key]
188
- end
189
- end
190
-
191
- setEacherFrame( occur_at )
192
- defined? param and setEacherParam( param )
193
- if filepaths = eacherFilepaths( key )
194
- filepaths.each do |filepath|
195
- load filepath
196
- end
197
- end
198
- unsetEacherParam
199
- unsetEacherFrame
200
- end
201
-
202
- def whichEacherFrame
203
- @eacher_frame
204
- end
205
-
206
- def setEacherFrame( f )
207
- @eacher_frame = f
208
- end
209
-
210
- def unsetEacherFrame
211
- @eacher_frame = nil
212
- end
213
-
214
- def setEacherParam( p )
215
- @eacher_param = p
216
- end
217
-
218
- def unsetEacherParam
219
- @eacher_param = nil
220
- end
221
-
222
- def getEacherParam
223
- @eacher_param
224
- end
225
-
226
- # == initialize eachers
227
- #
228
- # register all the eachers
229
- #
230
- # called by initializePrimers so it's not necessary to call this separate from that
231
- def initializeEachers
232
-
233
- primers_dirpath = get( "sadie.primers_dirpath" ) \
234
- or raise "sadie.primers_dirpath not set"
235
-
236
- puts "Initializing eachers..."
237
- setEacherInit
238
- initializeEacherDirectory( "", primers_dirpath )
239
- clearEacherInit
240
- puts "...finished initializing eachers."
241
-
242
-
243
- @@eachers_initialized = true
244
- end
245
-
246
- def initializeEacherDirectory( key_prefix, current_dirpath )
247
-
248
- puts "initializing eacher directory: #{current_dirpath}"
249
- Dir.foreach( current_dirpath ) do |filename|
250
-
251
- # skip the dit dirs
252
- next if filename.eql?(".") || filename.eql?("..") || filename =~ /\~$/
253
-
254
-
255
- filepath = File.expand_path( filename, current_dirpath )
256
-
257
- if File.directory? filepath
258
- new_key_prefix = key_prefix + '.' + filename
259
- new_key_prefix = new_key_prefix.gsub(/^\.+/,"")
260
- initializeEacherDirectory( new_key_prefix, filepath )
261
- else
262
- if filename =~ /\.each(?:\..*)*$/
263
- initializeEacherFile( key_prefix, filepath )
264
- end
265
- end
266
- end
267
- end
268
-
269
- def initializeEacherFile( key_prefix, filepath )
270
- puts "initializing eacher file (#{key_prefix}): #{filepath}"
271
- setCurrentPrimerFilepath filepath
272
- setCurrentPrimerKeyPrefix key_prefix
273
- load filepath
274
- end
275
-
276
- def eachersInitialized?
277
- defined? @@eachers_initialized or return false
278
- @@eachers_initialized and return true
279
- return false
280
- end
281
-
282
-
283
92
  # ==method: Sadie::registerPrimerPlugin
284
93
  #
285
94
  # this method is called in the .plugin.rb files to register new plugin types
@@ -321,6 +130,11 @@ class Sadie
321
130
  return ret
322
131
  end
323
132
 
133
+ # ==method: Sadie::templatedFileToString
134
+ #
135
+ # utility class method. accepts a filepath. digests a template and returns
136
+ # a string containing processed template output
137
+ #
324
138
  def self.templatedFileToString( filepath, binding=nil )
325
139
 
326
140
  template = ERB.new File.new(filepath).read
@@ -334,6 +148,7 @@ class Sadie
334
148
  end
335
149
 
336
150
 
151
+
337
152
  # ==method: constructor
338
153
  # options can include any kay, value pairs but the following key values bear mention:
339
154
  # REQUIRED
@@ -389,11 +204,116 @@ class Sadie
389
204
  "lib/sadie/primer_plugins"
390
205
  )
391
206
 
207
+ if ! File.exists? plugins_dirpath
208
+ plugins_dirpath = File.expand_path "../sadie/lib/sadie/primer_plugins"
209
+ end
210
+
392
211
  end
393
212
  addPrimerPluginsDirPath plugins_dirpath
394
213
 
395
214
  end
396
215
 
216
+ # ==method: setDebugLevel
217
+ #
218
+ # from 0 to 10 with 0 being no debugging messages and 10 being all debugging messages
219
+ #
220
+ def setDebugLevel( lvl )
221
+ lvl > 10 and lvl = 10
222
+ lvl < 0 and lvl = 0
223
+ @debug_level = lvl.to_i
224
+ end
225
+
226
+ # ==method: getDebugLevel
227
+ #
228
+ # return current debug level (default is 10)
229
+ #
230
+ def getDebugLevel
231
+ defined? @debug_level or @debug_level = 10
232
+ @debug_level
233
+ end
234
+
235
+ # ==method: getDebugLevel
236
+ #
237
+ # will print a debugging message if the current debug level is greater than
238
+ # or equal to lvl
239
+ #
240
+ def debug!( lvl, msg )
241
+ defined? @debug_level or @debug_level = 10
242
+ (lvl <= @debug_level) and puts "SADIE(#{lvl}): #{msg}"
243
+ end
244
+
245
+ # ==method: eacher
246
+ #
247
+ # ( usually this will be called by the class method...it looks better )
248
+ #
249
+ # see class method eacher for an explanation
250
+ #
251
+ def eacher( params, &block )
252
+ filepath = getCurrentPrimerFilepath
253
+ key_prefix = getCurrentPrimerKeyPrefix
254
+ occur_at = params[:when]
255
+
256
+ # gen sadie key
257
+ basefilename = filepath.gsub(/^.*\//,"")
258
+ sadiekey = key_prefix + "." + basefilename.gsub(/\.each(?:\..*)*$/,"")
259
+ if params.has_key? "sadiekey"
260
+ sadiekey = params["sadiekey"]
261
+ end
262
+
263
+ if midEacherInit?
264
+ memorizeEacherFileLocation( sadiekey, filepath )
265
+
266
+ if params.has_key? :provides
267
+
268
+ provide_array = params[:provides]
269
+ provide_array.respond_to? "each" or provide_array = [provide_array]
270
+
271
+ # tell sadie that the sadiekey primer also provides everything in the provide array
272
+ setEachersProvidedByPrimer( sadiekey, provide_array )
273
+
274
+ end
275
+
276
+ elsif whichEacherFrame == occur_at
277
+ if block.arity == 0
278
+ yield self
279
+ else
280
+ yield self, getEacherParam
281
+ end
282
+ end
283
+ end
284
+
285
+ # ==method: eacher
286
+ #
287
+ # ( usually this will be called by the class method...it looks better )
288
+ #
289
+ # see class method eacherFrame for an explanation
290
+ #
291
+ def eacherFrame( sadiekey, occur_at, param=nil )
292
+
293
+ key = sadiekey
294
+ if defined? @eacher_frame_redirect
295
+ if @eacher_frame_redirect.has_key? key
296
+ key = @eacher_frame_redirect[key]
297
+ end
298
+ end
299
+
300
+ setEacherFrame( occur_at )
301
+ defined? param and setEacherParam( param )
302
+ if filepaths = eacherFilepaths( key )
303
+ filepaths.each do |filepath|
304
+ load filepath
305
+ end
306
+ end
307
+ unsetEacherParam
308
+ unsetEacherFrame
309
+ end
310
+
311
+
312
+ # ==method: addPrimerPluginsDirPath
313
+ #
314
+ # addPrimerPluginsDirPath adds a directory which will be scanned for plugins to
315
+ # register just before initializePrimers looks for primers to initialize
316
+ #
397
317
  def addPrimerPluginsDirPath( path )
398
318
 
399
319
  exppath = File.expand_path(path)
@@ -408,10 +328,16 @@ class Sadie
408
328
  @plugins_dir_paths.include?(exppath) \
409
329
  or @plugins_dir_paths.unshift(exppath)
410
330
 
411
- @@primer_plugins_initialized = nil
331
+ @primer_plugins_initialized = nil
412
332
  return self
413
333
  end
414
334
 
335
+ # ==method: prime
336
+ #
337
+ # ( usually this will be called by the class method...it looks better )
338
+ #
339
+ # see class method prime for an explanation
340
+ #
415
341
  def prime( primer_definition, &block )
416
342
  # validate params
417
343
  defined? primer_definition \
@@ -426,7 +352,7 @@ class Sadie
426
352
  if midPrimerInit?
427
353
 
428
354
  # mid primer init, just memorize primer location
429
- memorizePrimerLocation( @@mid_primer_filepath, getCurrentPrimerPluginFilepath, primer_definition["provides"] )
355
+ memorizePrimerLocation( @mid_primer_filepath, getCurrentPrimerPluginFilepath, primer_definition["provides"] )
430
356
  else
431
357
 
432
358
  # run code block with the current sadie instance
@@ -447,6 +373,12 @@ class Sadie
447
373
 
448
374
  end
449
375
 
376
+ # ==method: registerPrimerPlugin
377
+ #
378
+ # ( usually this will be called by the class method...it looks better )
379
+ #
380
+ # see class method registerPrimerPlugin for an explanation
381
+ #
450
382
  def registerPrimerPlugin ( arghash, &block )
451
383
 
452
384
  # if mid plugin init is set, we're registering the plugin
@@ -457,12 +389,12 @@ class Sadie
457
389
  # if mid plugin init, register the plugin params with the match
458
390
  if midPluginInit?
459
391
 
460
- regPluginMatch( arghash["match"], @@mid_plugin_filepath, accepts_block, prime_on_init )
392
+ regPluginMatch( arghash["match"], @mid_plugin_filepath, accepts_block, prime_on_init )
461
393
 
462
394
  # midplugininit returned false, we're actually in the process of either initializing
463
395
  # a primer or actually priming
464
396
  else
465
- yield self, getCurrentPrimerKeyPrefix, @@current_primer_filepath
397
+ yield self, getCurrentPrimerKeyPrefix, getCurrentPrimerFilepath
466
398
  end
467
399
  end
468
400
 
@@ -474,6 +406,7 @@ class Sadie
474
406
  # completely behind-the-scenes as directed by the resource (.res) files
475
407
  def get( k )
476
408
 
409
+ debug! 10, "get(#{k})"
477
410
 
478
411
  if ! isset?( k )
479
412
  # prime if not yet primed
@@ -552,6 +485,8 @@ class Sadie
552
485
  # the cheap setter. key, value pairs stored via this method are kept in memory
553
486
  def setCheap( k, v )
554
487
 
488
+ debug! 10, "setting: #{k}"
489
+
555
490
  # set it, mark not expensive and primed
556
491
  _set( k, v )
557
492
  _expensive( k, false )
@@ -561,10 +496,6 @@ class Sadie
561
496
 
562
497
  end
563
498
 
564
- def cheap?( k )
565
- ! expensive? ( k )
566
- end
567
-
568
499
  # ==method: setExpensive
569
500
  #
570
501
  # the expensive setter. key, value pairs stored via this method are not kept in memory
@@ -572,6 +503,10 @@ class Sadie
572
503
  def setExpensive(k,v)
573
504
  expensive_filepath = _computeExpensiveFilepath( k )
574
505
  serialized_value = Marshal::dump( v )
506
+
507
+ File.exist? File.dirname( expensive_filepath ) \
508
+ or Dir.mkdir File.dirname( expensive_filepath )
509
+
575
510
  File.open(expensive_filepath, 'w') { |f|
576
511
  f.write( serialized_value )
577
512
  }
@@ -579,17 +514,6 @@ class Sadie
579
514
  _primed( k, true )
580
515
  end
581
516
 
582
- # ==method: primed?
583
- #
584
- # INTERNAL: this method should only be called the the class method, Prime
585
- #
586
- def expensive?( k )
587
- @flag_expensive.has_key?( k ) or return false;
588
- @flag_expensive["#{k}"] \
589
- and return true
590
- return false
591
- end
592
-
593
517
 
594
518
  # ==method: save
595
519
  #
@@ -618,6 +542,12 @@ class Sadie
618
542
  _initializeWithSessionId( get( "sadie.session_id" ) )
619
543
  end
620
544
 
545
+ # ==method: initializePrimers
546
+ #
547
+ # call this method only after registering all the plugin directories and setting the
548
+ # appropriate session and primer directory paths. after this is called, the key/val
549
+ # pairs will be available via get
550
+ #
621
551
  def initializePrimers
622
552
 
623
553
  Sadie::setCurrentSadieInstance( self )
@@ -634,17 +564,190 @@ class Sadie
634
564
 
635
565
  return true if primersInitialized? primers_dirpath
636
566
 
637
- puts "Initializing primers..."
567
+ debug! 1, "Initializing primers..."
638
568
  initializePrimerDirectory( "", primers_dirpath )
639
- puts "...finished initializing primers."
569
+ debug! 1, "...finished initializing primers."
640
570
 
641
- @@flag_primed[primers_dirpath] = true
571
+ @flag_primed[primers_dirpath] = true
642
572
  end
643
573
 
644
574
 
645
575
 
646
576
  private
647
577
 
578
+ def cheap?( k )
579
+ ! expensive? ( k )
580
+ end
581
+
582
+ # ==method: primed?
583
+ #
584
+ # INTERNAL: this method should only be called the the class method, Prime
585
+ #
586
+ def expensive?( k )
587
+ @flag_expensive.has_key?( k ) or return false;
588
+ @flag_expensive["#{k}"] \
589
+ and return true
590
+ return false
591
+ end
592
+
593
+
594
+ # == initialize eachers
595
+ #
596
+ # register all the eachers
597
+ #
598
+ # called by initializePrimers so it's not necessary to call this separate from that
599
+ def initializeEachers
600
+
601
+ primers_dirpath = get( "sadie.primers_dirpath" ) \
602
+ or raise "sadie.primers_dirpath not set"
603
+
604
+ puts "Initializing eachers..."
605
+ setEacherInit
606
+ initializeEacherDirectory( "", primers_dirpath )
607
+ clearEacherInit
608
+ puts "...finished initializing eachers."
609
+
610
+
611
+ @eachers_initialized = true
612
+ end
613
+
614
+ def initializeEacherDirectory( key_prefix, current_dirpath )
615
+
616
+ puts "initializing eacher directory: #{current_dirpath}"
617
+ Dir.foreach( current_dirpath ) do |filename|
618
+
619
+ # skip the dit dirs
620
+ next if filename.eql?(".") || filename.eql?("..") || filename =~ /\~$/
621
+
622
+
623
+ filepath = File.expand_path( filename, current_dirpath )
624
+
625
+ if File.directory? filepath
626
+ new_key_prefix = key_prefix + '.' + filename
627
+ new_key_prefix = new_key_prefix.gsub(/^\.+/,"")
628
+ initializeEacherDirectory( new_key_prefix, filepath )
629
+ else
630
+ if filename =~ /\.each(?:\..*)*$/
631
+ initializeEacherFile( key_prefix, filepath )
632
+ end
633
+ end
634
+ end
635
+ end
636
+
637
+ def initializeEacherFile( key_prefix, filepath )
638
+ puts "initializing eacher file (#{key_prefix}): #{filepath}"
639
+ setCurrentPrimerFilepath filepath
640
+ setCurrentPrimerKeyPrefix key_prefix
641
+ load filepath
642
+ end
643
+
644
+ def eachersInitialized?
645
+ defined? @eachers_initialized or return false
646
+ @eachers_initialized and return true
647
+ return false
648
+ end
649
+
650
+
651
+
652
+
653
+ def whichEacherFrame
654
+ @eacher_frame
655
+ end
656
+
657
+ def setEacherFrame( f )
658
+ @eacher_frame = f
659
+ end
660
+
661
+ def unsetEacherFrame
662
+ @eacher_frame = nil
663
+ end
664
+
665
+ def setEacherParam( p )
666
+ @eacher_param = p
667
+ end
668
+
669
+ def unsetEacherParam
670
+ @eacher_param = nil
671
+ end
672
+
673
+ def getEacherParam
674
+ @eacher_param
675
+ end
676
+
677
+
678
+ def isEacherKey?( key )
679
+ defined? @eacher_frame_redirect or return false
680
+ @eacher_frame_redirect.has_key? key or return false
681
+ true
682
+ end
683
+
684
+ def getEacherDependency( key )
685
+ defined? @eacher_frame_redirect or return nil
686
+ @eacher_frame_redirect.has_key? key or return nil
687
+ @eacher_frame_redirect[key]
688
+ end
689
+
690
+ def getEachersProvidedByPrimer( sadiekey )
691
+ defined? @eachers_provided or return nil
692
+ @eachers_provided.has_key? sadiekey or return nil
693
+ @eachers_provided[sadiekey]
694
+ end
695
+
696
+
697
+
698
+ def eacherFilepaths( sadiekey )
699
+ defined? @eacher_filepaths or return nil
700
+ @eacher_filepaths.has_key? sadiekey or return nil
701
+ @eacher_filepaths[sadiekey]
702
+ end
703
+
704
+ def midEacherInit?
705
+ defined? @eacher_init or return false
706
+ @eacher_init or return false
707
+ true
708
+ end
709
+
710
+ def setEacherInit
711
+ @eacher_init = true
712
+ end
713
+
714
+ def clearEacherInit
715
+ @eacher_init = nil
716
+ end
717
+
718
+
719
+ def setEachersProvidedByPrimer( sadiekey, providers )
720
+
721
+ # record reverse map for use by eacherFrame
722
+ defined? @eacher_frame_redirect \
723
+ or @eacher_frame_redirect = Hash.new
724
+ providers.each do |provider|
725
+ @eacher_frame_redirect[provider] = sadiekey
726
+ end
727
+
728
+ defined? @eachers_provided or @eachers_provided = Hash.new
729
+ if @eachers_provided.has_key? sadiekey
730
+ @eachers_provided[sadiekey] = @eachers_provided[sadiekey].concat( providers )
731
+ else
732
+ @eachers_provided[sadiekey] = providers
733
+ end
734
+ end
735
+
736
+
737
+
738
+ def memorizeEacherFileLocation( sadiekey, filepath )
739
+
740
+ # store the file path
741
+ defined? @eacher_filepaths or @eacher_filepaths = Hash.new
742
+ if ! @eacher_filepaths.has_key? sadiekey
743
+ @eacher_filepaths[sadiekey] = [filepath]
744
+ elsif ! @eacher_filepaths[sadiekey].include? filepath
745
+ @eacher_filepaths[sadiekey].push filepath
746
+ end
747
+ end
748
+
749
+
750
+
648
751
  # ==method: unprime
649
752
  # unprimes k. Note that this does not unset the value, so
650
753
  # get(key) will continue to return whatever it otherwise would have.
@@ -658,6 +761,9 @@ class Sadie
658
761
  # INTERNAL: this method should only be called the the class method, Prime
659
762
  #
660
763
  def primed?( k )
764
+
765
+ isset?( k ) and return true
766
+
661
767
  @flag_primed.has_key?( k ) \
662
768
  or return false
663
769
  @flag_primed["#{k}"] \
@@ -675,7 +781,7 @@ class Sadie
675
781
 
676
782
  def primerPluginRegistered?( filename )
677
783
 
678
- @@primer_plugin_lookup.each do | plugin_array |
784
+ @primer_plugin_lookup.each do | plugin_array |
679
785
  re, path,accepts_block = plugin_array
680
786
  re.match( filename ) \
681
787
  and return true
@@ -684,40 +790,40 @@ class Sadie
684
790
  end
685
791
 
686
792
  def currentPrimerPluginAcceptsBlock( accepts )
687
- @@primer_plugin_accepts_block = accepts
793
+ @primer_plugin_accepts_block = accepts
688
794
  end
689
795
 
690
796
  def currentPrimerPluginAcceptsBlock?
691
- @@primer_plugin_accepts_block
797
+ @primer_plugin_accepts_block
692
798
  end
693
799
 
694
800
  def currentPrimerPluginPrimeOnInit( prime_on_init )
695
- @@primer_plugin_prime_on_init = prime_on_init
801
+ @primer_plugin_prime_on_init = prime_on_init
696
802
  end
697
803
 
698
804
  def currentPrimerPluginPrimeOnInit?
699
- @@primer_plugin_prime_on_init
805
+ @primer_plugin_prime_on_init
700
806
  end
701
807
 
702
808
  def setMidPluginInit( filepath )
703
- @@mid_plugin_initialization = true
704
- @@mid_plugin_filepath = filepath
809
+ @mid_plugin_initialization = true
810
+ @mid_plugin_filepath = filepath
705
811
  end
706
812
 
707
813
  def unsetMidPluginInit
708
- @@mid_plugin_initialization = false
814
+ @mid_plugin_initialization = false
709
815
  end
710
816
 
711
817
  def midPluginInit?
712
- @@mid_plugin_initialization
818
+ @mid_plugin_initialization
713
819
  end
714
820
 
715
821
  def regPluginMatch ( regexp, filepath, accepts_block, prime_on_init )
716
- @@primer_plugin_lookup.push( [ regexp, filepath, accepts_block, prime_on_init ] )
822
+ @primer_plugin_lookup.push( [ regexp, filepath, accepts_block, prime_on_init ] )
717
823
  end
718
824
 
719
825
  def primerPluginsInitialized?
720
- @@primer_plugins_initialized
826
+ @primer_plugins_initialized
721
827
  end
722
828
 
723
829
  # == initializePrimerPlugins
@@ -730,7 +836,7 @@ class Sadie
730
836
  defined? @plugins_dir_paths \
731
837
  or raise 'plugins_dir_paths not set'
732
838
 
733
- puts "Initializing primer plugins..."
839
+ debug! 1, "Initializing primer plugins..."
734
840
 
735
841
  # load the plugins
736
842
  @plugins_dir_paths.each do | dirpath |
@@ -739,28 +845,28 @@ class Sadie
739
845
 
740
846
  filepath = File.expand_path( filename, dirpath )
741
847
 
742
- puts "initializing primer plugin with file: #{filename}"
848
+ debug! 2, "initializing primer plugin with file: #{filename}"
743
849
 
744
850
  setMidPluginInit( filepath )
745
851
  load( filename )
746
852
  unsetMidPluginInit
747
853
  end
748
854
  end
749
- puts "...finished initializing primer plugins"
750
- @@primer_plugins_initialized = true
855
+ debug! 1, "...finished initializing primer plugins"
856
+ @primer_plugins_initialized = true
751
857
  end
752
858
 
753
859
  def setMidPrimerInit ( filepath )
754
- @@mid_primer_initialization = true
755
- @@mid_primer_filepath = filepath
860
+ @mid_primer_initialization = true
861
+ @mid_primer_filepath = filepath
756
862
  end
757
863
 
758
864
  def unsetMidPrimerInit
759
- @@mid_primer_initialization = false
865
+ @mid_primer_initialization = false
760
866
  end
761
867
 
762
868
  def midPrimerInit?
763
- @@mid_primer_initialization \
869
+ @mid_primer_initialization \
764
870
  and return true;
765
871
  return false;
766
872
  end
@@ -768,9 +874,9 @@ class Sadie
768
874
 
769
875
 
770
876
  def primersInitialized? ( toplevel_dirpath )
771
- @@flag_primed.has_key?( toplevel_dirpath ) \
877
+ @flag_primed.has_key?( toplevel_dirpath ) \
772
878
  or return false;
773
- return @@flag_primed[toplevel_dirpath]
879
+ return @flag_primed[toplevel_dirpath]
774
880
  end
775
881
 
776
882
  def initializePrimerDirectory( key_prefix, current_dirpath )
@@ -810,7 +916,9 @@ class Sadie
810
916
 
811
917
  def initializePrimerWithPlugin( key_prefix, filepath )
812
918
 
813
- @@primer_plugin_lookup.each do | plugin_array |
919
+ debug! 9, "initializing primer file #{File.basename(filepath)} with plugin"
920
+
921
+ @primer_plugin_lookup.each do | plugin_array |
814
922
 
815
923
  # we just need to match the basename
816
924
  filename = File.basename( filepath )
@@ -837,35 +945,35 @@ class Sadie
837
945
  end
838
946
 
839
947
  def setCurrentPrimerPluginFilepath( filepath )
840
- @@current_primer_plugin_filepath = filepath
948
+ @current_primer_plugin_filepath = filepath
841
949
  end
842
950
 
843
951
  def getCurrentPrimerPluginFilepath
844
- @@current_primer_plugin_filepath
952
+ @current_primer_plugin_filepath
845
953
  end
846
954
 
847
955
  def setCurrentPrimerKeyPrefix ( prefix )
848
- @@current_primer_keyprefix = prefix
956
+ @current_primer_keyprefix = prefix
849
957
  end
850
958
 
851
959
  def getCurrentPrimerKeyPrefix
852
- @@current_primer_keyprefix
960
+ @current_primer_keyprefix
853
961
  end
854
962
 
855
963
  def setCurrentPrimerFilepath ( filepath )
856
- @@current_primer_filepath = filepath
964
+ @current_primer_filepath = filepath
857
965
  end
858
966
 
859
967
  def getCurrentPrimerFilepath
860
- @@current_primer_filepath
968
+ @current_primer_filepath
861
969
  end
862
970
 
863
971
  def setCurrentPrimerRequestingKey( key )
864
- @@current_primer_requesting_key = key
972
+ @current_primer_requesting_key = key
865
973
  end
866
974
 
867
975
  def getCurrentPrimerRequestingKey
868
- @@current_primer_requesting_key
976
+ @current_primer_requesting_key
869
977
  end
870
978
 
871
979
  # ==memorizePrimerLocation
@@ -874,10 +982,10 @@ class Sadie
874
982
  def memorizePrimerLocation( filepath, plugin_filepath, primer_provides )
875
983
 
876
984
  # validate primer hash
877
- #primer_dirpath = @@mid_primer_toplevel_primer_dirpath
985
+ #primer_dirpath = @mid_primer_toplevel_primer_dirpath
878
986
  primer_dirpath = _get("sadie.primers_dirpath")
879
- @@primer_hash.has_key?( primer_dirpath ) \
880
- or @@primer_hash["#{primer_dirpath}"] = Hash.new
987
+ @primer_hash.has_key?( primer_dirpath ) \
988
+ or @primer_hash["#{primer_dirpath}"] = Hash.new
881
989
 
882
990
  # interate over provides setting primer providers for each
883
991
  primer_provides.each do | key |
@@ -894,10 +1002,10 @@ class Sadie
894
1002
  def setPrimerProvider( primer_name, primer_filepath, primer_plugin_filepath, key_prefix )
895
1003
 
896
1004
  primer_dirpath = _get( "sadie.primers_dirpath" )
897
- @@primer_hash.has_key?( primer_dirpath ) \
898
- or @@primer_hash[primer_dirpath] = Hash.new
1005
+ @primer_hash.has_key?( primer_dirpath ) \
1006
+ or @primer_hash[primer_dirpath] = Hash.new
899
1007
 
900
- @@primer_hash["#{primer_dirpath}"]["#{primer_name}"] = [ primer_filepath, primer_plugin_filepath, key_prefix ]
1008
+ @primer_hash["#{primer_dirpath}"]["#{primer_name}"] = [ primer_filepath, primer_plugin_filepath, key_prefix ]
901
1009
 
902
1010
  end
903
1011
 
@@ -905,10 +1013,10 @@ class Sadie
905
1013
 
906
1014
  # fetch primers dirpath and validate the primer hash
907
1015
  primer_dirpath = _get( "sadie.primers_dirpath" )
908
- @@primer_hash.has_key?( primer_dirpath ) \
909
- or @@primer_hash[primer_dirpath] = Hash.new
1016
+ @primer_hash.has_key?( primer_dirpath ) \
1017
+ or @primer_hash[primer_dirpath] = Hash.new
910
1018
 
911
- primers = @@primer_hash[primer_dirpath]
1019
+ primers = @primer_hash[primer_dirpath]
912
1020
  primers.has_key?( key ) \
913
1021
  or return nil # primer not defined
914
1022
 
@@ -933,6 +1041,8 @@ class Sadie
933
1041
 
934
1042
  def _prime ( k )
935
1043
 
1044
+ debug! 10, "priming: #{k}"
1045
+
936
1046
  if isEacherKey? k
937
1047
  get( getEacherDependency( k ) )
938
1048
  else
@@ -941,11 +1051,17 @@ class Sadie
941
1051
  if provider = getPrimerProvider( k )
942
1052
  primer_filepath, plugin_filepath, key_prefix = provider
943
1053
 
1054
+ currfilepath = getCurrentPrimerFilepath
1055
+
944
1056
  setCurrentPrimerFilepath(primer_filepath)
945
1057
  setCurrentPrimerKeyPrefix( key_prefix )
946
1058
  Sadie::setCurrentSadieInstance( self )
947
1059
 
948
1060
  load plugin_filepath
1061
+
1062
+ if defined? currfilepath
1063
+ setCurrentPrimerFilepath currfilepath
1064
+ end
949
1065
  end
950
1066
  Sadie::eacherFrame( k, AFTER )
951
1067
  end
@@ -1067,24 +1183,24 @@ class Sadie
1067
1183
  #
1068
1184
  # verifies that needed class variables are defined
1069
1185
  def _checkClassSanity
1070
- defined? @@flag_primed \
1071
- or @@flag_primed = Hash.new
1186
+ defined? @flag_primed \
1187
+ or @flag_primed = Hash.new
1072
1188
 
1073
1189
  # init primer plugin vars
1074
- if ( ! defined? @@primer_plugin_lookup )
1075
- @@mid_plugin_initialization = false
1076
- @@primer_plugin_lookup = Array.new
1077
- @@primer_plugins_initialized = false
1190
+ if ( ! defined? @primer_plugin_lookup )
1191
+ @mid_plugin_initialization = false
1192
+ @primer_plugin_lookup = Array.new
1193
+ @primer_plugins_initialized = false
1078
1194
  end
1079
1195
 
1080
1196
  # init primer vars
1081
- defined? @@primer_hash \
1082
- or @@primer_hash = Hash.new
1197
+ defined? @primer_hash \
1198
+ or @primer_hash = Hash.new
1083
1199
  defined? @flag_primed \
1084
1200
  or @flag_primed = Hash.new
1085
- if ! defined? @@mid_primer_initialization
1086
- @@mid_primer_initialization = false
1087
- @@mid_primer_filepath = nil
1201
+ if ! defined? @mid_primer_initialization
1202
+ @mid_primer_initialization = false
1203
+ @mid_primer_filepath = nil
1088
1204
  end
1089
1205
 
1090
1206
  end
data/sadie.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
 
25
25
  #s.add_runtime_dependency "ini"
26
26
  s.add_runtime_dependency "dbi"
27
- s.add_runtime_dependency "mysql"
27
+ #s.add_runtime_dependency "mysql2"
28
28
  s.add_runtime_dependency "dbd-mysql"
29
29
  s.extra_rdoc_files = ['README', 'CHANGELOG', 'TODO']
30
30
  end
@@ -3,6 +3,8 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
3
3
  require "test/unit"
4
4
  require "sadie"
5
5
  require "tmpdir"
6
+ # require "mysql"
7
+ #require "dbd-mysql"
6
8
 
7
9
  class TestSadieTwoDeep < Test::Unit::TestCase
8
10
  def test_simple
@@ -13,4 +13,3 @@ Sadie::eacher( :when => Sadie::AFTER, :provides => ["simple.eacher.test"] ) do
13
13
  sadie.set "simple.eacher.test", @testeach
14
14
  end
15
15
 
16
- #def dsl_correct?; ( bitch_to_wrap_head_around? ) && ( rewritten_atleast_three_times? ) && ( seems_easy_now_that_its_done? ) && ( have_less_hair_now? ); end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sadie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.45
4
+ version: 0.0.46
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-20 00:00:00.000000000Z
12
+ date: 2012-04-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dbi
16
- requirement: &12231900 !ruby/object:Gem::Requirement
16
+ requirement: &16171300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12231900
25
- - !ruby/object:Gem::Dependency
26
- name: mysql
27
- requirement: &12281320 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *12281320
24
+ version_requirements: *16171300
36
25
  - !ruby/object:Gem::Dependency
37
26
  name: dbd-mysql
38
- requirement: &12280900 !ruby/object:Gem::Requirement
27
+ requirement: &16170880 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - ! '>='
@@ -43,7 +32,7 @@ dependencies:
43
32
  version: '0'
44
33
  type: :runtime
45
34
  prerelease: false
46
- version_requirements: *12280900
35
+ version_requirements: *16170880
47
36
  description: Sadie is a data framework intended to ease the pain of managing related
48
37
  data.
49
38
  email:
@@ -65,6 +54,7 @@ files:
65
54
  - TODO
66
55
  - lib/.gitignore
67
56
  - lib/sadie.rb
57
+ - lib/sadie/debug.rb
68
58
  - lib/sadie/defaults.rb
69
59
  - lib/sadie/primer_plugins/DatabaseConnection.plugin.rb
70
60
  - lib/sadie/primer_plugins/IniFile.plugin.rb