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,14 +1,14 @@
1
- # Copyright:: (c) Autotelik Media Ltd 2011
2
- # Author :: Tom Statter
3
- # Date :: Aug 2010
4
- # License:: MIT
5
- #
6
- # Details:: Base class for generators, which provide serivrs to describe a Model in an external format
7
- #
8
- module DataShift
9
-
10
- class GeneratorBase
11
-
12
- end
13
-
1
+ # Copyright:: (c) Autotelik Media Ltd 2011
2
+ # Author :: Tom Statter
3
+ # Date :: Aug 2010
4
+ # License:: MIT
5
+ #
6
+ # Details:: Base class for generators, which provide serivrs to describe a Model in an external format
7
+ #
8
+ module DataShift
9
+
10
+ class GeneratorBase
11
+
12
+ end
13
+
14
14
  end
@@ -1,24 +1,24 @@
1
- class Object
2
- def to_b
3
- case self
4
- when true, false then self
5
- when nil then false
6
- else
7
- to_i != 0
8
- end
9
- end
10
- end
11
-
12
- class String
13
- TRUE_REGEXP = /^(yes|true|on|t|1|\-1)$/i.freeze
14
- FALSE_REGEXP = /^(no|false|off|f|0)$/i.freeze
15
-
16
- def to_b
17
- case self
18
- when TRUE_REGEXP then true
19
- when FALSE_REGEXP then false
20
- else
21
- to_i != 0
22
- end
23
- end
24
- end
1
+ class Object
2
+ def to_b
3
+ case self
4
+ when true, false then self
5
+ when nil then false
6
+ else
7
+ to_i != 0
8
+ end
9
+ end
10
+ end
11
+
12
+ class String
13
+ TRUE_REGEXP = /^(yes|true|on|t|1|\-1)$/i.freeze
14
+ FALSE_REGEXP = /^(no|false|off|f|0)$/i.freeze
15
+
16
+ def to_b
17
+ case self
18
+ when TRUE_REGEXP then true
19
+ when FALSE_REGEXP then false
20
+ else
21
+ to_i != 0
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,42 @@
1
+ # Copyright:: (c) Autotelik Media Ltd 2011
2
+ # Author :: Tom Statter
3
+ # Date :: Aug 2011
4
+ # License:: MIT
5
+ #
6
+ #
7
+ module RakeUtils
8
+
9
+ # Method to check arguments from a rake task and display help if required
10
+ #
11
+ # Expects a block which prints out the usage information
12
+ #
13
+ # task_args is expected to be of type Rake::TaskArguments
14
+ #
15
+ # NOTES: TaskArgs - bit of a weird class, has internal hash but also looks up on ENV
16
+ # So if ENV[:filter] defined, args[:filter] would return the value,
17
+ # but it would not show up in args.inspect or args.to_s or args.to_hash
18
+ #
19
+ def self.check_args( task_args, required = [] )
20
+
21
+ # Tasks that call other tasks may wish to switch off displaying help for those sub tasks
22
+
23
+ if( block_given? )
24
+ yield unless task_args && required
25
+
26
+ # Does task_args contain keys for ALL required items
27
+ if(task_args[:help] || ENV['help'])
28
+ yield
29
+ exit(-1)
30
+ end
31
+
32
+ required.each do |r|
33
+ unless(task_args.send(r))# || task_args[r.to_sym])
34
+ puts "ERROR: Missing mandatory Param [#{r}]"
35
+ yield
36
+ exit(-1)
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ end
@@ -1,153 +1,194 @@
1
- # Copyright:: (c) Autotelik Media Ltd 2011
2
- # Author :: Tom Statter
3
- # Date :: Aug 2011
4
- # License:: MIT
5
- #
6
- # Details:: Spree Helper mixing in Support for testing or loading Rails Spree e-commerce.
7
- #
8
- # The Spree version you want to test should be picked up from the Gemfile
9
- #
10
- # Since datashift gem is not a Rails app or a Spree App, provides utilities to internally
11
- # create a Spree Database, and to load Spree components, enabling standalone testing.
12
- #
13
- # => Has been tested with 0.7
14
- #
15
- # # => TODO - Can we move to a Gemfile/bunlder
16
- # require 'rubygems'
17
- # gemfile = File.expand_path("<%= gemfile_path %>", __FILE__)
18
- #
19
- # ENV['BUNDLE_GEMFILE'] = gemfile
20
- # require 'bundler'
21
- # Bundler.setup
22
- #
23
- # => TODO - See if we can improve DB creation/migration ....
24
- # N.B Some or all of Spree Tests may fail very first time run,
25
- # as the database is auto generated
26
- # =>
27
- module Spree
28
-
29
- def self.root
30
- Gem.loaded_specs['spree_core'] ? Gem.loaded_specs['spree_core'].full_gem_path : ""
31
- end
32
-
33
- def self.lib_root
34
- File.join(root, 'lib')
35
- end
36
-
37
- def self.app_root
38
- File.join(root, 'app')
39
- end
40
-
41
- def self.load()
42
- gem 'spree'
43
- end
44
-
45
- def self.boot
46
-
47
- require 'spree'
48
- require 'spree_core'
49
-
50
- if(Gem.loaded_specs['spree'].version.version.to_f < 1)
51
- boot_pre_1
52
- else
53
- require File.expand_path( lib_root + '/generators/spree/install/install_generator')
54
- require 'spree/core/testing_support/common_rake'
55
-
56
-
57
- Spree::SandboxGenerator.start ["--lib_name=spree", "--database=#{ENV['DB_NAME']}"]
58
- Spree::InstallGenerator.start ["--auto-accept"]
59
-
60
- cmd = "bundle exec rake assets:precompile:nondigest";
61
- puts cmd; system cmd
62
- end
63
- end
64
-
65
- def self.boot_pre_1
66
-
67
- require 'rake'
68
- require 'rubygems/package_task'
69
- require 'thor/group'
70
-
71
- require 'spree_core/preferences/model_hooks'
72
- #
73
- # Initialize preference system
74
- ActiveRecord::Base.class_eval do
75
- include Spree::Preferences
76
- include Spree::Preferences::ModelHooks
77
- end
78
-
79
- gem 'paperclip'
80
- gem 'nested_set'
81
-
82
- require 'nested_set'
83
- require 'paperclip'
84
- require 'acts_as_list'
85
-
86
- CollectiveIdea::Acts::NestedSet::Railtie.extend_active_record
87
- ActiveRecord::Base.send(:include, Paperclip::Glue)
88
-
89
- gem 'activemerchant'
90
- require 'active_merchant'
91
- require 'active_merchant/billing/gateway'
92
-
93
- ActiveRecord::Base.send(:include, ActiveMerchant::Billing)
94
-
95
- require 'scopes'
96
-
97
- # Not sure how Rails manages this seems lots of circular dependencies so
98
- # keep trying stuff till no more errors
99
-
100
- Dir[lib_root + '/*.rb'].each do |r|
101
- begin
102
- require r if File.file?(r)
103
- rescue => e
104
- end
105
- end
106
-
107
- Dir[lib_root + '/**/*.rb'].each do |r|
108
- begin
109
- require r if File.file?(r) && ! r.include?('testing') && ! r.include?('generators')
110
- rescue => e
111
- end
112
- end
113
-
114
- load_models( true )
115
-
116
- Dir[lib_root + '/*.rb'].each do |r|
117
- begin
118
- require r if File.file?(r)
119
- rescue => e
120
- end
121
- end
122
-
123
- Dir[lib_root + '/**/*.rb'].each do |r|
124
- begin
125
- require r if File.file?(r) && ! r.include?('testing') && ! r.include?('generators')
126
- rescue => e
127
- end
128
- end
129
-
130
- # require 'lib/product_filters'
131
-
132
- load_models( true )
133
-
134
- end
135
-
136
- def self.load_models( report_errors = nil )
137
- puts 'Loading Spree models from', root
138
- Dir[root + '/app/models/**/*.rb'].each {|r|
139
- begin
140
- require r if File.file?(r)
141
- rescue => e
142
- puts("WARNING failed to load #{r}", e.inspect) if(report_errors == true)
143
- end
144
- }
145
- end
146
-
147
- def self.migrate_up
148
- load
149
- boot
150
- ActiveRecord::Migrator.up( File.join(root, 'db/migrate') )
151
- end
152
-
153
- end
1
+ # Copyright:: (c) Autotelik Media Ltd 2011
2
+ # Author :: Tom Statter
3
+ # Date :: Aug 2011
4
+ # License:: MIT
5
+ #
6
+ # Details:: Spree Helper mixing in Support for testing or loading Rails Spree e-commerce.
7
+ #
8
+ # The Spree version you want to test should be picked up from the Gemfile
9
+ #
10
+ # Since datashift gem is not a Rails app or a Spree App, provides utilities to internally
11
+ # create a Spree Database, and to load Spree components, enabling standalone testing.
12
+ #
13
+ # => Has been tested with 0.7
14
+ #
15
+ # # => TODO - Can we move to a Gemfile/bunlder
16
+ # require 'rubygems'
17
+ # gemfile = File.expand_path("<%= gemfile_path %>", __FILE__)
18
+ #
19
+ # ENV['BUNDLE_GEMFILE'] = gemfile
20
+ # require 'bundler'
21
+ # Bundler.setup
22
+ #
23
+ # => TODO - See if we can improve DB creation/migration ....
24
+ # N.B Some or all of Spree Tests may fail very first time run,
25
+ # as the database is auto generated
26
+ # =>
27
+
28
+
29
+
30
+ module DataShift
31
+
32
+ module SpreeHelper
33
+
34
+
35
+ def self.root
36
+ Gem.loaded_specs['spree_core'] ? Gem.loaded_specs['spree_core'].full_gem_path : ""
37
+ end
38
+
39
+ # Helpers so we can cope with both pre 1.0 and post 1.0 versions of Spree in same datashift version
40
+
41
+ def self.get_spree_class(x)
42
+ if(is_namespace_version())
43
+ ModelMapper::class_from_string("Spree::#{x}")
44
+ else
45
+ ModelMapper::class_from_string(x.to_s)
46
+ end
47
+ end
48
+
49
+ def self.get_product_class
50
+ if(is_namespace_version())
51
+ Spree::Product
52
+ else
53
+ Product
54
+ end
55
+ end
56
+
57
+ def self.is_namespace_version
58
+ Gem.loaded_specs['spree'].version.version.to_f >= 1
59
+ end
60
+
61
+ def self.lib_root
62
+ File.join(root, 'lib')
63
+ end
64
+
65
+ def self.app_root
66
+ File.join(root, 'app')
67
+ end
68
+
69
+ def self.load()
70
+ require 'spree'
71
+ require 'spree_core'
72
+ end
73
+
74
+
75
+ # Datahift isi usually included and tasks pulled in by a parent/host application.
76
+ # So here we are hacking our way around the fact that datashift is not a Rails/Spree app/engine
77
+ # so that we can ** run our specs ** directly in datashift library
78
+ # i.e without ever having to install datashift in a host application
79
+ def self.boot( database_env )
80
+
81
+ if( ! is_namespace_version )
82
+ db_connect( database_env )
83
+ @dslog.info "Booting Spree using pre 1.0.0 version"
84
+ boot_pre_1
85
+ @dslog.info "Booted Spree using pre 1.0.0 version"
86
+ else
87
+
88
+ # TODO as Spree versions moves how do we best track reqd Rails version
89
+ # parse the gemspec of the core Gemfile ?
90
+
91
+ gem('rails', '3.1.3')
92
+
93
+ db_connect( database_env, '3.1.3' )
94
+
95
+ @dslog.info "Booting Spree using post 1.0.0 version"
96
+
97
+ require 'rails/all'
98
+
99
+ Dir.chdir( File.expand_path('../../../sandbox', __FILE__) )
100
+
101
+ require 'config/environment.rb'
102
+
103
+ @dslog.info "Booted Spree using post 1.0.0 version"
104
+ end
105
+ end
106
+
107
+ def self.boot_pre_1
108
+
109
+ require 'rake'
110
+ require 'rubygems/package_task'
111
+ require 'thor/group'
112
+
113
+ require 'spree_core/preferences/model_hooks'
114
+ #
115
+ # Initialize preference system
116
+ ActiveRecord::Base.class_eval do
117
+ include Spree::Preferences
118
+ include Spree::Preferences::ModelHooks
119
+ end
120
+
121
+ gem 'paperclip'
122
+ gem 'nested_set'
123
+
124
+ require 'nested_set'
125
+ require 'paperclip'
126
+ require 'acts_as_list'
127
+
128
+ CollectiveIdea::Acts::NestedSet::Railtie.extend_active_record
129
+ ActiveRecord::Base.send(:include, Paperclip::Glue)
130
+
131
+ gem 'activemerchant'
132
+ require 'active_merchant'
133
+ require 'active_merchant/billing/gateway'
134
+
135
+ ActiveRecord::Base.send(:include, ActiveMerchant::Billing)
136
+
137
+ require 'scopes'
138
+
139
+ # Not sure how Rails manages this seems lots of circular dependencies so
140
+ # keep trying stuff till no more errors
141
+
142
+ Dir[lib_root + '/*.rb'].each do |r|
143
+ begin
144
+ require r if File.file?(r)
145
+ rescue => e
146
+ end
147
+ end
148
+
149
+ Dir[lib_root + '/**/*.rb'].each do |r|
150
+ begin
151
+ require r if File.file?(r) && ! r.include?('testing') && ! r.include?('generators')
152
+ rescue => e
153
+ end
154
+ end
155
+
156
+ load_models( true )
157
+
158
+ Dir[lib_root + '/*.rb'].each do |r|
159
+ begin
160
+ require r if File.file?(r)
161
+ rescue => e
162
+ end
163
+ end
164
+
165
+ Dir[lib_root + '/**/*.rb'].each do |r|
166
+ begin
167
+ require r if File.file?(r) && ! r.include?('testing') && ! r.include?('generators')
168
+ rescue => e
169
+ end
170
+ end
171
+
172
+ # require 'lib/product_filters'
173
+
174
+ load_models( true )
175
+
176
+ end
177
+
178
+ def self.load_models( report_errors = nil )
179
+ puts 'Loading Spree models from', root
180
+ Dir[root + '/app/models/**/*.rb'].each {|r|
181
+ begin
182
+ require r if File.file?(r)
183
+ rescue => e
184
+ puts("WARNING failed to load #{r}", e.inspect) if(report_errors == true)
185
+ end
186
+ }
187
+ end
188
+
189
+ def self.migrate_up
190
+ ActiveRecord::Migrator.up( File.join(root, 'db/migrate') )
191
+ end
192
+
193
+ end
194
+ end