transplant 0.1.2 → 0.1.3
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/lib/transplant/planter.rb +6 -5
- data/lib/transplant/stats.rb +47 -34
- data/lib/transplant/version.rb +1 -1
- metadata +4 -4
data/lib/transplant/planter.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module Transplant
|
2
2
|
class Planter
|
3
3
|
|
4
|
-
attr_accessor :app_name, :connection
|
4
|
+
attr_accessor :app_name, :connection, :statistician
|
5
5
|
|
6
6
|
def initialize(app_name, connection)
|
7
7
|
@app_name = app_name
|
8
8
|
@connection = connection
|
9
|
+
@statistician = Stats.new(self)
|
9
10
|
@queries ||= []
|
10
11
|
@results ||= {}
|
11
12
|
end
|
@@ -24,10 +25,10 @@ module Transplant
|
|
24
25
|
klass
|
25
26
|
else
|
26
27
|
fail(klass_name)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
@statistician.output "Invalid #{klass_name} information:"
|
29
|
+
@statistician.output("Additional Info about #{klass_name}", other)
|
30
|
+
@statistician.output("#{klass_name} errors", klass.errors.full_messages)
|
31
|
+
@statistician.output("#{klass_name} attributes", klass.attributes)
|
31
32
|
return false
|
32
33
|
end
|
33
34
|
end
|
data/lib/transplant/stats.rb
CHANGED
@@ -2,6 +2,7 @@ module Transplant
|
|
2
2
|
class Stats
|
3
3
|
|
4
4
|
def initialize(transplanter)
|
5
|
+
@result_set = []
|
5
6
|
@planter = transplanter
|
6
7
|
end
|
7
8
|
|
@@ -10,70 +11,82 @@ module Transplant
|
|
10
11
|
total_import_records
|
11
12
|
successes
|
12
13
|
failures
|
14
|
+
output_to_file
|
13
15
|
end
|
14
16
|
|
15
|
-
|
17
|
+
def output_to_file
|
18
|
+
timestamp = Time.now.utc.to_datetime.to_formatted_s(:number)
|
19
|
+
Dir.chdir Rails.root
|
20
|
+
filepath = ".import.#{timestamp}_#{@planter.app_name.downcase}"
|
21
|
+
f = File.open(filepath, "w")
|
22
|
+
@result_set.each { |output| f.puts output }
|
23
|
+
f.close
|
24
|
+
end
|
16
25
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
elsif input.is_a? Array
|
21
|
-
array_output(header, input, depth, sub_output)
|
22
|
-
end
|
23
|
-
end
|
26
|
+
def add_to_results(output)
|
27
|
+
@result_set << output
|
28
|
+
end
|
24
29
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
30
|
+
def output(header, input = {}, depth = 0, sub_output = false)
|
31
|
+
if input.is_a? Hash
|
32
|
+
hash_output(header, input, depth, sub_output)
|
33
|
+
elsif input.is_a? Array
|
34
|
+
array_output(header, input, depth, sub_output)
|
35
|
+
elsif input.is_a? String
|
36
|
+
add_to_results input
|
34
37
|
end
|
38
|
+
end
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
40
|
+
def hash_output(header, hash, depth = 0, sub_hash = false)
|
41
|
+
add_to_results tabs(depth) + "#{header}:" if hash.any? && header.present?
|
42
|
+
hash.each_pair do |key, value|
|
43
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
44
|
+
output(key, value, depth + 1, sub_hash = true)
|
45
|
+
else
|
46
|
+
add_to_results tabs(depth + 1) + "* #{key}: #{value}"
|
44
47
|
end
|
45
48
|
end
|
49
|
+
end
|
46
50
|
|
47
|
-
|
48
|
-
|
51
|
+
def array_output(header, array, depth = 0, sub_array = false)
|
52
|
+
add_to_results tabs(depth) + "#{header}:" if array.any? && header.present?
|
53
|
+
array.each do |item|
|
54
|
+
if item.is_a?(Hash) || item.is_a?(Array)
|
55
|
+
output("", item, depth + 1, sub_hash = true)
|
56
|
+
else
|
57
|
+
add_to_results tabs(depth + 1) + "* #{item}"
|
58
|
+
end
|
49
59
|
end
|
50
|
-
|
60
|
+
end
|
51
61
|
|
62
|
+
def tabs(count)
|
63
|
+
"\t"*count
|
52
64
|
end
|
65
|
+
private :tabs
|
53
66
|
|
54
67
|
def total_import_records
|
55
|
-
|
68
|
+
add_to_results "Estimated number of records imported into #{@planter.app_name}: #{@planter.total_successes}"
|
56
69
|
end
|
57
70
|
|
58
71
|
def total_import_time(m)
|
59
|
-
|
72
|
+
add_to_results "Total time taken to import everything into #{@planter.app_name}: #{(m.real/60).round(2)} minutes"
|
60
73
|
end
|
61
74
|
|
62
75
|
def successes
|
63
76
|
if @planter.successes.count <= 0
|
64
|
-
|
77
|
+
add_to_results "\nNo records were imported! Boo!!!!\n"
|
65
78
|
else
|
66
79
|
count = Hash[@planter.successes.map { |key, value| [key.tableize.humanize, value] }]
|
67
|
-
|
80
|
+
output("\nEstimated number of successful imports to #{@planter.app_name}", count)
|
68
81
|
end
|
69
82
|
end
|
70
83
|
|
71
84
|
def failures
|
72
85
|
if @planter.failures.count <= 0
|
73
|
-
|
86
|
+
add_to_results "\nNo failed record imports!!!! Time to par-tay!!!!\n"
|
74
87
|
else
|
75
88
|
count = Hash[@planter.failures.map { |key, value| [key.tableize.humanize, value] }]
|
76
|
-
|
89
|
+
output("\nEstimated number failed imports to #{@planter.app_name}", count)
|
77
90
|
end
|
78
91
|
end
|
79
92
|
|
data/lib/transplant/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transplant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
segments:
|
109
109
|
- 0
|
110
|
-
hash:
|
110
|
+
hash: 1015560238026182920
|
111
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
112
|
none: false
|
113
113
|
requirements:
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
segments:
|
118
118
|
- 0
|
119
|
-
hash:
|
119
|
+
hash: 1015560238026182920
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
122
|
rubygems_version: 1.8.21
|