transplant 0.0.1 → 0.1.0

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Custom Rails Importer
1
+ # Transplant
2
2
 
3
- The gem was born from a need for the organization I work for ([CollegePlus](http://collegeplus.org)). We were migrating our systems from one, single, monolithic system into a Service Oriented Architecture (SOA) using Rails and needed a way to do this as easily as possible. Thus, **Custom Rails Importer** was born.
3
+ The gem was born from a need for the organization I work for ([CollegePlus](http://collegeplus.org)). We were migrating our systems from one, single, monolithic system into a Service Oriented Architecture (SOA) using Rails and needed a way to do this as easily as possible. Thus, **Transplant** was born.
4
4
 
5
5
  #### Currently, you can only import data from a MySQL database. I hope to have this gem be database agnostic in the future.
6
6
 
@@ -8,7 +8,7 @@ The gem was born from a need for the organization I work for ([CollegePlus](http
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- gem 'custom_rails_importer'
11
+ gem 'transplant'
12
12
 
13
13
  And then execute:
14
14
 
@@ -16,7 +16,7 @@ And then execute:
16
16
 
17
17
  Or install it yourself as:
18
18
 
19
- $ gem install custom_rails_importer
19
+ $ gem install transplant
20
20
 
21
21
  ## Usage
22
22
 
@@ -0,0 +1,69 @@
1
+ module Transplant
2
+ class Planter
3
+
4
+ attr_accessor :app_name, :connection
5
+
6
+ def initialize(app_name, connection)
7
+ @app_name = app_name
8
+ @connection = connection
9
+ end
10
+
11
+ def query(sql)
12
+ @connection.execute sql
13
+ end
14
+
15
+ def save(klass, other = {})
16
+ klass_name = klass.class.to_s.tableize.humanize
17
+ if klass.valid?
18
+ klass.save!
19
+ increment
20
+ klass
21
+ else
22
+ increment_failure(klass.class.to_s)
23
+ puts "Invalid #{klass_name} information:"
24
+ Stats.output("Additional Info about #{klass_name}", other)
25
+ Stats.output("#{klass_name} errors", klass.errors.full_messages)
26
+ Stats.output("#{klass_name} attributes:", klass.attributes)
27
+ return false
28
+ end
29
+ end
30
+
31
+ def tables
32
+ return @tables if @tables.present?
33
+ @tables ||= @connection.tables
34
+ @tables.delete 'schema_migrations'
35
+ @tables
36
+ end
37
+
38
+ def truncate(*tables)
39
+ tables.each { |table| self.query "TRUNCATE TABLE #{table.to_s}" }
40
+ end
41
+
42
+ def truncate_all
43
+ truncate *tables
44
+ end
45
+
46
+ def increment
47
+ @total_records ||= 0
48
+ @total_records += 1
49
+ end
50
+
51
+ def increment_failure(klass_name)
52
+ @failures ||= Hash.new
53
+ @failures[klass_name] ||= 0
54
+ @failures[klass_name] += 1
55
+ end
56
+
57
+ def failures
58
+ @failures
59
+ rescue
60
+ @failures ||= Hash.new
61
+ end
62
+
63
+ def total_records
64
+ @total_records
65
+ rescue
66
+ @total_records ||= Hash.new
67
+ end
68
+ end
69
+ end
@@ -8,7 +8,7 @@ module Transplant
8
8
  def output_all_info(opts = {})
9
9
  total_import_time(opts[:measurement]) if opts[:measurement].present?
10
10
  total_import_records
11
- failures
11
+ @transplanter.failures
12
12
  end
13
13
 
14
14
  def self.output(header, input, depth = 0, sub_output = false)
@@ -46,11 +46,11 @@ module Transplant
46
46
  end
47
47
 
48
48
  def total_import_records
49
- puts "\nTotal number of records imported into #{Manager.app_name}: #{@transplanter.total_records}"
49
+ puts "\nTotal number of records imported into #{@transplanter.app_name}: #{@transplanter.total_records}"
50
50
  end
51
51
 
52
52
  def total_import_time(measurement)
53
- puts "Total time taken to import everything into #{Manager.app_name}"
53
+ puts "Total time taken to import everything into #{@transplanter.app_name}"
54
54
  puts measurement
55
55
  end
56
56
 
@@ -59,7 +59,7 @@ module Transplant
59
59
  puts "\nNo failed record imports!!!! Time to par-tay!!!!\n"
60
60
  else
61
61
  failures = Hash[@transplanter.failures.map { |key, value| [key.tableize.humanize, value] }]
62
- Stats.output("\nTotal number failed imports to #{Manager.app_name}:", failures)
62
+ self.class.output("\nTotal number failed imports to #{@transplanter.app_name}:", failures)
63
63
  end
64
64
  end
65
65
 
@@ -1,3 +1,3 @@
1
1
  module Transplant
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/transplant.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'active_support/all'
2
+
1
3
  require "transplant/version"
2
4
  require "transplant/stats"
3
5
  require "transplant/manager"
data/transplant.gemspec CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
5
5
  gem.authors = ["Matt Bridges"]
6
6
  gem.email = ["mbridges.91@gmail.com"]
7
7
  gem.description = %q{Transplant your data from your old database into your new Rails application}
8
- gem.summary = %q{Transplant your data from your old database into your new Rails application}
8
+ gem.summary = %q{Transplant your data from your old database into your new Rails application}
9
9
  gem.homepage = "http://github.com/mattdbridges/transplant"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
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.0.1
4
+ version: 0.1.0
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-03-31 00:00:00.000000000 Z
12
+ date: 2012-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -89,7 +89,7 @@ files:
89
89
  - README.md
90
90
  - Rakefile
91
91
  - lib/transplant.rb
92
- - lib/transplant/manager.rb
92
+ - lib/transplant/planter.rb
93
93
  - lib/transplant/stats.rb
94
94
  - lib/transplant/version.rb
95
95
  - transplant.gemspec
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  segments:
109
109
  - 0
110
- hash: -4175224259072295896
110
+ hash: -739698848193988956
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: -4175224259072295896
119
+ hash: -739698848193988956
120
120
  requirements: []
121
121
  rubyforge_project:
122
122
  rubygems_version: 1.8.21
@@ -1,73 +0,0 @@
1
- module Transplant
2
- class Manager
3
-
4
- cattr_accessor :app_name
5
-
6
- def self.connect(app_name, mysql_credentials = {}, local_conn)
7
- @@app_name = app_name
8
- @@remote = Mysql2::Client.new mysql_credentials
9
- @@local ||= local_conn
10
- end
11
-
12
- def self.local(sql)
13
- @@local.execute sql
14
- end
15
-
16
- def self.save(klass, other = {})
17
- nice_class_name = klass.class.to_s.tableize.humanize
18
- if klass.valid?
19
- klass.save!
20
- increment
21
- klass
22
- else
23
- increment_failure(klass.class.to_s)
24
- puts "Invalid #{nice_class_name} information:"
25
- Stats.output("Additional Info about #{nice_class_name}", other)
26
- Stats.output("#{nice_class_name} errors", klass.errors.full_messages)
27
- Stats.output("#{nice_class_name} attributes:", klass.attributes)
28
- return false
29
- end
30
- end
31
-
32
- def self.remote(sql)
33
- @@remote.query(sql)
34
- end
35
-
36
- def self.local_tables
37
- tables = @@local.tables
38
- tables.delete 'schema_migrations'
39
- tables
40
- end
41
-
42
- def self.local_truncate(*tables)
43
- tables.each { |table| local "TRUNCATE TABLE #{table.to_s}" }
44
- end
45
-
46
- def self.local_truncate_all
47
- local_truncate *local_tables
48
- end
49
-
50
- def self.increment
51
- @@total_records ||= 0
52
- @@total_records += 1
53
- end
54
-
55
- def self.increment_failure(klass_name)
56
- @@failures ||= Hash.new
57
- @@failures[klass_name] ||= 0
58
- @@failures[klass_name] += 1
59
- end
60
-
61
- def self.failures
62
- @@failures
63
- rescue
64
- @@failures ||= Hash.new
65
- end
66
-
67
- def self.total_records
68
- @@total_records
69
- rescue
70
- @@total_records ||= Hash.new
71
- end
72
- end
73
- end