active_extend 0.0.3.1 → 0.0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 318d41f7b21b50b7ca77c47277850ba49f3c5a50
4
+ data.tar.gz: 3d5435a4dbf060e3d4d5117f2febce9557db8f03
5
+ SHA512:
6
+ metadata.gz: 6af14c9bbc9d1d1c2f2916a4f7f7b773046ced13f8d68e6e903eb70fc926e98f50d04768622dab6075bac72fa994dc43cd6e5262e0128db47b23c2b559006ebc
7
+ data.tar.gz: 7ed2147101edd4d44e5781192b9815faab619c4fee03469ba9103f8f3aea15eef9b632ff3b60885642e6e051685047ffa499cf01aa4220529b3be706f58b0ddc
@@ -2,6 +2,7 @@
2
2
  require "active_extend/active_disablable"
3
3
  require "active_extend/railtie" if defined?(Rails)
4
4
  require "active_extend/string_helper"
5
+ require "active_extend/hash_utils"
5
6
 
6
7
  module ActiveExtend
7
8
  end
@@ -0,0 +1,14 @@
1
+ Hash.class_eval do
2
+ def self.keys_to_sym(h_or_v)
3
+ Hash === h_or_v ?
4
+ Hash[
5
+ h_or_v.map do |k, v|
6
+ [k.respond_to?(:to_sym) ? k.to_sym : k, Hash.keys_to_sym(v)]
7
+ end
8
+ ] : h_or_v
9
+ end
10
+
11
+ def keys_to_sym
12
+ Hash.keys_to_sym self
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveExtend
2
- VERSION = "0.0.3.1".freeze
2
+ VERSION = "0.0.3.2".freeze
3
3
  end
@@ -16,10 +16,28 @@ module ExternalMigration
16
16
 
17
17
  end
18
18
 
19
- ##
20
- # Module Data Transformation
19
+ # Module for Data Transformation
21
20
  # When passing schema file or struct, the data between datasources
22
- # needs a transformations
21
+ # needs a transformations.
22
+ # # called on start of transaction
23
+ # def begin_transaction(schema_from, schema_to)
24
+ #
25
+ # # definily obrigatory to define this method!<br>
26
+ # # Transform from data row to destinate data row
27
+ # # @result
28
+ # # - true means continue with your job
29
+ # # - false stop job now!
30
+ # # - :ignore ignore this chunk
31
+ # def transform(row)
32
+ #
33
+ # # called on ending migration
34
+ # def end(schema_from, schema_to)
35
+ #
36
+ # # called on ending transaction
37
+ # def end_transaction(schema_from, schema_to)
38
+ #
39
+ # def after_row_saved(row, object)
40
+ # @abstract
23
41
  module Transformer
24
42
  ##
25
43
  # called on start of migration
@@ -27,67 +45,43 @@ module ExternalMigration
27
45
  @schema_from = schema_from
28
46
  @schema_to = schema_to
29
47
  end
30
-
31
- ##
32
- # called on start of transaction
33
- def begin_transaction(schema_from, schema_to)
34
- # nothing
35
- end
36
-
37
- ##
38
- # transform from data row to destinate data row
39
- # @result true, false or :ignore to ignore this row
40
- def transform(row)
41
- raise "Implements transform method!"
42
- end
43
-
44
- ##
45
- # called on ending migration
46
- def end(schema_from, schema_to)
47
- # nothing
48
- end
49
-
50
- ##
51
- # called on ending transaction
52
- def end_transaction(schema_from, schema_to)
53
- # nothing
54
- end
55
-
56
- ##
57
- #
58
- def after_row_saved(row, object)
59
- #
60
- end
61
-
48
+
49
+ # Ignore a field starts with ignore(.*): assumes length fields
50
+ # or separator
51
+ # @return [Hash] row without ignores
52
+ # @example
53
+ # schema:
54
+ # columns:
55
+ # digit:
56
+ # format: N
57
+ # length: 10
58
+ # ignore_not_need_this__really__so_i_ll_not_touch_this:
59
+ # length: 10000
62
60
  def transform_ignore_fields(row)
63
- #delete ignore
64
61
  row.reject! { |key,value| key.to_s.start_with?("ignore") }
65
62
  end
66
63
 
67
64
  end
68
65
 
66
+ #Interface for your decoder
69
67
  module Decoder
70
68
  def migrate!
71
69
  end
72
70
  end
73
71
 
74
- ##
75
- # == Class Migration
76
- #
72
+
77
73
  # Migrate data between data source and transforme to destination
78
- #
79
74
  class Migration
80
75
  attr_accessor :schema_from, :schema_to, :transformer, :name, :processor
81
-
76
+
82
77
  # constructor
83
78
  def initialize(schema_url=nil)
84
79
  self.load_schema(schema_url) unless schema_url.nil?
85
80
  end
86
-
87
- ##
81
+
88
82
  # load yml schemas from and to
89
83
  def load_schema(url)
90
- schema = YAML::load(File.open(url))
84
+ schema = YAML::load(File.open(url)).keys_to_sym
91
85
  self.schema_from = schema[:from]
92
86
  self.schema_to = schema[:to]
93
87
  end
@@ -111,9 +105,10 @@ module ExternalMigration
111
105
  begin_migration()
112
106
 
113
107
  # TODO: Make flexible configurable and more input formats
114
- if @schema_from[:format].to_s.to_sym == :XLS
108
+ case @schema_from[:format].to_s.to_sym
109
+ when :XLS
115
110
  xls_migrate()
116
- elsif @schema_from[:format].to_s.to_sym == :TXT_FIXED
111
+ when :TXT_FIXED
117
112
  decoder = ExternalMigration::TextFixed.new(@schema_from)
118
113
  decoder.migration = self
119
114
  decoder.migrate!
@@ -21,7 +21,17 @@ module ExternalMigration
21
21
  end
22
22
 
23
23
  def schema=(schema)
24
- @schema = schema
24
+
25
+ if schema[:multiple_lines] == :true
26
+ @schema_multiple_lines = true
27
+ @schema_line_index = -1
28
+ @schema = schema
29
+ @schema_lines = @schema.columns.keys
30
+ @schema[:lines] = @schema[:columns] #backup layout
31
+ next_schema_line
32
+ else
33
+ @schema = schema
34
+ end
25
35
  end
26
36
 
27
37
  def migrate!
@@ -42,10 +52,20 @@ module ExternalMigration
42
52
  end
43
53
  row.keys.each {|k| row.delete k if k.to_s =~ /ignore\d+/ }
44
54
  @migration.migrate_row! row
55
+
56
+ next_schema_line
45
57
  end
46
58
  file.close
47
59
 
48
60
  end
61
+
62
+ def next_schema_line
63
+ if @schema_multiple_lines
64
+ @schema_line_index += 1
65
+ @schema_line_index = 0 if @schema_line_index >= @schema_lines.size
66
+ @schema[:columns] = @schema[:lines][@schema_lines[@schema_line_index]]
67
+ end
68
+ end
49
69
 
50
70
  end
51
71
 
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_extend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.1
5
- prerelease:
4
+ version: 0.0.3.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Bruno Guerra
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
11
+ date: 2013-10-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: spreadsheet
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,12 +34,12 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
- description: many cool behaviors for active_model.
41
+ description: many cool behaviors for Activerecord like ActiveDisable, Hash.keys_to_sym
42
+ and more
47
43
  email:
48
44
  - bruno@woese.com
49
45
  executables: []
@@ -51,6 +47,7 @@ extensions: []
51
47
  extra_rdoc_files: []
52
48
  files:
53
49
  - lib/active_extend/active_disablable.rb
50
+ - lib/active_extend/hash_utils.rb
54
51
  - lib/active_extend/railtie.rb
55
52
  - lib/active_extend/string_helper.rb
56
53
  - lib/active_extend/version.rb
@@ -69,27 +66,27 @@ files:
69
66
  - Rakefile
70
67
  - README.rdoc
71
68
  homepage: http://www.woese.com
72
- licenses: []
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
73
72
  post_install_message:
74
73
  rdoc_options: []
75
74
  require_paths:
76
75
  - lib
77
76
  required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
77
  requirements:
80
78
  - - ! '>='
81
79
  - !ruby/object:Gem::Version
82
80
  version: '0'
83
81
  required_rubygems_version: !ruby/object:Gem::Requirement
84
- none: false
85
82
  requirements:
86
83
  - - ! '>='
87
84
  - !ruby/object:Gem::Version
88
85
  version: '0'
89
86
  requirements: []
90
87
  rubyforge_project:
91
- rubygems_version: 1.8.24
88
+ rubygems_version: 2.0.3
92
89
  signing_key:
93
- specification_version: 3
94
- summary: many cool behaviors for active_model
90
+ specification_version: 4
91
+ summary: many cool behaviors for ActiveRecord
95
92
  test_files: []