sadie 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,71 @@
1
1
  # WARNING: THIS DOESN'T WORK YET!!!
2
2
 
3
3
  Sadie::registerPrimerPlugin( { "match" => /\.dbi\.conx$/,
4
- "accepts-block" => true } ) do |sadie, key_prefix, primer_file_filepath, block|
5
-
6
- # build parameter hash
7
- dbparams = Hash.new
8
- inifile = Ini.new( primer_file_filepath )
9
- inifile.each do | section, key_from_ini_file, value |
10
- section.match(/^connection$/) \
11
- or next
12
- dbparams[key_from_ini_file] = value
13
- end
4
+ "accepts-block" => false,
5
+ "prime-on-init" => false } ) do |sadie, key_prefix, primer_file_filepath|
6
+
7
+ # determine key
8
+ sadie_key = key_prefix+'.'+File.basename( primer_file_filepath )
14
9
 
15
- # validate dbistr
16
- dbparams.has_key( 'dbistr' ) \
17
- or raise 'requried connection::dbistr was not defined'
18
10
 
19
- # default user and pass to nil
20
- user = dbparams.has_key('user') ? dbparams['user']: nil;
21
- pass = dbparams.has_key('pass') ? dbparams['pass']: nil;
11
+ Sadie::prime( { "provides" => [ sadie_key ] }) do |sadie|
12
+
13
+ if inihash = Sadie::iniFileToHash( primer_file_filepath )
14
+ dbparams = Hash.new
15
+
16
+ inihash.each do |section, section_hash|
17
+ section.match(/^connection$/) \
18
+ or next
19
+ section_hash.each do |key, value|
20
+ dbparams[key] = value
21
+ end
22
+ end
23
+
24
+ if ! dbparams.empty?
25
+ # validate dbistr
26
+ dbparams.has_key?( 'dbistr' ) \
27
+ or raise 'requried connection::dbistr was not defined'
28
+
29
+ # default user and pass to nil
30
+ user = dbparams.has_key?('user') ? dbparams['user']: nil;
31
+ pass = dbparams.has_key?('pass') ? dbparams['pass']: nil;
32
+
33
+ # call connect with block
34
+ require 'rubygems'
35
+ require 'mysql'
36
+ require 'dbi'
37
+
38
+ dbh = DBI.connect( dbparams['dbistr'], user, pass )
39
+
40
+ # determine key
41
+ #sadie_key = key_prefix+'.'+File.basename( primer_file_filepath )
42
+
43
+ # puts "installing db connection: #{sadie_key}"
44
+
45
+ sadie.set( sadie_key, dbh )
46
+
47
+ end
48
+ end
49
+ end
22
50
 
23
- # call connect with block
24
- require 'dbi'
25
- DBI.connect( dbparams['dbistr'], user, pass, block )
51
+ # # build parameter hash
52
+ # dbparams = Hash.new
53
+ # inifile = Ini.new( primer_file_filepath )
54
+ # inifile.each do | section, key_from_ini_file, value |
55
+ # section.match(/^connection$/) \
56
+ # or next
57
+ # dbparams[key_from_ini_file] = value
58
+ # end
59
+ #
60
+ # # validate dbistr
61
+ # dbparams.has_key?( 'dbistr' ) \
62
+ # or raise 'requried connection::dbistr was not defined'
63
+ #
64
+ # # default user and pass to nil
65
+ # user = dbparams.has_key?('user') ? dbparams['user']: nil;
66
+ # pass = dbparams.has_key?('pass') ? dbparams['pass']: nil;
67
+ #
68
+ # # call connect with block
69
+ # require 'dbi'
70
+ # DBI.connect( dbparams['dbistr'], user, pass, block )
26
71
  end
@@ -2,20 +2,59 @@ Sadie::registerPrimerPlugin( { "match" => /\.ini$/,
2
2
  "accepts-block" => false,
3
3
  "prime-on-init" => true } ) do |sadie, key_prefix, primer_file_filepath|
4
4
 
5
- require 'ini'
6
-
7
5
  ini_file_basename = File.basename primer_file_filepath
8
6
  ini_file_root = ini_file_basename.gsub( /\.ini$/, "" )
9
7
 
10
- inifile = Ini.new( primer_file_filepath )
11
- # puts "key_prefix: #{key_prefix}, primer_file_filepath: #{primer_file_filepath}"
12
- inifile.each do | section, key_from_ini_file, value |
13
-
14
- # compute key
15
- # key_prefix = sadie.getCurrentPrimerKeyPrefix
16
- key_to_set = key_prefix + "." + ini_file_root + "." +section + "." + key_from_ini_file
17
- key_to_set = key_to_set.gsub( /^\.+/, "" )
8
+ if inihash = Sadie::iniFileToHash( primer_file_filepath )
18
9
 
19
- sadie.set( key_to_set, value )
10
+ inihash.each do |section, section_hash|
11
+
12
+ section_hash.each do |key, value|
13
+
14
+ key_to_set = key_prefix + "." + ini_file_root + "." + section + "." + key
15
+ key_to_set = key_to_set.gsub(/^\./,"")
16
+ sadie.set( key_to_set, value )
17
+
18
+ end
19
+ end
20
20
  end
21
+
22
+ # section = nil
23
+ # File.open( primer_file_filepath, "r" ).each do |f|
24
+ # f.each_line do |line|
25
+ # next if line.match(/^;/) # skip comments
26
+ # if matches = line.match(/\[([^\]]+)\]/)
27
+ # section = matches[1]
28
+ # elsif matches = line.match(/^\s*([^\s\=]+)\s*\=\s*([^\s]+)\s*$/)
29
+ # key = matches[1]
30
+ # value = matches[2]
31
+ # if qmatches = value.match(/[\'\"](.*)[\'\"]/)
32
+ # newvalue = qmatches[1]
33
+ # value = newvalue
34
+ # end
35
+ # if defined? section
36
+ # key_to_set = key_prefix + "." + ini_file_root + "." +section + "." + key
37
+ # sadie.set( key_to_set, value )
38
+ # end
39
+ # end
40
+ # end
41
+ # end
42
+
43
+ # require 'rubygems'
44
+ # require 'ini'
45
+ #
46
+ # ini_file_basename = File.basename primer_file_filepath
47
+ # ini_file_root = ini_file_basename.gsub( /\.ini$/, "" )
48
+ #
49
+ # inifile = Ini.new( primer_file_filepath )
50
+ # # puts "key_prefix: #{key_prefix}, primer_file_filepath: #{primer_file_filepath}"
51
+ # inifile.each do | section, key_from_ini_file, value |
52
+ #
53
+ # # compute key
54
+ # # key_prefix = sadie.getCurrentPrimerKeyPrefix
55
+ # key_to_set = key_prefix + "." + ini_file_root + "." +section + "." + key_from_ini_file
56
+ # key_to_set = key_to_set.gsub( /^\.+/, "" )
57
+ #
58
+ # sadie.set( key_to_set, value )
59
+ # end
21
60
  end
@@ -1,5 +1,5 @@
1
1
  Sadie::registerPrimerPlugin( { "match" => /(\.res|\.res\.rb)$/,
2
- "accepts-block" => true,
2
+ "accepts-block" => false,
3
3
  "prime-on-init" => false } ) do |sadie, key_prefix, primer_file_filepath, block|
4
4
 
5
5
  load( primer_file_filepath )
@@ -0,0 +1,36 @@
1
+ Sadie::registerPrimerPlugin( { "match" => /\.sql$/,
2
+ "accepts-block" => false,
3
+ "prime-on-init" => false } ) do |sadie, key_prefix, primer_file_filepath|
4
+ primer_file_basename = File.basename( primer_file_filepath )
5
+ sadie_key = key_prefix + '.' + primer_file_basename
6
+ sadie_key = sadie_key.gsub(/^\./,"")
7
+
8
+ Sadie::prime( { "provides" => [ sadie_key ] }) do |sadie|
9
+
10
+ if ( matches = primer_file_basename.match( /^(.*)\.([^\.]+)\.sql$/ ) )
11
+ dbi_sadie_key = key_prefix + '.' + matches[2] + ".dbi.conx"
12
+ # puts "dbi_sadie_key: #{dbi_sadie_key}, connecting..."
13
+ dbconx = sadie.get( dbi_sadie_key )
14
+ # puts "dbconx: #{dbconx}"
15
+ if ( dbconx = sadie.get( dbi_sadie_key ) )
16
+ # puts " connected."
17
+ if sql_query = Sadie::templatedFileToString( primer_file_filepath )
18
+
19
+ sth = dbconx.prepare(sql_query)
20
+ sth.execute
21
+
22
+ result = Array.new
23
+ while row = sth.fetch
24
+ result.push row.to_a
25
+ end
26
+
27
+
28
+ sadie.setExpensive( sadie_key, result )
29
+
30
+ # Close the statement handle when done
31
+ sth.finish
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ Sadie::registerPrimerPlugin( { "match" => /\.tmpl$/,
2
+ "accepts-block" => false,
3
+ "prime-on-init" => false } ) do |sadie, key_prefix, primer_file_filepath|
4
+ primer_file_basename = File.basename( primer_file_filepath )
5
+ sadie_key = key_prefix + '.' + primer_file_basename
6
+ sadie_key = sadie_key.gsub(/^\./,"")
7
+
8
+ Sadie::prime( { "provides" => [ sadie_key ] }) do |sadie|
9
+
10
+ sadie.setExpensive( sadie_key, Sadie::templatedFileToString( primer_file_filepath ) )
11
+
12
+ end
13
+ end
data/lib/sadie/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # this file sets the version of the Sadie gem
3
3
 
4
4
  class Sadie
5
- VERSION = "0.0.8"
5
+ VERSION = "0.0.9"
6
6
  end
data/lib/sadie.rb CHANGED
@@ -3,8 +3,7 @@ require 'rubygems'
3
3
  require "bundler/setup"
4
4
  require 'bundler'
5
5
  Bundler.require(:default)
6
- #require 'ini'
7
-
6
+ require 'erb'
8
7
 
9
8
  # ==Description: Sadie
10
9
  # Sadie is a data framework intended to ease the pain of constructing, accessing, and
@@ -17,6 +16,11 @@ Bundler.require(:default)
17
16
  # supports on-demand, one-time evaluation of "primers" which may define, or prime,
18
17
  # multiple key, value pairs in a single run.
19
18
 
19
+ def S( key )
20
+ instance = Sadie::getCurrentSadieInstance
21
+ return instance.get( key )
22
+ end
23
+
20
24
  class Sadie
21
25
 
22
26
  # ==method: Sadie::getSadieInstance
@@ -62,6 +66,44 @@ class Sadie
62
66
  current_sadie_instance = Sadie::getCurrentSadieInstance
63
67
  current_sadie_instance.registerPrimerPlugin( arghash, &block )
64
68
  end
69
+
70
+ # ==method: Sadie::iniFileToHash
71
+ #
72
+ # utility class method. accepts a filepath. digests inin file and returns hash of hashes.
73
+ #
74
+ def self.iniFileToHash ( filepath )
75
+ section = nil
76
+ ret = Hash.new
77
+ File.open( filepath, "r" ).each do |f|
78
+ f.each_line do |line|
79
+ next if line.match(/^;/) # skip comments
80
+ if matches = line.match(/\[([^\]]+)\]/)
81
+ section = matches[1]
82
+ ret[section] = Hash.new
83
+ elsif matches = line.match(/^\s*([^\s\=]+)\s*\=\s*([^\s]+)\s*$/)
84
+ key = matches[1]
85
+ value = matches[2]
86
+
87
+ # strip quotes
88
+ if qmatches = value.match(/[\'\"](.*)[\'\"]/)
89
+ value = qmatches[1]
90
+ end
91
+
92
+ if defined? section
93
+ ret[section][key] = value
94
+ end
95
+ end
96
+ end
97
+ end
98
+ ret.empty? and return nil
99
+ return ret
100
+ end
101
+
102
+ def self.templatedFileToString( filepath )
103
+ f = open( filepath )
104
+ template = ERB.new( f.read )
105
+ template.result
106
+ end
65
107
 
66
108
 
67
109
  # ==method: constructor
@@ -110,20 +152,31 @@ class Sadie
110
152
  and set( "sadie.primers_dirpath", delay_set_primers_dirpath )
111
153
 
112
154
  # if a path to a session is given, init using session file
113
- if defined? options[:sadie.session_filepath] && options[:sadie.session_filepath].match(/^[^\s]+$/)
114
- set( "sadie.session_filepath", options[:sadie.session_filepath] )
155
+ if options.has_key?( "sadie.session_filepath" )
156
+ set( "sadie.session_filepath", options["sadie.session_filepath"] )
115
157
  _initializeWithSessionFilePath( get("sadie.session_filepath") )
116
- return
117
- end
118
-
119
- # determine session id, init from session if provided as arg
120
- if defined?options[:sadie.session_id] && options[:sadie.session_id].match(/^[^\s]+$/)
121
- set( "sadie.session_id", options[:sadie.session_id] )
158
+ elsif options.has_key?( "sadie.session_id" )
159
+ set( "sadie.session_id", options["sadie.session_id"] )
122
160
  _initializeWithSessionId( get( "sadie.session_id" ) )
123
161
  else
124
162
  set( "sadie.session_id", _generateNewSessionId )
125
163
  end
126
164
 
165
+ # if defined? options["sadie.session_filepath"] \
166
+ # && options["sadie.session_filepath"].match(/^[^\s]+$/)
167
+ # set( "sadie.session_filepath", options["sadie.session_filepath"] )
168
+ # _initializeWithSessionFilePath( get("sadie.session_filepath") )
169
+ # return
170
+ # end
171
+ #
172
+ # # determine session id, init from session if provided as arg
173
+ # if defined?options["sadie.session_id"] && options["sadie.session_id"].match(/^[^\s]+$/)
174
+ # set( "sadie.session_id", options["sadie.session_id"] )
175
+ # _initializeWithSessionId( get( "sadie.session_id" ) )
176
+ # else
177
+ # set( "sadie.session_id", _generateNewSessionId )
178
+ # end
179
+
127
180
  end
128
181
 
129
182
  def prime ( primer_definition, &block )
@@ -140,7 +193,7 @@ class Sadie
140
193
  if midPrimerInit?
141
194
 
142
195
  # mid primer init, just memorize primer location
143
- memorizePrimerLocation( @@mid_primer_filepath, primer_definition["provides"] )
196
+ memorizePrimerLocation( @@mid_primer_filepath, getCurrentPrimerPluginFilepath, primer_definition["provides"] )
144
197
  else
145
198
 
146
199
  # run code block with the current sadie instance
@@ -164,31 +217,42 @@ class Sadie
164
217
  end
165
218
 
166
219
  def registerPrimerPlugin ( arghash, &block )
220
+
221
+ # if mid plugin init is set, we're registering the plugin
222
+ # init mode, just store arghash info
223
+ accepts_block = arghash.has_key?( "accepts-block" ) && arghash["accepts-block"] ? true : false
224
+ prime_on_init = arghash.has_key?( "prime-on-init" ) && arghash["prime-on-init"] ? true : false
225
+
226
+
227
+
228
+
229
+
230
+ # if mid plugin init, register the plugin params with the match
167
231
  if midPluginInit?
168
232
 
169
- # init mode, just store arghash info
170
- accepts_block = arghash.has_key?( "accepts-block" ) && arghash["accepts-block"] ? true : false
171
- prime_on_init = arghash.has_key?( "prime-on-init" ) && arghash["prime-on-init"] ? true : false
172
233
  regPluginMatch( arghash["match"], @@mid_plugin_filepath, accepts_block, prime_on_init )
173
234
 
235
+ # midplugininit returned false, we're actually in the process of either initializing
236
+ # a primer or actually priming
174
237
  else
175
-
176
- # prime mode
177
- currentPrimerPluginPrimerOnInit? \
178
- or setMidPrimerInit( @@current_primer_filepath )
179
- key_prefix = getCurrentPrimerKeyPrefix
180
- if currentPrimerPluginAcceptsBlock?
181
-
182
- # call with block only if accepts block
183
- yield( self, key_prefix, @@current_primer_filepath, block )
184
-
185
- else
238
+ yield( self, getCurrentPrimerKeyPrefix, @@current_primer_filepath ) \
239
+ # unless midPrimerInit?
240
+ # if registering the prime mode, skips block exec
241
+ #
242
+ # if currentPrimerPluginAcceptsBlock?
243
+ #
244
+ # # call with block only if accepts block
245
+ # yield( self, getCurrentPrimerKeyPrefix, @@current_primer_filepath, &block )
246
+ #
247
+ # else
186
248
 
187
- yield( self, key_prefix, @@current_primer_filepath )
249
+ # yield( self, getCurrentPrimerKeyPrefix, @@current_primer_filepath ) \
250
+ # if prime_on_init or
188
251
 
189
- end
190
- currentPrimerPluginPrimerOnInit? \
191
- or unsetMidPrimerInit
252
+ # end
253
+
254
+ # prime_on_init \
255
+ # or unsetMidPrimerInit
192
256
 
193
257
  end
194
258
  end
@@ -338,6 +402,7 @@ class Sadie
338
402
  # the expensive setter. key, value pairs stored via this method are not kept in memory
339
403
  # but are stored to file and recalled as needed
340
404
  def setExpensive(k,v)
405
+ # puts "setting expensive, key: #{k}"
341
406
  expensive_filepath = _computeExpensiveFilepath( k )
342
407
  serialized_value = Marshal::dump( v )
343
408
  File.open(expensive_filepath, 'w') { |f|
@@ -428,31 +493,6 @@ class Sadie
428
493
  return false;
429
494
  end
430
495
 
431
- def primeWithPlugin( key_prefix, filepath )
432
-
433
- # when this primes, the block run of registerPrimerPlugin needs
434
- # to know whether or not it accepts block
435
- @@primer_plugin_lookup.each do | plugin_array |
436
-
437
- # we just need to match the basename
438
- filename = File.basename( filepath )
439
-
440
- regexp, plugin_filepath, accepts_block, prime_on_init = plugin_array
441
-
442
- if regexp.match( filename )
443
-
444
- currentPrimerPluginAcceptsBlock( accepts_block )
445
- currentPrimerPluginPrimeOnInit( prime_on_init )
446
-
447
- plugin_filename = File.basename( plugin_filepath )
448
-
449
- load( plugin_filepath )
450
-
451
- return
452
- end
453
- end
454
- end
455
-
456
496
  def currentPrimerPluginAcceptsBlock( accepts )
457
497
  @@primer_plugin_accepts_block = accepts
458
498
  end
@@ -465,7 +505,7 @@ class Sadie
465
505
  @@primer_plugin_prime_on_init = prime_on_init
466
506
  end
467
507
 
468
- def currentPrimerPluginPrimerOnInit?
508
+ def currentPrimerPluginPrimeOnInit?
469
509
  @@primer_plugin_prime_on_init
470
510
  end
471
511
 
@@ -514,6 +554,7 @@ class Sadie
514
554
  load( filepath )
515
555
  unsetMidPluginInit
516
556
  end
557
+ puts "...finished initializing primer plugins"
517
558
  @@primer_plugins_initialized = true
518
559
  end
519
560
 
@@ -556,7 +597,7 @@ class Sadie
556
597
 
557
598
  puts "Initializing primers..."
558
599
  initializePrimerDirectory( "", primers_dirpath )
559
-
600
+ puts "...finished initializing primers."
560
601
 
561
602
  @@flag_primed[primers_dirpath] = true
562
603
  end
@@ -590,11 +631,49 @@ class Sadie
590
631
  setCurrentPrimerKeyPrefix key_prefix
591
632
 
592
633
  basename = File.basename( filepath )
593
- primeWithPlugin( key_prefix, filepath )
634
+ initializePrimerWithPlugin( key_prefix, filepath )
635
+
636
+
594
637
  end
595
638
  end
596
639
 
640
+ def initializePrimerWithPlugin( key_prefix, filepath )
641
+
642
+ @@primer_plugin_lookup.each do | plugin_array |
643
+
644
+ # we just need to match the basename
645
+ filename = File.basename( filepath )
646
+
647
+ regexp, plugin_filepath, accepts_block, prime_on_init = plugin_array
648
+
649
+ if regexp.match( filename )
650
+
651
+ # currentPrimerPluginAcceptsBlock( accepts_block )
652
+ # currentPrimerPluginPrimeOnInit( prime_on_init )
653
+ setCurrentPrimerPluginFilepath( plugin_filepath )
654
+ prime_on_init \
655
+ or setMidPrimerInit( filepath )
656
+
657
+ plugin_filename = File.basename( plugin_filepath )
658
+
659
+ load( plugin_filepath )
660
+
661
+ prime_on_init \
662
+ or unsetMidPrimerInit
663
+
664
+
665
+ return
666
+ end
667
+ end
668
+ end
597
669
 
670
+ def setCurrentPrimerPluginFilepath( filepath )
671
+ @@current_primer_plugin_filepath = filepath
672
+ end
673
+
674
+ def getCurrentPrimerPluginFilepath
675
+ @@current_primer_plugin_filepath
676
+ end
598
677
 
599
678
  def setCurrentPrimerKeyPrefix ( prefix )
600
679
  @@current_primer_keyprefix = prefix
@@ -617,7 +696,7 @@ class Sadie
617
696
  # ==memorizePrimerLocation
618
697
  #
619
698
  # internal, ignore the man behind the curtain
620
- def memorizePrimerLocation( filepath, primer_provides )
699
+ def memorizePrimerLocation( filepath, plugin_filepath, primer_provides )
621
700
 
622
701
  # validate primer hash
623
702
  #primer_dirpath = @@mid_primer_toplevel_primer_dirpath
@@ -627,7 +706,7 @@ class Sadie
627
706
 
628
707
  # interate over provides setting primer providers for each
629
708
  primer_provides.each do | key |
630
- setPrimerProvider( key, filepath )
709
+ setPrimerProvider( key, filepath, plugin_filepath, getCurrentPrimerKeyPrefix )
631
710
  end
632
711
  end
633
712
 
@@ -635,13 +714,13 @@ class Sadie
635
714
  # ==setPrimerProvider
636
715
  #
637
716
  # internal, ignore the man behind the curtain
638
- def setPrimerProvider( primer_name, primer_filepath )
717
+ def setPrimerProvider( primer_name, primer_filepath, primer_plugin_filepath, key_prefix )
639
718
 
640
719
  primer_dirpath = _get( "sadie.primers_dirpath" )
641
720
  @@primer_hash.has_key?( primer_dirpath ) \
642
721
  or @@primer_hash[primer_dirpath] = Hash.new
643
722
 
644
- @@primer_hash["#{primer_dirpath}"]["#{primer_name}"] = primer_filepath
723
+ @@primer_hash["#{primer_dirpath}"]["#{primer_name}"] = [ primer_filepath, primer_plugin_filepath, key_prefix ]
645
724
 
646
725
  end
647
726
 
@@ -677,13 +756,17 @@ class Sadie
677
756
 
678
757
  def _prime ( k )
679
758
 
680
- provider = getPrimerProvider( k ) \
681
- or return true;
759
+ if provider = getPrimerProvider( k )
760
+ primer_filepath, plugin_filepath, key_prefix = provider
682
761
 
683
- setCurrentPrimerFilepath(provider)
684
- Sadie::setCurrentSadieInstance( self )
685
- load provider
686
- true
762
+ setCurrentPrimerFilepath(primer_filepath)
763
+ setCurrentPrimerKeyPrefix( key_prefix )
764
+ Sadie::setCurrentSadieInstance( self )
765
+
766
+ # puts "_prime( #{k} ) loading #{provider}"
767
+
768
+ load plugin_filepath
769
+ end
687
770
 
688
771
  end
689
772
 
@@ -738,7 +821,15 @@ class Sadie
738
821
 
739
822
 
740
823
  # init given path to session file
741
- def _initializeWithSessionFilePath(session_filepath)
824
+ def _initializeWithSessionFilePath( session_filepath )
825
+
826
+ puts "session_filepath: #{session_filepath}"
827
+
828
+ defined?( session_filepath ) \
829
+ or raise "session_filepath was undefined"
830
+
831
+ /^\s*$/.match("#{session_filepath}") \
832
+ and raise "session_filepath was empty string"
742
833
 
743
834
  # bail on non-existant file
744
835
  File.exist?( session_filepath ) \
@@ -766,8 +857,8 @@ class Sadie
766
857
 
767
858
  # init given session id
768
859
  def _initializeWithSessionId(session_id)
769
- session_filepath = File.expand_path( "session."+session_id, get( "sadie.sessions_dirpath" ) )
770
- _initializeWithSessionFilePath(session_filepath)
860
+ session_filepath = File.expand_path( "session."+session_id, _get( "sadie.sessions_dirpath" ) )
861
+ _initializeWithSessionFilePath( session_filepath )
771
862
  end
772
863
 
773
864
  # gen new session id
data/sadie.gemspec CHANGED
@@ -22,6 +22,9 @@ Gem::Specification.new do |s|
22
22
  # s.add_development_dependency "rspec"
23
23
  # s.add_runtime_dependency "rest-client"
24
24
 
25
- s.add_runtime_dependency "ini"
26
-
25
+ #s.add_runtime_dependency "ini"
26
+ s.add_runtime_dependency "dbi"
27
+ s.add_runtime_dependency "mysql"
28
+ s.add_runtime_dependency "dbd-mysql"
29
+
27
30
  end
data/test/README ADDED
@@ -0,0 +1,9 @@
1
+ These tests depend on a mysql database created as follows on the local machine:
2
+
3
+ create database test
4
+ grant all on test.* to test@localhost identified by 'test'
5
+ CREATE TABLE `test` (
6
+ `col1` int(8) DEFAULT NULL,
7
+ `col2` varchar(256) DEFAULT NULL
8
+ )
9
+ INSERT INTO `test` VALUES (1,'testing123'),(2,'testing456');
@@ -1,4 +1,8 @@
1
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
1
+ #$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ #$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
3
+ #$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
4
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+ $:.unshift ENV["GEM_HOME"]
2
6
 
3
7
  require "test/unit"
4
8
  require "sadie"
@@ -22,7 +26,7 @@ class TestSadieToplevel < Test::Unit::TestCase
22
26
  dog1a = sadie.get( "toplevel_destructonget.oneprime" )
23
27
  dog2a = sadie.get( "toplevel_destructonget.twoprime" )
24
28
  dog2b = sadie.get( "toplevel_destructonget.twoprime" )
25
- sleep( 2 )
29
+ sleep( 0.01 )
26
30
  dog1b = sadie.get( "toplevel_destructonget.oneprime" )
27
31
  assert_equal( dog2a, dog2b )
28
32
  assert_not_equal( dog1a, dog1b )
@@ -20,6 +20,23 @@ class TestSadieTwoDeep < Test::Unit::TestCase
20
20
 
21
21
  # test two-deep expensive
22
22
  assert_equal( sadie.get( "expensive.oneprime" ), "primedit" )
23
+
24
+ # test db connection
25
+ dbconx = sadie.get( "two.deep.test.dbi.conx" )
26
+ assert_not_nil( dbconx )
27
+
28
+ # test sql22darray
29
+ tablearray = sadie.get( "two.deep.testquery.test.sql" )
30
+ assert_not_nil( tablearray )
31
+ assert_equal( tablearray[0][0], 1 )
32
+ assert_equal( tablearray[1][1], "testing456" )
33
+
34
+ # test templating
35
+ template_text = sadie.get( "two.deep.test_template.txt.tmpl" )
36
+ template_text = template_text.gsub(/\s+/," ").gsub(/^\s*/,"").gsub(/\s*$/,"")
37
+ # puts "template text\n#{template_text}"
38
+ assert( (template_text.match(/later\s+gator/)), "incorrect match on template text" )
39
+ assert( (template_text.match(/test\/test\_primers/)), "incorrect match on template text" )
23
40
  end
24
41
  end
25
42
  end
@@ -0,0 +1,4 @@
1
+ [connection]
2
+ dbistr = DBI:Mysql:test:127.0.0.1
3
+ user = test
4
+ pass = test
@@ -0,0 +1,10 @@
1
+ <% testmode = "later" %>
2
+ <% animal = "gator" %>
3
+ <% if testmode.eql? "initial" %>
4
+ my first time thru
5
+ <% end %>
6
+ <% if testmode.eql? "later" %>
7
+ later
8
+ <% end %>
9
+ <%= animal %>
10
+ <%= S("sadie.primers_dirpath") %>
@@ -0,0 +1 @@
1
+ select * from test
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sadie
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Fred McDavid
@@ -15,10 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-24 00:00:00 Z
18
+ date: 2012-01-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: ini
21
+ name: dbi
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
@@ -31,6 +31,34 @@ dependencies:
31
31
  version: "0"
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: mysql
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: dbd-mysql
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ version_requirements: *id003
34
62
  description: Sadie is a data framework intended to ease the pain of managing related data.
35
63
  email:
36
64
  - fred@landmetrics.com
@@ -54,7 +82,8 @@ files:
54
82
  - lib/sadie/primer_plugins/DatabaseConnection.plugin.rb
55
83
  - lib/sadie/primer_plugins/IniFile.plugin.rb
56
84
  - lib/sadie/primer_plugins/Resource.plugin.rb
57
- - lib/sadie/primer_plugins/SQLQuery.plugin.rb
85
+ - lib/sadie/primer_plugins/SQLQueryTo2DArray.plugin.rb
86
+ - lib/sadie/primer_plugins/TemplateTextFile.plugin.rb
58
87
  - lib/sadie/version.rb
59
88
  - rdoc/classes/Sadie.html
60
89
  - rdoc/created.rid
@@ -68,6 +97,7 @@ files:
68
97
  - rdoc/index.html
69
98
  - rdoc/rdoc-style.css
70
99
  - sadie.gemspec
100
+ - test/README
71
101
  - test/tc_sadie_toplevel.rb
72
102
  - test/tc_sadie_twodeep.rb
73
103
  - test/test_primers/.gitignore
@@ -78,6 +108,9 @@ files:
78
108
  - test/test_primers/toplevel_single.res.rb
79
109
  - test/test_primers/two/deep/conf.ini
80
110
  - test/test_primers/two/deep/expensive.res
111
+ - test/test_primers/two/deep/test.dbi.conx
112
+ - test/test_primers/two/deep/test_template.txt.tmpl
113
+ - test/test_primers/two/deep/testquery.test.sql
81
114
  - test/test_primers/two/deep/two_results.res
82
115
  homepage: http://www.landmetrics.com/Sadie
83
116
  licenses: []
@@ -1,21 +0,0 @@
1
- # WARNING: THIS DOESN'T WORK YET!!!
2
-
3
- Sadie::registerPrimerPlugin( { "match" => /\.sql$/,
4
- "accepts-block" => true } ) do |sadie, key_prefix, primer_file_filepath, block|
5
-
6
- # read query from file @filepath, ditch newlines
7
- f = open( primer_file_filepath )
8
- query = f.read
9
- close( f )
10
- query = query.gsub(/\n/,'')
11
-
12
- # get the database and run query
13
- db_key = key_prefix+".db.conx"
14
- sadie.get( db_key ) do | dbh |
15
-
16
- # run the query
17
- dbh.select_all( query, block )
18
-
19
- end
20
- raise 'Sadie returned nil for key: #{db_key}'
21
- end