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.
@@ -1,3 +1,3 @@
1
1
  module ActiveExtend
2
- VERSION = "0.0.2".freeze
2
+ VERSION = "0.0.3".freeze
3
3
  end
@@ -3,6 +3,7 @@ require 'spreadsheet'
3
3
 
4
4
  #main
5
5
  require "external_migration/migration"
6
+ require "external_migration/migration_processor"
6
7
 
7
8
  #utils
8
9
  require "external_migration/dictionary"
@@ -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 migreate_row!(row_to)
130
+ def migrate_row!(row_to)
131
131
  @line += 1
132
132
  begin
133
- #transform row to @schema_to
134
- res = true
135
- res = @transformer.transform(row_to) unless @transformer.nil?
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
- if (res!=:ignore)
138
- res = res==true && send_row_to_schema(row_to)
139
- raise_migration if (res==false)
138
+ if (res!=:ignore)
139
+ res = res==true && send_row_to_schema(row_to)
140
+ raise_migration if (res==false)
140
141
 
141
- @transformer.after_row_saved(row_to, @last_object) unless @transformer.nil?
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
@@ -0,0 +1,9 @@
1
+
2
+ module ExternalMigration
3
+ module MigrationProcessor
4
+
5
+ def migrate_row(src_row)
6
+ end
7
+
8
+ end
9
+ end
@@ -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
- raise "Invalid File: should not null!" if file_schemas.nil?
23
- raise "Invalid File: should not exists!" if not File.exists?(file_schemas)
24
- @schemas = YAML::load(File.open(file_schemas))
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
- def run_migration_job
50
- transformer_from_schema()
51
-
52
- case @schema[:type]
53
- when :SCHEMA
54
- self.migrate_schema
55
- when :CUSTOM
56
- self.migrate_custom
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
@@ -42,7 +42,7 @@ module ExternalMigration
42
42
  end
43
43
  row.keys.each {|k| row.delete k if k.to_s =~ /ignore\d+/ }
44
44
  puts row.to_yaml
45
- @migration.migreate_row! row
45
+ @migration.migrate_row! row
46
46
  end
47
47
  file.close
48
48
 
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.2
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-04-29 00:00:00.000000000 Z
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