active_extend 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
data/lib/external_migration.rb
CHANGED
@@ -77,7 +77,7 @@ module ExternalMigration
|
|
77
77
|
# Migrate data between data source and transforme to destination
|
78
78
|
#
|
79
79
|
class Migration
|
80
|
-
attr_accessor :schema_from, :schema_to, :transformer, :name
|
80
|
+
attr_accessor :schema_from, :schema_to, :transformer, :name, :processor
|
81
81
|
|
82
82
|
# constructor
|
83
83
|
def initialize(schema_url=nil)
|
@@ -127,18 +127,22 @@ module ExternalMigration
|
|
127
127
|
return true
|
128
128
|
end
|
129
129
|
|
130
|
-
def
|
130
|
+
def migrate_row!(row_to)
|
131
131
|
@line += 1
|
132
132
|
begin
|
133
|
-
|
134
|
-
|
135
|
-
|
133
|
+
if @processor.nil?
|
134
|
+
#transform row to @schema_to
|
135
|
+
res = true
|
136
|
+
res = @transformer.transform(row_to) unless @transformer.nil?
|
136
137
|
|
137
|
-
|
138
|
-
|
139
|
-
|
138
|
+
if (res!=:ignore)
|
139
|
+
res = res==true && send_row_to_schema(row_to)
|
140
|
+
raise_migration if (res==false)
|
140
141
|
|
141
|
-
|
142
|
+
@transformer.after_row_saved(row_to, @last_object) unless @transformer.nil?
|
143
|
+
end
|
144
|
+
else
|
145
|
+
@processor.migrate_row row_to
|
142
146
|
end
|
143
147
|
rescue Exception => e
|
144
148
|
line = @line.nil? ? 0 : @line
|
@@ -16,12 +16,17 @@ module ExternalMigration
|
|
16
16
|
# transformer: class will be called to data transformations
|
17
17
|
class SchemasMigration
|
18
18
|
|
19
|
-
attr_accessor :transformer, :schemas
|
19
|
+
attr_accessor :transformer, :schemas, :processor, :verbose
|
20
20
|
|
21
|
-
def initialize(file_schemas)
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def initialize(file_schemas, schemas=nil)
|
22
|
+
if schemas.nil?
|
23
|
+
raise "Invalid File: should not null!" if file_schemas.nil?
|
24
|
+
raise "Invalid File: should not exists!" if not File.exists?(file_schemas)
|
25
|
+
@schemas = YAML::load(File.open(file_schemas))
|
26
|
+
else
|
27
|
+
@schemas = schemas
|
28
|
+
end
|
29
|
+
@verbose = true
|
25
30
|
end
|
26
31
|
|
27
32
|
def migrate!
|
@@ -33,7 +38,7 @@ module ExternalMigration
|
|
33
38
|
|
34
39
|
msg = "Starting external migration: %s..." % @migration_name
|
35
40
|
Rails.logger.info msg
|
36
|
-
puts msg
|
41
|
+
puts msg if verbose
|
37
42
|
|
38
43
|
result = run_migration_job
|
39
44
|
|
@@ -41,21 +46,21 @@ module ExternalMigration
|
|
41
46
|
|
42
47
|
msg = "Ending: %s." % @migration_name
|
43
48
|
Rails.logger.info msg
|
44
|
-
puts msg
|
49
|
+
puts msg if verbose
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
54
|
+
def run_migration_job
|
55
|
+
transformer_from_schema()
|
56
|
+
|
57
|
+
case @schema[:type]
|
58
|
+
when :SCHEMA
|
59
|
+
self.migrate_schema
|
60
|
+
when :CUSTOM
|
61
|
+
self.migrate_custom
|
58
62
|
end
|
63
|
+
end
|
59
64
|
|
60
65
|
def eval_class(class_str)
|
61
66
|
begin
|
@@ -122,6 +127,7 @@ module ExternalMigration
|
|
122
127
|
migration.schema_from = @schema[:from]
|
123
128
|
migration.schema_to = @schema[:to]
|
124
129
|
migration.transformer = @transformer if not @transformer.nil?
|
130
|
+
migration.processor = @processor if not @processor.nil?
|
125
131
|
#rock!
|
126
132
|
migration.migrate!
|
127
133
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_extend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.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: 2013-
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/external_migration/converters/rtf_to_html.rb
|
59
59
|
- lib/external_migration/dictionary.rb
|
60
60
|
- lib/external_migration/migration.rb
|
61
|
+
- lib/external_migration/migration_processor.rb
|
61
62
|
- lib/external_migration/schemas.rb
|
62
63
|
- lib/external_migration/spelling_fix.rb
|
63
64
|
- lib/external_migration/text_fixed.rb
|