datashift 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/.document +5 -5
  2. data/LICENSE.txt +26 -26
  3. data/README.markdown +326 -305
  4. data/README.rdoc +19 -19
  5. data/Rakefile +86 -93
  6. data/VERSION +1 -1
  7. data/datashift.gemspec +163 -152
  8. data/lib/applications/jruby/jexcel_file.rb +410 -408
  9. data/lib/applications/jruby/word.rb +79 -79
  10. data/lib/datashift.rb +183 -152
  11. data/lib/datashift/exceptions.rb +11 -11
  12. data/lib/datashift/file_definitions.rb +353 -353
  13. data/lib/datashift/mapping_file_definitions.rb +87 -87
  14. data/lib/datashift/method_detail.rb +293 -275
  15. data/lib/datashift/method_dictionary.rb +208 -209
  16. data/lib/datashift/method_mapper.rb +90 -90
  17. data/lib/datashift/model_mapper.rb +27 -0
  18. data/lib/exporters/csv_exporter.rb +36 -0
  19. data/lib/exporters/excel_exporter.rb +116 -0
  20. data/lib/exporters/exporter_base.rb +15 -0
  21. data/lib/generators/csv_generator.rb +36 -36
  22. data/lib/generators/excel_generator.rb +106 -122
  23. data/lib/generators/generator_base.rb +13 -13
  24. data/lib/helpers/core_ext/to_b.rb +24 -24
  25. data/lib/helpers/rake_utils.rb +42 -0
  26. data/lib/helpers/spree_helper.rb +194 -153
  27. data/lib/java/poi-3.7/LICENSE +507 -507
  28. data/lib/java/poi-3.7/NOTICE +21 -21
  29. data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -115
  30. data/lib/loaders/csv_loader.rb +98 -98
  31. data/lib/loaders/excel_loader.rb +155 -155
  32. data/lib/loaders/loader_base.rb +420 -420
  33. data/lib/loaders/spreadsheet_loader.rb +136 -136
  34. data/lib/loaders/spree/image_loader.rb +67 -63
  35. data/lib/loaders/spree/product_loader.rb +289 -248
  36. data/lib/thor/generate_excel.thor +54 -0
  37. data/sandbox/app/controllers/application_controller.rb +3 -0
  38. data/sandbox/config/application.rb +43 -0
  39. data/sandbox/config/database.yml +34 -0
  40. data/sandbox/config/environment.rb +7 -0
  41. data/sandbox/config/environments/development.rb +30 -0
  42. data/spec/csv_loader_spec.rb +30 -30
  43. data/spec/datashift_spec.rb +26 -26
  44. data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -85
  45. data/spec/excel_exporter_spec.rb +78 -78
  46. data/spec/excel_generator_spec.rb +78 -78
  47. data/spec/excel_loader_spec.rb +223 -223
  48. data/spec/file_definitions.rb +141 -141
  49. data/spec/fixtures/ProjectsDefaults.yml +29 -29
  50. data/spec/fixtures/config/database.yml +27 -27
  51. data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
  52. data/spec/fixtures/datashift_test_models_db.sqlite +0 -0
  53. data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +4 -4
  54. data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -4
  55. data/spec/fixtures/spree/SpreeProducts.csv +4 -4
  56. data/spec/fixtures/spree/SpreeProducts.xls +0 -0
  57. data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -4
  58. data/spec/fixtures/spree/SpreeProductsMultiColumn.xls +0 -0
  59. data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -4
  60. data/spec/fixtures/spree/SpreeProductsWithImages.csv +4 -4
  61. data/spec/fixtures/spree/SpreeZoneExample.csv +5 -5
  62. data/spec/fixtures/test_model_defs.rb +57 -57
  63. data/spec/loader_spec.rb +120 -120
  64. data/spec/method_dictionary_spec.rb +242 -242
  65. data/spec/method_mapper_spec.rb +41 -41
  66. data/spec/spec_helper.rb +154 -116
  67. data/spec/spree_exporter_spec.rb +67 -0
  68. data/spec/spree_generator_spec.rb +77 -64
  69. data/spec/spree_loader_spec.rb +363 -324
  70. data/spec/spree_method_mapping_spec.rb +218 -214
  71. data/tasks/config/seed_fu_product_template.erb +15 -15
  72. data/tasks/config/tidy_config.txt +12 -12
  73. data/tasks/{excel_generator.rake → export/excel_generator.rake} +101 -78
  74. data/tasks/file_tasks.rake +36 -36
  75. data/tasks/import/csv.rake +50 -49
  76. data/tasks/import/excel.rake +74 -71
  77. data/tasks/spree/image_load.rake +108 -108
  78. data/tasks/spree/product_loader.rake +43 -43
  79. data/tasks/word_to_seedfu.rake +166 -166
  80. data/test/helper.rb +18 -18
  81. data/test/test_interact.rb +7 -7
  82. metadata +16 -8
  83. data/datashift-0.1.0.gem +0 -0
  84. data/tasks/db_tasks.rake +0 -66
@@ -1,79 +1,79 @@
1
- # Author:: Tom Statter
2
- # License:: MIT ?
3
- #
4
- # NOTES ON INVESTIGATING OLE METHODS in irb
5
- #
6
- # visible = @word_app.ole_method_help( 'Visible' ) # Get a Method Object
7
-
8
- # log( visible.return_type_detail.to_s ) # => ["BOOL"]
9
- # log( visible.invoke_kind.to_s ) # => "PROPERTYGET"
10
- # log( visible.params.to_s ) # => []
11
-
12
- # @fc.ole_method_help( 'Report' ).params[1].ole_type_detail
13
- #
14
- # prefs = @word_app.Preferences.Strings.ole_method_help( 'Set' ).params
15
- # => [index, newVal]
16
- #
17
- # WORD_OLE_CONST.constants
18
- #
19
- # WORD_OLE_CONST.constants.sort.grep /CR/
20
- # => ["ClHideCRLF", "LesCR", "LesCRLF"]
21
- #
22
- # WORD_OLE_CONST.const_get( 'LesCR' ) or WORD_OLE_CONST::LesCR
23
- # => 1
24
-
25
- if(Guards::windows?)
26
-
27
- require 'win32ole'
28
-
29
- # Module for constants to be loaded int
30
-
31
- module WORD_OLE_CONST
32
- end
33
-
34
- class Word
35
-
36
- attr_reader :wd, :doc
37
-
38
- def initialize( visible )
39
- @wd = WIN32OLE.new('Word.Application')
40
-
41
- WIN32OLE.const_load(@wd, WORD_OLE_CONST) if WORD_OLE_CONST.constants.empty?
42
-
43
- @wd.Visible = visible
44
- end
45
-
46
- def open(file)
47
- @doc = @wd.Documents.Open(file)
48
- @doc
49
- end
50
-
51
- def save()
52
- @doc.Save()
53
- @doc
54
- end
55
-
56
- # Format : From WORD_OLE_CONST e.g WORD_OLE_CONST::WdFormatHTML
57
- #
58
- def save_as(name, format)
59
- @doc.SaveAs(name, format)
60
- return @doc
61
- end
62
-
63
- # WdFormatFilteredHTML
64
- # WdFormatHTML
65
- def save_as_html(name)
66
- @doc.SaveAs(name, WORD_OLE_CONST::WdFormatHTML)
67
- return @doc
68
- end
69
-
70
- def quit
71
- @wd.quit()
72
- end
73
- end
74
-
75
- else
76
-
77
- class Word
78
- end
79
- end
1
+ # Author:: Tom Statter
2
+ # License:: MIT ?
3
+ #
4
+ # NOTES ON INVESTIGATING OLE METHODS in irb
5
+ #
6
+ # visible = @word_app.ole_method_help( 'Visible' ) # Get a Method Object
7
+
8
+ # log( visible.return_type_detail.to_s ) # => ["BOOL"]
9
+ # log( visible.invoke_kind.to_s ) # => "PROPERTYGET"
10
+ # log( visible.params.to_s ) # => []
11
+
12
+ # @fc.ole_method_help( 'Report' ).params[1].ole_type_detail
13
+ #
14
+ # prefs = @word_app.Preferences.Strings.ole_method_help( 'Set' ).params
15
+ # => [index, newVal]
16
+ #
17
+ # WORD_OLE_CONST.constants
18
+ #
19
+ # WORD_OLE_CONST.constants.sort.grep /CR/
20
+ # => ["ClHideCRLF", "LesCR", "LesCRLF"]
21
+ #
22
+ # WORD_OLE_CONST.const_get( 'LesCR' ) or WORD_OLE_CONST::LesCR
23
+ # => 1
24
+
25
+ if(Guards::windows?)
26
+
27
+ require 'win32ole'
28
+
29
+ # Module for constants to be loaded int
30
+
31
+ module WORD_OLE_CONST
32
+ end
33
+
34
+ class Word
35
+
36
+ attr_reader :wd, :doc
37
+
38
+ def initialize( visible )
39
+ @wd = WIN32OLE.new('Word.Application')
40
+
41
+ WIN32OLE.const_load(@wd, WORD_OLE_CONST) if WORD_OLE_CONST.constants.empty?
42
+
43
+ @wd.Visible = visible
44
+ end
45
+
46
+ def open(file)
47
+ @doc = @wd.Documents.Open(file)
48
+ @doc
49
+ end
50
+
51
+ def save()
52
+ @doc.Save()
53
+ @doc
54
+ end
55
+
56
+ # Format : From WORD_OLE_CONST e.g WORD_OLE_CONST::WdFormatHTML
57
+ #
58
+ def save_as(name, format)
59
+ @doc.SaveAs(name, format)
60
+ return @doc
61
+ end
62
+
63
+ # WdFormatFilteredHTML
64
+ # WdFormatHTML
65
+ def save_as_html(name)
66
+ @doc.SaveAs(name, WORD_OLE_CONST::WdFormatHTML)
67
+ return @doc
68
+ end
69
+
70
+ def quit
71
+ @wd.quit()
72
+ end
73
+ end
74
+
75
+ else
76
+
77
+ class Word
78
+ end
79
+ end
data/lib/datashift.rb CHANGED
@@ -1,153 +1,184 @@
1
- # Copyright:: (c) Autotelik Media Ltd 2011
2
- # Author :: Tom Statter
3
- # Date :: Aug 2010
4
- # License:: TBD. Free, Open Source. MIT ?
5
- #
6
- # Details:: Active Record Loader
7
- #
8
- require 'rbconfig'
9
-
10
- module DataShift
11
-
12
- module Guards
13
-
14
- def self.jruby?
15
- return RUBY_PLATFORM == "java"
16
- end
17
- def self.mac?
18
- RbConfig::CONFIG['target_os'] =~ /darwin/i
19
- end
20
-
21
- def self.linux?
22
- RbConfig::CONFIG['target_os'] =~ /linux/i
23
- end
24
-
25
- def self.windows?
26
- RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
27
- end
28
-
29
- end
30
-
31
- if(Guards::jruby?)
32
- require 'java'
33
-
34
- class Object
35
- def add_to_classpath(path)
36
- $CLASSPATH << File.join( DataShift.root_path, 'lib', path.gsub("\\", "/") )
37
- end
38
- end
39
- end
40
-
41
- def self.gem_version
42
- unless(@gem_version)
43
- if(File.exists?('VERSION'))
44
- File.read( File.join('VERSION') ).match(/.*(\d+.\d+.\d+)/)
45
- @gem_version = $1
46
- else
47
- @gem_version = '1.0.0'
48
- end
49
- end
50
- @gem_version
51
- end
52
-
53
- def self.gem_name
54
- "datashift"
55
- end
56
-
57
- def self.root_path
58
- File.expand_path("#{File.dirname(__FILE__)}/..")
59
- end
60
-
61
- def self.library_path
62
- File.expand_path("#{File.dirname(__FILE__)}/../lib")
63
- end
64
-
65
- def self.require_libraries
66
-
67
- loader_libs = %w{ lib }
68
-
69
- # Base search paths - these will be searched recursively
70
- loader_paths = []
71
-
72
- loader_libs.each {|l| loader_paths << File.join(root_path(), l) }
73
-
74
- # Define require search paths, any dir in here will be added to LOAD_PATH
75
-
76
- loader_paths.each do |base|
77
- $:.unshift base if File.directory?(base)
78
- Dir[File.join(base, '**', '**')].each do |p|
79
- if File.directory? p
80
- $:.unshift p
81
- end
82
- end
83
- end
84
-
85
- require_libs = %w{ datashift loaders helpers }
86
-
87
- require_libs.each do |base|
88
- Dir[File.join(library_path, base, '*.rb')].each do |rb|
89
- unless File.directory? rb
90
- require rb
91
- end
92
- end
93
- end
94
-
95
- end
96
-
97
- def self.load_tasks
98
- # Long parameter lists so ensure rake -T produces nice wide output
99
- ENV['RAKE_COLUMNS'] = '180'
100
- base = File.join(root_path, 'tasks', '**')
101
- Dir["#{base}/*.rake"].sort.each { |ext| load ext }
102
- end
103
-
104
-
105
- module Logging
106
-
107
- class MultiIO
108
-
109
- def initialize(*targets)
110
- @targets = []
111
- targets.each {|t| @targets << Logger.new(t) }
112
- end
113
-
114
- def add(target)
115
- @targets << Logger.new(target)
116
- end
117
-
118
-
119
- def method_missing(method, *args, &block)
120
- @targets.each {|t| t.send(method, *args, &block) }
121
- end
122
-
123
- def verbose
124
- add(STDOUT)
125
- end
126
-
127
- end
128
-
129
- require 'logger'
130
-
131
- def logdir
132
- @logdir ||= 'log'
133
- @logdir
134
- end
135
-
136
- def logger
137
- @logger ||= open
138
- @logger
139
- end
140
-
141
- private
142
-
143
- def open( log = 'datashift.log')
144
- FileUtils::mkdir(logdir) unless File.directory?(logdir)
145
- log_file = File.open( File.join(logdir(), 'datashift.log'), "a")
146
- @logger = MultiIO.new(log_file)
147
- @logger
148
- end
149
- end
150
-
151
- end
152
-
1
+ # Copyright:: (c) Autotelik Media Ltd 2011
2
+ # Author :: Tom Statter
3
+ # Date :: Aug 2010
4
+ # License:: TBD. Free, Open Source. MIT ?
5
+ #
6
+ # Details:: Active Record Loader
7
+ #
8
+ # # To pull Datashift commands into your main application :
9
+ #
10
+ # require 'datashift'
11
+ #
12
+ # DataShift::load_commands
13
+ #
14
+ require 'rbconfig'
15
+
16
+ module DataShift
17
+
18
+ module Guards
19
+
20
+ def self.jruby?
21
+ return RUBY_PLATFORM == "java"
22
+ end
23
+ def self.mac?
24
+ RbConfig::CONFIG['target_os'] =~ /darwin/i
25
+ end
26
+
27
+ def self.linux?
28
+ RbConfig::CONFIG['target_os'] =~ /linux/i
29
+ end
30
+
31
+ def self.windows?
32
+ RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
33
+ end
34
+
35
+ end
36
+
37
+ if(Guards::jruby?)
38
+ require 'java'
39
+
40
+ class Object
41
+ def add_to_classpath(path)
42
+ $CLASSPATH << File.join( DataShift.root_path, 'lib', path.gsub("\\", "/") )
43
+ end
44
+ end
45
+ end
46
+
47
+ def self.gem_version
48
+ unless(@gem_version)
49
+ if(File.exists?('VERSION'))
50
+ File.read( File.join('VERSION') ).match(/.*(\d+.\d+.\d+)/)
51
+ @gem_version = $1
52
+ else
53
+ @gem_version = '1.0.0'
54
+ end
55
+ end
56
+ @gem_version
57
+ end
58
+
59
+ def self.gem_name
60
+ "datashift"
61
+ end
62
+
63
+ def self.root_path
64
+ File.expand_path("#{File.dirname(__FILE__)}/..")
65
+ end
66
+
67
+ def self.library_path
68
+ File.expand_path("#{File.dirname(__FILE__)}/../lib")
69
+ end
70
+
71
+ def self.require_libraries
72
+
73
+ loader_libs = %w{ lib }
74
+
75
+ # Base search paths - these will be searched recursively
76
+ loader_paths = []
77
+
78
+ loader_libs.each {|l| loader_paths << File.join(root_path(), l) }
79
+
80
+ # Define require search paths, any dir in here will be added to LOAD_PATH
81
+
82
+ loader_paths.each do |base|
83
+ $:.unshift base if File.directory?(base)
84
+ Dir[File.join(base, '**', '**')].each do |p|
85
+ if File.directory? p
86
+ $:.unshift p
87
+ end
88
+ end
89
+ end
90
+
91
+ require_libs = %w{ datashift loaders helpers }
92
+
93
+ require_libs.each do |base|
94
+ Dir[File.join(library_path, base, '*.rb')].each do |rb|
95
+ unless File.directory? rb
96
+ require rb
97
+ end
98
+ end
99
+ end
100
+
101
+ end
102
+
103
+ # Load all the datashift rake tasks and make them available throughout app
104
+ def self.load_tasks
105
+ # Long parameter lists so ensure rake -T produces nice wide output
106
+ ENV['RAKE_COLUMNS'] = '180'
107
+ base = File.join(root_path, 'tasks', '**')
108
+ Dir["#{base}/*.rake"].sort.each { |ext| load ext }
109
+ end
110
+
111
+
112
+ # Load all the datashift Thor commands and make them available throughout app
113
+
114
+ def self.load_commands()
115
+
116
+ base = File.join(library_path, 'thor', '**')
117
+
118
+ Dir["#{base}/*.thor"].each do |f|
119
+
120
+ next unless File.file?(f)
121
+ Thor::Util.load_thorfile(f)
122
+ end
123
+ end
124
+
125
+
126
+ def self.load_thorfiles(dir)
127
+ Dir.chdir(dir) do
128
+ thor_files = Dir.glob('**/*.thor').delete_if { |x| not File.file?(x) }
129
+ thor_files.each do |f|
130
+ Thor::Util.load_thorfile(f)
131
+ end
132
+ end
133
+ end
134
+
135
+
136
+ module Logging
137
+
138
+ class MultiIO
139
+
140
+ def initialize(*targets)
141
+ @targets = []
142
+ targets.each {|t| @targets << Logger.new(t) }
143
+ end
144
+
145
+ def add(target)
146
+ @targets << Logger.new(target)
147
+ end
148
+
149
+
150
+ def method_missing(method, *args, &block)
151
+ @targets.each {|t| t.send(method, *args, &block) }
152
+ end
153
+
154
+ def verbose
155
+ add(STDOUT)
156
+ end
157
+
158
+ end
159
+
160
+ require 'logger'
161
+
162
+ def logdir
163
+ @logdir ||= 'log'
164
+ @logdir
165
+ end
166
+
167
+ def logger
168
+ @logger ||= open
169
+ @logger
170
+ end
171
+
172
+ private
173
+
174
+ def open( log = 'datashift.log')
175
+ FileUtils::mkdir(logdir) unless File.directory?(logdir)
176
+ log_file = File.open( File.join(logdir(), 'datashift.log'), "a")
177
+ @logger = MultiIO.new(log_file)
178
+ @logger
179
+ end
180
+ end
181
+
182
+ end
183
+
153
184
  DataShift::require_libraries