dohruby 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -14,6 +14,12 @@
14
14
  * override Test::Unit::TestCase::run to add setup & teardown hooks (util/testcase_with_hooks)
15
15
  * use this new hook ability to add a teardown hook that calls Doh::clear_current_date (util/test_case)
16
16
  * add util/test_case to the doh/unit_test "include" file
17
+ *0.1.7* (April 7th, 2008)
18
+ * added flush_always to iostreamacceptor
19
+ * make BigDecimal.to_s default behavior be more human readable
20
+ * implement db hash util: insert_hash, update_hash, select_as_hash
21
+ * add logger util: default_logfile_name
22
+ * add set_source_ip function, change default source_ip to 'unknown'
17
23
 
18
24
 
19
25
 
@@ -0,0 +1,8 @@
1
+ require 'bigdecimal'
2
+
3
+ class BigDecimal
4
+ alias :_original_to_s :to_s
5
+ def to_s(format = 'F')
6
+ _original_to_s(format)
7
+ end
8
+ end
data/lib/doh/core.rb CHANGED
@@ -1,2 +1,4 @@
1
+ require 'doh/core/bigdecimal'
2
+ require 'doh/core/date'
1
3
  require 'doh/core/dir'
2
4
  require 'doh/core/string'
@@ -9,6 +9,10 @@ class IOStreamAcceptor
9
9
  @error_formatter = Formatter.new(error_format || format || "%datetime [%severity] : %msg\nexception: %exception\nstack:\n%call_stack")
10
10
  end
11
11
 
12
+ def flush_always(flag = true)
13
+ @flush = flag
14
+ end
15
+
12
16
  def log(event)
13
17
  if event.severity >= ERROR
14
18
  curr_formatter = @error_formatter
@@ -16,6 +20,7 @@ class IOStreamAcceptor
16
20
  curr_formatter = @standard_formatter
17
21
  end
18
22
  @ios.puts(curr_formatter.replace(event))
23
+ @ios.fsync if @flush
19
24
  end
20
25
  end
21
26
 
@@ -0,0 +1,7 @@
1
+ module DohLogger
2
+
3
+ def self.default_logfile_name
4
+ File.basename($0, '.rb') + '.log'
5
+ end
6
+
7
+ end
@@ -0,0 +1,40 @@
1
+ module DohDb
2
+
3
+ class Handle
4
+ def insert_hash(hash, table)
5
+ names = []
6
+ values = []
7
+ hash.each_pair do |key, value|
8
+ next if value.nil?
9
+ names.push(key)
10
+ values.push(value.to_sql)
11
+ end
12
+ insert("INSERT INTO #{table} (#{names.join(',')}) VALUES (#{values.join(',')})")
13
+ end
14
+
15
+ def update_hash(hash, table, primary_key_value, primary_key_name)
16
+ items = hash.keys.collect {|key| key + ' = ' + hash[key].to_sql}
17
+ query("UPDATE #{table} SET #{items.join(', ')} WHERE #{primary_key_name} = #{primary_key_value}")
18
+ end
19
+
20
+ def select_as_hash(statement, row_builder = nil)
21
+ select(statement, row_builder).inject(Hash.new) do |hash, row|
22
+ hash[row.at(0)] = row.at(1)
23
+ hash
24
+ end
25
+ end
26
+ end
27
+
28
+ def self.insert_hash(hash, table)
29
+ request_handle.insert_hash(hash, table)
30
+ end
31
+
32
+ def self.update_hash(hash, table, primary_key_value, primary_key_name)
33
+ request_handle.update_hash(hash, table, primary_key_value, primary_key_name)
34
+ end
35
+
36
+ def self.select_as_hash(statement, row_builder = nil)
37
+ request_handle.select_as_hash(statement, row_builder)
38
+ end
39
+
40
+ end
@@ -1,3 +1,4 @@
1
+ require 'bigdecimal'
1
2
  require 'date'
2
3
  require 'mysql'
3
4
 
data/lib/doh/unit_test.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'doh/util/unit_test_logging'
2
- require 'doh/util/test_case'
2
+ require 'test/unit'
@@ -4,7 +4,11 @@ module Doh
4
4
 
5
5
  @@source_ip = nil
6
6
  def self.source_ip
7
- @@source_ip ||= Socket.getaddrinfo(Socket.gethostname, Socket::AF_INET).find {|elem| elem[0] == 'AF_INET'}[3]
7
+ @@source_ip ||= 'unknown'
8
+ end
9
+
10
+ def self.set_source_ip(source_ip)
11
+ @@source_ip = source_ip
8
12
  end
9
13
 
10
14
  end
@@ -9,10 +9,10 @@ end
9
9
 
10
10
  require 'doh/logger_app'
11
11
  require 'doh/logger/memory_acceptor'
12
+ require 'doh/logger/util'
12
13
 
13
14
  scheduler = DohLogger::DirectScheduler.new
14
- logfile_name = File.basename($0, '.rb') + '.log'
15
- file_acceptor = DohLogger::IOStreamAcceptor.new(File.new(logfile_name, "wb"))
15
+ file_acceptor = DohLogger::IOStreamAcceptor.new(File.new(DohLogger::default_logfile_name, "wb"))
16
16
  $doh_unit_test_error_acceptor = DohLogger::MemoryAcceptor.new
17
17
  intrfc = DohLogger::StandardInterface.new(scheduler)
18
18
  intrfc.add_acceptor(DohLogger::DEBUG, file_acceptor)
@@ -7,13 +7,13 @@ class TC_Event < Test::Unit::TestCase
7
7
  def test_call_stack
8
8
  event = DohLogger::Event.new(1, '')
9
9
  stack = event.call_stack
10
- assert_equal('tc_event', stack[0].before('.rb:').rafter('/'))
10
+ assert_match(/tc_event\.rb/, stack[0])
11
11
  begin
12
12
  raise Exception.new('smoe')
13
13
  rescue Exception => e
14
14
  event = DohLogger::Event.new(1, '', e)
15
15
  stack = event.call_stack
16
- assert_equal('tc_event', stack[0].before('.rb:').rafter('/'))
16
+ assert_match(/tc_event\.rb/, stack[0])
17
17
  end
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dohruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Makani & Kem Mason
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-02 00:00:00 -06:00
12
+ date: 2008-04-07 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -37,6 +37,7 @@ files:
37
37
  - bin/run_tests.rb
38
38
  - lib/doh
39
39
  - lib/doh/core
40
+ - lib/doh/core/bigdecimal.rb
40
41
  - lib/doh/core/date.rb
41
42
  - lib/doh/core/dir.rb
42
43
  - lib/doh/core/string.rb
@@ -52,6 +53,7 @@ files:
52
53
  - lib/doh/logger/null_interface.rb
53
54
  - lib/doh/logger/severity.rb
54
55
  - lib/doh/logger/standard_interface.rb
56
+ - lib/doh/logger/util.rb
55
57
  - lib/doh/logger.rb
56
58
  - lib/doh/logger_app.rb
57
59
  - lib/doh/mysql
@@ -62,6 +64,7 @@ files:
62
64
  - lib/doh/mysql/default_type_guesser.rb
63
65
  - lib/doh/mysql/error.rb
64
66
  - lib/doh/mysql/handle.rb
67
+ - lib/doh/mysql/hash_util.rb
65
68
  - lib/doh/mysql/parse.rb
66
69
  - lib/doh/mysql/raw_row_builder.rb
67
70
  - lib/doh/mysql/readonly_row.rb
@@ -76,8 +79,6 @@ files:
76
79
  - lib/doh/util/options.rb
77
80
  - lib/doh/util/run_tests.rb
78
81
  - lib/doh/util/source_ip.rb
79
- - lib/doh/util/test_case.rb
80
- - lib/doh/util/testcase_with_hooks.rb
81
82
  - lib/doh/util/unit_test_logging.rb
82
83
  - lib/doh.rb
83
84
  - test/core
@@ -1,13 +0,0 @@
1
- require 'doh/util/testcase_with_hooks'
2
- require 'doh/util/current_date'
3
- Test::Unit::TestCase.add_teardown_hook("doh_teardown")
4
-
5
- module Test
6
- module Unit
7
- class TestCase
8
- def doh_teardown
9
- Doh::clear_current_date
10
- end
11
- end
12
- end
13
- end
@@ -1,55 +0,0 @@
1
- require 'test/unit'
2
-
3
- module Test
4
- module Unit
5
- class TestCase
6
- @@setup_hooks = []
7
- @@teardown_hooks = []
8
-
9
- def self.add_setup_hook(method_name)
10
- @@setup_hooks.push(method_name)
11
- end
12
-
13
- def self.add_teardown_hook(method_name)
14
- @@teardown_hooks.push(method_name)
15
- end
16
-
17
- # NOTE: this is an exact copy from the original implementation, it will (of course) need to be kept up-to-date
18
- # except the call of "setup" has been replaced with "setup_with_hooks" and "teardown" with "teardown_with_hooks"
19
- def run(result)
20
- yield(STARTED, name)
21
- @_result = result
22
- begin
23
- setup_with_hooks
24
- __send__(@method_name)
25
- rescue AssertionFailedError => e
26
- add_failure(e.message, e.backtrace)
27
- rescue Exception
28
- raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
29
- add_error($!)
30
- ensure
31
- begin
32
- teardown_with_hooks
33
- rescue AssertionFailedError => e
34
- add_failure(e.message, e.backtrace)
35
- rescue Exception
36
- raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
37
- add_error($!)
38
- end
39
- end
40
- result.add_run
41
- yield(FINISHED, name)
42
- end
43
-
44
- def setup_with_hooks
45
- @@setup_hooks.each {|elem| __send__(elem)}
46
- setup
47
- end
48
-
49
- def teardown_with_hooks
50
- teardown
51
- @@teardown_hooks.each {|elem| __send__(elem)}
52
- end
53
- end
54
- end
55
- end