dohruby 0.1.28 → 0.1.29
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/bin/create_database.rb +16 -0
- data/bin/repeat_test.rb +11 -0
- data/lib/doh/app/activate_logger.rb +2 -2
- data/lib/doh/app/init_runnable.rb +1 -1
- data/lib/doh/app_pwd.rb +3 -0
- data/lib/doh/app_util.rb +1 -0
- data/lib/doh/data/basic.rb +5 -0
- data/lib/doh/data/bulk.rb +7 -0
- data/lib/doh/data/human.rb +40 -0
- data/lib/doh/logger/event.rb +1 -1
- data/lib/doh/merb/notify_on_exception.rb +12 -0
- data/lib/doh/merb/post_hash.rb +26 -0
- data/lib/doh/merb.rb +2 -0
- data/lib/doh/mysql/metadata_util.rb +32 -0
- data/lib/doh/unit_test_create_db.rb +7 -0
- metadata +11 -2
data/CHANGELOG
CHANGED
@@ -84,3 +84,13 @@
|
|
84
84
|
* rework DohApp stuff to be simpler and more flexible
|
85
85
|
*0.1.28* (May 30th, 2008)
|
86
86
|
* add configuration ability to DohApp framework
|
87
|
+
*0.1.29* (Jun 11th, 2008)
|
88
|
+
* add default mail_server = localhost to default debug config
|
89
|
+
* add more us human data generation methods
|
90
|
+
* made default max log entry length 4096 instead of 1024
|
91
|
+
* added create_database.rb to bin directory
|
92
|
+
* added metadata_util.rb to mysql
|
93
|
+
* added unit_test_create_db.rb
|
94
|
+
* added merb library
|
95
|
+
* added random_date, random_country_code, random_ip_address to data random generation
|
96
|
+
* added repeat_test.rb to bin directory
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'doh/app_pwd'
|
3
|
+
require 'doh/mysql/database_creator'
|
4
|
+
|
5
|
+
opts = DohApp::Options.new(
|
6
|
+
{'drop_first' => [false, "-z", "--drop_first", "if true, will drop the database before creating it"] \
|
7
|
+
,'database' => [DohApp::config['primary_database'], "-d", "--database <database>", "name of the database to create -- defaults to config['primary_database'], currently '#{DohApp::config['primary_database']}'"] \
|
8
|
+
,'all' => [false, "-a", "--all", "create all databases"] \
|
9
|
+
})
|
10
|
+
|
11
|
+
db_creator = DohDb::DatabaseCreator.new
|
12
|
+
if opts.all
|
13
|
+
db_creator.create_all_databases(opts.drop_first)
|
14
|
+
else
|
15
|
+
db_creator.create_database(opts.database, opts.drop_first)
|
16
|
+
end
|
data/bin/repeat_test.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
file_to_run = ARGV[0]
|
4
|
+
repeat_count = (ARGV[1] || 10000).to_i
|
5
|
+
|
6
|
+
while (repeat_count > 0) do
|
7
|
+
puts "running #{file_to_run} #{repeat_count} more times (or until it fails)"
|
8
|
+
repeat_count -= 1
|
9
|
+
system("run_tests.rb #{file_to_run}")
|
10
|
+
exit if $?.exitstatus != 0
|
11
|
+
end
|
@@ -46,7 +46,7 @@ def self.activate_logger
|
|
46
46
|
require 'doh/logger/email_acceptor'
|
47
47
|
mail_server = root_cfg['mail_server'] || 'mail.' + root_cfg['domain_name']
|
48
48
|
from_address = acceptor_cfg['from_address'] || 'notify@' + root_cfg['domain_name']
|
49
|
-
to_address_list = acceptor_cfg['to_address_list'] || ['
|
49
|
+
to_address_list = acceptor_cfg['to_address_list'] || ['root@localhost']
|
50
50
|
notify_acceptor = DohLogger::EmailAcceptor.new(mail_server, from_address, to_address_list, logfile_name, nil, DohLogger::exceptionless_email_format)
|
51
51
|
Doh::log.add_acceptor(DohLogger::NOTIFY, notify_acceptor, true)
|
52
52
|
end
|
@@ -55,7 +55,7 @@ def self.activate_logger
|
|
55
55
|
require 'doh/logger/email_acceptor'
|
56
56
|
mail_server = root_cfg['mail_server'] || 'mail.' + root_cfg['domain_name']
|
57
57
|
from_address = acceptor_cfg['from_address'] || 'error@' + root_cfg['domain_name']
|
58
|
-
to_address_list = acceptor_cfg['to_address_list'] || ['
|
58
|
+
to_address_list = acceptor_cfg['to_address_list'] || ['root@localhost']
|
59
59
|
error_acceptor = DohLogger::EmailAcceptor.new(mail_server, from_address, to_address_list, logfile_name)
|
60
60
|
Doh::log.add_acceptor(DohLogger::ERROR, error_acceptor)
|
61
61
|
end
|
@@ -18,7 +18,7 @@ def self.use_default_runnable_development_config
|
|
18
18
|
logger_cfg = {'file_acceptor' => file_acceptor_cfg, 'stdout_acceptor' => stdout_acceptor_cfg}
|
19
19
|
root_cfg['logger'] = logger_cfg
|
20
20
|
root_cfg['enable_logger'] = true
|
21
|
-
|
21
|
+
root_cfg['mail_server'] = 'localhost'
|
22
22
|
root_cfg['database'] = {'username' => 'root', 'host' => 'localhost'}
|
23
23
|
end
|
24
24
|
|
data/lib/doh/app_pwd.rb
ADDED
data/lib/doh/app_util.rb
CHANGED
data/lib/doh/data/basic.rb
CHANGED
data/lib/doh/data/bulk.rb
CHANGED
@@ -129,4 +129,11 @@ module DohData
|
|
129
129
|
|
130
130
|
@@employers = ['Google', 'Geeks R Us', 'Home Depot', 'Wal-Mart', 'Shopko', "Wendy's", "Staples", "E-Bay", "McDonald's", "Computer World", "OfficeMax"]
|
131
131
|
|
132
|
+
@@generation_options = ['I', 'II', 'III', 'IV', 'Jr', 'Sr']
|
133
|
+
|
134
|
+
@@us_state_abbreviations = ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY']
|
135
|
+
@@us_state_long_names = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'District of Columbia', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']
|
136
|
+
|
137
|
+
@@occupations = ['Software Developer', 'Cashiers', 'Waiter', 'Waitress', 'Customer service', 'Laborer', 'Carpenter', 'Landscaping', 'Janitor', 'Sales', 'Nurse', 'Medical assistant', 'Bodyshop Technician', 'Finance Director', 'HR Manager', 'Parts Person', 'Regional Manager', 'Sales Executive', 'Sales Manager', 'Manager', 'Receptionist', 'Technician', 'Used Car Sales', 'Website Administrator', 'Workshop Foreman']
|
138
|
+
|
132
139
|
end
|
data/lib/doh/data/human.rb
CHANGED
@@ -11,6 +11,34 @@ def self.random_last_name
|
|
11
11
|
random_element(@@last_names)
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.random_generation
|
15
|
+
random_element(@@generation_options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.random_us_state_abbreviation
|
19
|
+
random_element(@@us_state_abbreviations)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.random_us_state_long_name
|
23
|
+
random_element(@@us_state_long_names)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.random_occupation
|
27
|
+
random_element(@@occupations)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.random_us_state
|
31
|
+
(rand(2) == 0) ? DohData::random_us_state_abbreviation : DohData::random_us_state_long_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.random_us_zip
|
35
|
+
random_digits(5) + ((rand(4) == 0) ? '-' + random_digits(4) : '')
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.random_us_phone
|
39
|
+
random_range(200,999).to_s + '-' + random_digits(3) + '-' + random_digits(4)
|
40
|
+
end
|
41
|
+
|
14
42
|
def self.random_full_name
|
15
43
|
random_first_name + ' ' + random_last_name
|
16
44
|
end
|
@@ -83,4 +111,16 @@ def self.random_employer_name
|
|
83
111
|
random_element(@@employers)
|
84
112
|
end
|
85
113
|
|
114
|
+
def self.random_relation
|
115
|
+
random_element(['cousin', 'mother', 'father', 'aunt', 'uncle', 'brother', 'sister', 'son', 'daughter'])
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.random_country_code
|
119
|
+
random_element(['USA', 'MEX', 'CAN'])
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.random_ip_address
|
123
|
+
"#{rand(256)}.#{rand(256)}.#{rand(256)}.#{rand(256)}"
|
124
|
+
end
|
125
|
+
|
86
126
|
end
|
data/lib/doh/logger/event.rb
CHANGED
@@ -6,7 +6,7 @@ module DohLogger
|
|
6
6
|
|
7
7
|
class Event < OpenStruct
|
8
8
|
def initialize(severity, msg, excpt = nil)
|
9
|
-
msg = msg.gsub(/\n/, '\n').gsub(/\r/, '\r').gsub(/\t/, '\t').firstn(
|
9
|
+
msg = msg.gsub(/\n/, '\n').gsub(/\r/, '\r').gsub(/\t/, '\t').firstn(4096)
|
10
10
|
super('severity' => severity, 'msg' => msg, 'exception' => excpt, 'time' => Time.now)
|
11
11
|
end
|
12
12
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'rexml/document'
|
4
|
+
|
5
|
+
module DohMerb
|
6
|
+
|
7
|
+
def self.hash_to_xml(hash, base_node = 'root')
|
8
|
+
builder = REXML::Document.new
|
9
|
+
builder << REXML::XMLDecl.new
|
10
|
+
base = builder.add_element(base_node)
|
11
|
+
hash.each_pair do |field, value|
|
12
|
+
base.add_element(field).add_text(value.to_s)
|
13
|
+
end
|
14
|
+
builder.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.post_hash(hash, base_node = 'root', url = 'http://localhost:4000/')
|
18
|
+
uri = URI.parse(url)
|
19
|
+
xml = hash_to_xml(hash, base_node)
|
20
|
+
Net::HTTP.start(uri.host, uri.port) do |httpreq|
|
21
|
+
httpreq.read_timeout = 30;
|
22
|
+
response = httpreq.post(uri.path, xml, {'Connection' => 'close', 'Content-Type' => 'text/xml'}).body.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/doh/merb.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'doh/mysql'
|
2
|
+
|
3
|
+
module Doh
|
4
|
+
|
5
|
+
@@cached_table_info = {}
|
6
|
+
|
7
|
+
def self.chop_strings(table, row, ignore_non_db_fields = true, log = false)
|
8
|
+
result = ignore_non_db_fields ? {} : row.dup
|
9
|
+
self.column_info(table).each do |field, size, data_type|
|
10
|
+
Doh::log.debug("processing field: #{field.inspect}, size: #{size.inspect}, data_type: #{data_type.inspect}") if log
|
11
|
+
result[field] = row[field]
|
12
|
+
if row.keys.include?(field) && ['char', 'varchar'].include?(data_type.downcase) && row[field] && row[field].size > size.to_i
|
13
|
+
Doh::log.info("chopping field: #{row[field].inspect} to #{size} chars.") if log
|
14
|
+
result[field] = result[field].to_s[0, size.to_i]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
result
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.column_info(table)
|
21
|
+
return @@cached_table_info[table] if @@cached_table_info[table]
|
22
|
+
@@cached_table_info[table] = query_column_info(table)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.query_column_info(table)
|
26
|
+
column_info = DohDb::select("SELECT column_name, character_maximum_length, data_type FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='#{table}'")
|
27
|
+
column_info = column_info.collect {|column| [column['column_name'], column['character_maximum_length'], column['data_type']]}
|
28
|
+
Doh::log.debug("got column info for table: #{table}, info: #{column_info.inspect}")
|
29
|
+
column_info
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'doh/mysql/database_creator'
|
2
|
+
|
3
|
+
#kjmtodo -- mak possibly combine this with doh/unit_test ??
|
4
|
+
|
5
|
+
dbconfig = DohApp::config['database']
|
6
|
+
DohDb::set_connector_instance(DohDb::CacheConnector.new(dbconfig['host'], dbconfig['username'], dbconfig['password'], nil, DohApp::config['row_builder']))
|
7
|
+
DohDb::DatabaseCreator.new.create_database_copy('dohruby_unit_test_' + DohApp::config['primary_database'], DohApp::config['primary_database'], true)
|
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.
|
4
|
+
version: 0.1.29
|
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-
|
12
|
+
date: 2008-06-11 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -33,7 +33,9 @@ extra_rdoc_files:
|
|
33
33
|
- MIT-LICENSE
|
34
34
|
- CHANGELOG
|
35
35
|
files:
|
36
|
+
- bin/create_database.rb
|
36
37
|
- bin/rcov-preprocess-files.rb
|
38
|
+
- bin/repeat_test.rb
|
37
39
|
- bin/run_tests.rb
|
38
40
|
- lib/doh
|
39
41
|
- lib/doh/app
|
@@ -46,6 +48,7 @@ files:
|
|
46
48
|
- lib/doh/app/init_unit_test.rb
|
47
49
|
- lib/doh/app/options.rb
|
48
50
|
- lib/doh/app.rb
|
51
|
+
- lib/doh/app_pwd.rb
|
49
52
|
- lib/doh/app_util.rb
|
50
53
|
- lib/doh/core
|
51
54
|
- lib/doh/core/bigdecimal.rb
|
@@ -72,6 +75,10 @@ files:
|
|
72
75
|
- lib/doh/logger/util.rb
|
73
76
|
- lib/doh/logger.rb
|
74
77
|
- lib/doh/logger_configure.rb
|
78
|
+
- lib/doh/merb
|
79
|
+
- lib/doh/merb/notify_on_exception.rb
|
80
|
+
- lib/doh/merb/post_hash.rb
|
81
|
+
- lib/doh/merb.rb
|
75
82
|
- lib/doh/mysql
|
76
83
|
- lib/doh/mysql/cache_connector.rb
|
77
84
|
- lib/doh/mysql/connector_instance.rb
|
@@ -85,6 +92,7 @@ files:
|
|
85
92
|
- lib/doh/mysql/handle.rb
|
86
93
|
- lib/doh/mysql/hash_util.rb
|
87
94
|
- lib/doh/mysql/load_sql.rb
|
95
|
+
- lib/doh/mysql/metadata_util.rb
|
88
96
|
- lib/doh/mysql/parse.rb
|
89
97
|
- lib/doh/mysql/raw_row_builder.rb
|
90
98
|
- lib/doh/mysql/readonly_row.rb
|
@@ -93,6 +101,7 @@ files:
|
|
93
101
|
- lib/doh/mysql/unquoted.rb
|
94
102
|
- lib/doh/mysql.rb
|
95
103
|
- lib/doh/unit_test.rb
|
104
|
+
- lib/doh/unit_test_create_db.rb
|
96
105
|
- lib/doh/util
|
97
106
|
- lib/doh/util/blank_slate.rb
|
98
107
|
- lib/doh/util/current_date.rb
|