datashift 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/.document +5 -5
  2. data/Gemfile +28 -25
  3. data/LICENSE.txt +26 -26
  4. data/README.markdown +302 -285
  5. data/README.rdoc +19 -19
  6. data/Rakefile +93 -95
  7. data/VERSION +5 -5
  8. data/datashift.gemspec +162 -178
  9. data/lib/applications/jruby/jexcel_file.rb +396 -396
  10. data/lib/applications/jruby/word.rb +79 -79
  11. data/lib/datashift.rb +152 -113
  12. data/lib/datashift/exceptions.rb +11 -11
  13. data/lib/datashift/file_definitions.rb +353 -353
  14. data/lib/datashift/mapping_file_definitions.rb +87 -87
  15. data/lib/datashift/method_detail.rb +236 -236
  16. data/lib/datashift/method_mapper.rb +256 -256
  17. data/lib/generators/csv_generator.rb +36 -36
  18. data/lib/generators/excel_generator.rb +121 -121
  19. data/lib/generators/generator_base.rb +13 -13
  20. data/lib/helpers/core_ext/to_b.rb +24 -24
  21. data/lib/helpers/spree_helper.rb +131 -131
  22. data/lib/java/poi-3.7/LICENSE +507 -507
  23. data/lib/java/poi-3.7/NOTICE +21 -21
  24. data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -115
  25. data/lib/loaders/csv_loader.rb +98 -98
  26. data/lib/loaders/excel_loader.rb +154 -149
  27. data/lib/loaders/loader_base.rb +403 -331
  28. data/lib/loaders/spreadsheet_loader.rb +136 -136
  29. data/lib/loaders/spree/image_loader.rb +45 -45
  30. data/lib/loaders/spree/product_loader.rb +224 -224
  31. data/spec/csv_loader_spec.rb +30 -30
  32. data/spec/datashift_spec.rb +26 -26
  33. data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -85
  34. data/spec/excel_generator_spec.rb +78 -78
  35. data/spec/excel_loader_spec.rb +204 -176
  36. data/spec/file_definitions.rb +141 -141
  37. data/spec/fixtures/.~lock.ProjectsSingleCategories.xls# +1 -0
  38. data/spec/fixtures/ProjectsDefaults.yml +29 -0
  39. data/spec/fixtures/config/database.yml +24 -24
  40. data/spec/fixtures/interact_models_db.sqlite +0 -0
  41. data/spec/fixtures/interact_spree_db.sqlite +0 -0
  42. data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +4 -4
  43. data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -4
  44. data/spec/fixtures/spree/SpreeProducts.csv +4 -4
  45. data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -4
  46. data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -4
  47. data/spec/fixtures/spree/SpreeZoneExample.csv +5 -5
  48. data/spec/fixtures/test_model_defs.rb +57 -57
  49. data/spec/loader_spec.rb +120 -120
  50. data/spec/method_mapper_spec.rb +237 -237
  51. data/spec/spec_helper.rb +115 -115
  52. data/spec/spree_generator_spec.rb +64 -64
  53. data/spec/spree_loader_spec.rb +310 -310
  54. data/spec/spree_method_mapping_spec.rb +214 -214
  55. data/tasks/config/seed_fu_product_template.erb +15 -15
  56. data/tasks/config/tidy_config.txt +12 -12
  57. data/tasks/db_tasks.rake +65 -64
  58. data/tasks/excel_generator.rake +78 -78
  59. data/tasks/file_tasks.rake +36 -36
  60. data/tasks/import/csv.rake +49 -49
  61. data/tasks/import/excel.rake +71 -66
  62. data/tasks/spree/image_load.rake +108 -108
  63. data/tasks/spree/product_loader.rake +43 -43
  64. data/tasks/word_to_seedfu.rake +166 -166
  65. data/test/helper.rb +18 -18
  66. data/test/test_interact.rb +7 -7
  67. metadata +7 -38
  68. data/Gemfile.lock +0 -211
  69. data/bin/autospec +0 -16
  70. data/bin/convert_to_should_syntax +0 -16
  71. data/bin/erubis +0 -16
  72. data/bin/htmldiff +0 -16
  73. data/bin/jeweler +0 -16
  74. data/bin/ldiff +0 -16
  75. data/bin/nokogiri +0 -16
  76. data/bin/rackup +0 -16
  77. data/bin/rails +0 -16
  78. data/bin/rake +0 -16
  79. data/bin/rake2thor +0 -16
  80. data/bin/ri +0 -16
  81. data/bin/rspec +0 -16
  82. data/bin/spree +0 -16
  83. data/bin/thor +0 -16
  84. data/bin/tilt +0 -16
  85. data/bin/tt +0 -16
@@ -1,13 +1,13 @@
1
- # Copyright:: (c) Autotelik Media Ltd 2011
2
- # Author :: Tom Statter
3
- # Date :: Aug 2010
4
- #
5
- # License:: Free, OpenSource... MIT ?
6
-
7
- # This is the best effort I've found so far to reduce the amount of MS cruft
8
- # to absolute minimum
9
- # ... but unfortunately these tags will NOT BE REMOVED completely - manual cleanup still required
10
-
11
- # TODO - add another ruby parse layer to strip these out completely
12
-
1
+ # Copyright:: (c) Autotelik Media Ltd 2011
2
+ # Author :: Tom Statter
3
+ # Date :: Aug 2010
4
+ #
5
+ # License:: Free, OpenSource... MIT ?
6
+
7
+ # This is the best effort I've found so far to reduce the amount of MS cruft
8
+ # to absolute minimum
9
+ # ... but unfortunately these tags will NOT BE REMOVED completely - manual cleanup still required
10
+
11
+ # TODO - add another ruby parse layer to strip these out completely
12
+
13
13
  new-empty-tags: o:smarttagtype, st1:placename, st1:place, st1:placetype
data/tasks/db_tasks.rake CHANGED
@@ -1,65 +1,66 @@
1
- # Author :: Tom Statter
2
- # Date :: Mar 2011
3
- #
4
- # License:: The MIT License (Free and OpenSource)
5
- #
6
- # About:: Additional Rake tasks useful when testing seeding DB via DataShift
7
- #
8
- namespace :autotelik do
9
-
10
- namespace :db do
11
-
12
- SYSTEM_TABLE_EXCLUSION_LIST = ['schema_migrations']
13
-
14
- desc "Purge the current database"
15
- task :purge, :exclude_system_tables, :needs => [:environment] do |t, args|
16
- require 'highline/import'
17
-
18
- if(RAILS_ENV == 'production')
19
- agree("WARNING: In Production database, REALLY PURGE ? [y]:")
20
- end
21
-
22
- config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
23
- case config['adapter']
24
- when "mysql", "jdbcmysql"
25
- ActiveRecord::Base.establish_connection(config)
26
- ActiveRecord::Base.connection.tables.each do |table|
27
- next if(args[:exclude_system_tables] && SYSTEM_TABLE_EXCLUSION_LIST.include?(table) )
28
- puts "purging table: #{table}"
29
- ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
30
- end
31
- when "sqlite","sqlite3"
32
- dbfile = config["database"] || config["dbfile"]
33
- File.delete(dbfile) if File.exist?(dbfile)
34
- when "sqlserver"
35
- dropfkscript = "#{config["host"]}.#{config["database"]}.DP1".gsub(/\\/,'-')
36
- `osql -E -S #{config["host"]} -d #{config["database"]} -i db\\#{dropfkscript}`
37
- `osql -E -S #{config["host"]} -d #{config["database"]} -i db\\#{RAILS_ENV}_structure.sql`
38
- when "oci", "oracle"
39
- ActiveRecord::Base.establish_connection(config)
40
- ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
41
- ActiveRecord::Base.connection.execute(ddl)
42
- end
43
- when "firebird"
44
- ActiveRecord::Base.establish_connection(config)
45
- ActiveRecord::Base.connection.recreate_database!
46
- else
47
- raise "Task not supported by '#{config["adapter"]}'"
48
- end
49
- end
50
-
51
- desc "Clear database and optional directories such as assets, then run db:seed"
52
- task :seed_again, :assets, :needs => [:environment] do |t, args|
53
-
54
- Rake::Task['autotelik:db:purge'].invoke( true ) # i.e ENV['exclude_system_tables'] = true
55
-
56
- if(args[:assets])
57
- assets = "#{Rails.root}/public/assets"
58
- FileUtils::rm_rf(assets) if(File.exists?(assets))
59
- end
60
-
61
- Rake::Task['db:seed'].invoke
62
- end
63
-
64
- end # db
1
+ # Author :: Tom Statter
2
+ # Date :: Mar 2011
3
+ #
4
+ # License:: The MIT License (Free and OpenSource)
5
+ #
6
+ # About:: Additional Rake tasks useful when testing seeding DB via DataShift
7
+ #
8
+ namespace :autotelik do
9
+
10
+ namespace :db do
11
+
12
+ SYSTEM_TABLE_EXCLUSION_LIST = ['schema_migrations']
13
+
14
+ desc "Purge the current database"
15
+
16
+ task :purge, [:exclude_system_tables] => [:environment] do |t, args|
17
+ require 'highline/import'
18
+
19
+ if(RAILS_ENV == 'production')
20
+ agree("WARNING: In Production database, REALLY PURGE ? [y]:")
21
+ end
22
+
23
+ config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
24
+ case config['adapter']
25
+ when "mysql", "jdbcmysql"
26
+ ActiveRecord::Base.establish_connection(config)
27
+ ActiveRecord::Base.connection.tables.each do |table|
28
+ next if(args[:exclude_system_tables] && SYSTEM_TABLE_EXCLUSION_LIST.include?(table) )
29
+ puts "purging table: #{table}"
30
+ ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
31
+ end
32
+ when "sqlite","sqlite3"
33
+ dbfile = config["database"] || config["dbfile"]
34
+ File.delete(dbfile) if File.exist?(dbfile)
35
+ when "sqlserver"
36
+ dropfkscript = "#{config["host"]}.#{config["database"]}.DP1".gsub(/\\/,'-')
37
+ `osql -E -S #{config["host"]} -d #{config["database"]} -i db\\#{dropfkscript}`
38
+ `osql -E -S #{config["host"]} -d #{config["database"]} -i db\\#{RAILS_ENV}_structure.sql`
39
+ when "oci", "oracle"
40
+ ActiveRecord::Base.establish_connection(config)
41
+ ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
42
+ ActiveRecord::Base.connection.execute(ddl)
43
+ end
44
+ when "firebird"
45
+ ActiveRecord::Base.establish_connection(config)
46
+ ActiveRecord::Base.connection.recreate_database!
47
+ else
48
+ raise "Task not supported by '#{config["adapter"]}'"
49
+ end
50
+ end
51
+
52
+ desc "Clear database and optional directories such as assets, then run db:seed"
53
+ task :seed_again, [:assets] => [:environment] do |t, args|
54
+
55
+ Rake::Task['autotelik:db:purge'].invoke( true ) # i.e ENV['exclude_system_tables'] = true
56
+
57
+ if(args[:assets])
58
+ assets = "#{Rails.root}/public/assets"
59
+ FileUtils::rm_rf(assets) if(File.exists?(assets))
60
+ end
61
+
62
+ Rake::Task['db:seed'].invoke
63
+ end
64
+
65
+ end # db
65
66
  end # autotelik
@@ -1,79 +1,79 @@
1
- # Copyright:: (c) Autotelik Media Ltd 2011
2
- # Author :: Tom Statter
3
- # Date :: Aug 2011
4
- # License:: MIT.
5
- #
6
- # REQUIRES: JRuby
7
- #
8
- # Usage::
9
- #
10
- # In Rakefile:
11
- #
12
- # require 'datashift'
13
- #
14
- # DataShift::load_tasks
15
- #
16
- # Cmd Line:
17
- #
18
- # => jruby -S rake datashift:generate:excel model=<active record class> result=<output_template.xls>
19
- #
20
- namespace :datashift do
21
- namespace :generate do
22
-
23
- desc "Generate a template .xls (Excel) file for a model"
24
-
25
- task :excel, [:model, :result] => [:environment] do |t, args|
26
-
27
- require 'excel_generator'
28
-
29
- # in familiar ruby style args seems to have been become empty using this new style for rake 0.9.2
30
- # whatever format i try, on both Win and OSX .. so had to revert back to ENV
31
- model = args[:model] || ENV['model']
32
- result = args[:result] || ENV['result']
33
-
34
- raise "USAGE: jruby -S rake datashift:generate:excel model=<Class> result=<file.xls>" unless(result)
35
- raise "ERROR: Cannot process without AR Model - please supply model=<Class>" unless(model)
36
-
37
- begin
38
- klass = Kernel.const_get(model)
39
- rescue NameError
40
- raise "ERROR: No such AR Model found - check valid model supplied via model=<Class>"
41
- end
42
-
43
- gen = DataShift::ExcelGenerator.new(result)
44
-
45
- gen.generate(klass)
46
- end
47
-
48
- end
49
-
50
- namespace :export do
51
-
52
- desc "Export active record data to .xls (Excel) file"
53
-
54
- task :excel, [:model, :result] => [:environment] do |t, args|
55
-
56
- require 'excel_generator'
57
-
58
- # in familiar ruby style args seems to have been become empty using this new style for rake 0.9.2
59
- # whatever format i try, on both Win and OSX .. so had to revert back to ENV
60
- model = ENV['model']
61
- result = ENV['result']
62
-
63
- raise "USAGE: jruby -S rake datashift:gen:excel model=<Class> result=<file.xls>" unless(result)
64
- raise "ERROR: Cannot process without AR Model - please supply model=<Class>" unless(model)
65
-
66
- begin
67
- klass = Kernel.const_get(model)
68
- rescue NameError
69
- raise "ERROR: No such AR Model found - check valid model supplied via model=<Class>"
70
- end
71
-
72
- gen = DataShift::ExcelGenerator.new(result)
73
-
74
- gen.export(klass.all)
75
- end
76
-
77
- end
78
-
1
+ # Copyright:: (c) Autotelik Media Ltd 2011
2
+ # Author :: Tom Statter
3
+ # Date :: Aug 2011
4
+ # License:: MIT.
5
+ #
6
+ # REQUIRES: JRuby
7
+ #
8
+ # Usage::
9
+ #
10
+ # In Rakefile:
11
+ #
12
+ # require 'datashift'
13
+ #
14
+ # DataShift::load_tasks
15
+ #
16
+ # Cmd Line:
17
+ #
18
+ # => jruby -S rake datashift:generate:excel model=<active record class> result=<output_template.xls>
19
+ #
20
+ namespace :datashift do
21
+ namespace :generate do
22
+
23
+ desc "Generate a template .xls (Excel) file for a model"
24
+
25
+ task :excel, [:model, :result] => [:environment] do |t, args|
26
+
27
+ require 'excel_generator'
28
+
29
+ # in familiar ruby style args seems to have been become empty using this new style for rake 0.9.2
30
+ # whatever format i try, on both Win and OSX .. so had to revert back to ENV
31
+ model = args[:model] || ENV['model']
32
+ result = args[:result] || ENV['result']
33
+
34
+ raise "USAGE: jruby -S rake datashift:generate:excel model=<Class> result=<file.xls>" unless(result)
35
+ raise "ERROR: Cannot process without AR Model - please supply model=<Class>" unless(model)
36
+
37
+ begin
38
+ klass = Kernel.const_get(model)
39
+ rescue NameError
40
+ raise "ERROR: No such AR Model found - check valid model supplied via model=<Class>"
41
+ end
42
+
43
+ gen = DataShift::ExcelGenerator.new(result)
44
+
45
+ gen.generate(klass)
46
+ end
47
+
48
+ end
49
+
50
+ namespace :export do
51
+
52
+ desc "Export active record data to .xls (Excel) file"
53
+
54
+ task :excel, [:model, :result] => [:environment] do |t, args|
55
+
56
+ require 'excel_generator'
57
+
58
+ # in familiar ruby style args seems to have been become empty using this new style for rake 0.9.2
59
+ # whatever format i try, on both Win and OSX .. so had to revert back to ENV
60
+ model = ENV['model']
61
+ result = ENV['result']
62
+
63
+ raise "USAGE: jruby -S rake datashift:gen:excel model=<Class> result=<file.xls>" unless(result)
64
+ raise "ERROR: Cannot process without AR Model - please supply model=<Class>" unless(model)
65
+
66
+ begin
67
+ klass = Kernel.const_get(model)
68
+ rescue NameError
69
+ raise "ERROR: No such AR Model found - check valid model supplied via model=<Class>"
70
+ end
71
+
72
+ gen = DataShift::ExcelGenerator.new(result)
73
+
74
+ gen.export(klass.all)
75
+ end
76
+
77
+ end
78
+
79
79
  end
@@ -1,37 +1,37 @@
1
- # Copyright:: (c) Autotelik Media Ltd 2011
2
- # Author :: Tom Statter
3
- # Date :: Feb 2011
4
- # License:: MIT
5
- #
6
- # Usage:: rake datashift:file_rename input=/blah image_load input=path_to_images
7
- #
8
- namespace :datashift do
9
-
10
- desc "copy or mv a folder of files, consistently renaming in the process"
11
- task :file_rename, :input, :offset, :prefix, :width, :commit, :mv do |t, args|
12
- raise "USAGE: rake file_rename input='C:\blah' [offset=n prefix='str' width=n]" unless args[:input] && File.exists?(args[:input])
13
- width = args[:width] || 2
14
-
15
- action = args[:mv] ? 'mv' : 'cp'
16
-
17
- cache = args[:input]
18
-
19
- if(File.exists?(cache) )
20
- puts "Renaming files from #{cache}"
21
- Dir.glob(File.join(cache, "*")) do |name|
22
- path, base_name = File.split(name)
23
- id = base_name.slice!(/\w+/)
24
-
25
- id = id.to_i + args[:offset].to_i if(args[:offset])
26
- id = "%0#{width}d" % id.to_i if(args[:width])
27
- id = args[:prefix] + id.to_s if(args[:prefix])
28
-
29
- destination = File.join(path, "#{id}#{base_name}")
30
- puts "ACTION: #{action} #{name} #{destination}"
31
-
32
- File.send( action, name, destination) if args[:commit]
33
- end
34
- end
35
- end
36
-
1
+ # Copyright:: (c) Autotelik Media Ltd 2011
2
+ # Author :: Tom Statter
3
+ # Date :: Feb 2011
4
+ # License:: MIT
5
+ #
6
+ # Usage:: rake datashift:file_rename input=/blah image_load input=path_to_images
7
+ #
8
+ namespace :datashift do
9
+
10
+ desc "copy or mv a folder of files, consistently renaming in the process"
11
+ task :file_rename, :input, :offset, :prefix, :width, :commit, :mv do |t, args|
12
+ raise "USAGE: rake file_rename input='C:\blah' [offset=n prefix='str' width=n]" unless args[:input] && File.exists?(args[:input])
13
+ width = args[:width] || 2
14
+
15
+ action = args[:mv] ? 'mv' : 'cp'
16
+
17
+ cache = args[:input]
18
+
19
+ if(File.exists?(cache) )
20
+ puts "Renaming files from #{cache}"
21
+ Dir.glob(File.join(cache, "*")) do |name|
22
+ path, base_name = File.split(name)
23
+ id = base_name.slice!(/\w+/)
24
+
25
+ id = id.to_i + args[:offset].to_i if(args[:offset])
26
+ id = "%0#{width}d" % id.to_i if(args[:width])
27
+ id = args[:prefix] + id.to_s if(args[:prefix])
28
+
29
+ destination = File.join(path, "#{id}#{base_name}")
30
+ puts "ACTION: #{action} #{name} #{destination}"
31
+
32
+ File.send( action, name, destination) if args[:commit]
33
+ end
34
+ end
35
+ end
36
+
37
37
  end
@@ -1,50 +1,50 @@
1
- # Copyright:: (c) Autotelik Media Ltd 2011
2
- # Author :: Tom Statter
3
- # Date :: Aug 2011
4
- # License:: MIT
5
- #
6
- # Usage::
7
- #
8
- # In Rakefile:
9
- #
10
- # require 'datashift'
11
- #
12
- # DataShift::load_tasks
13
- #
14
- # Cmd Line:
15
- #
16
- # => jruby -S rake datashift:import:csv model=<active record class> input=<file.csv>
17
- #
18
- namespace :datashift do
19
-
20
- namespace :import do
21
-
22
- desc "Populate a model's table in db with data from CSV file"
23
- task :csv, [:model, :loader, :input, :verbose] => [:environment] do |t, args|
24
-
25
- # in familiar ruby style args seems to have been become empty with rake 0.9.2 whatever i try
26
- # so had to revert back to ENV
27
- model = ENV['model']
28
- input = ENV['input']
29
-
30
- raise "USAGE: rake datashift:import:csv input=file.csv model=<Class>" unless(input)
31
- raise "ERROR: Cannot process without AR Model - please supply model=<Class>" unless(model)
32
- raise "ERROR: Could not find csv file #{args[:input]}" unless File.exists?(input)
33
-
34
- require 'csv_loader'
35
-
36
- begin
37
- klass = Kernel.const_get(model)
38
- rescue NameError
39
- raise "ERROR: No such AR Model found - check valid model supplied via model=<Class>"
40
- end
41
-
42
- puts "INFO: Using CSV loader"
43
-
44
- loader = DataShift::CsvLoader.new(klass)
45
-
46
- loader.perform_load(input)
47
- end
48
- end
49
-
1
+ # Copyright:: (c) Autotelik Media Ltd 2011
2
+ # Author :: Tom Statter
3
+ # Date :: Aug 2011
4
+ # License:: MIT
5
+ #
6
+ # Usage::
7
+ #
8
+ # In Rakefile:
9
+ #
10
+ # require 'datashift'
11
+ #
12
+ # DataShift::load_tasks
13
+ #
14
+ # Cmd Line:
15
+ #
16
+ # => jruby -S rake datashift:import:csv model=<active record class> input=<file.csv>
17
+ #
18
+ namespace :datashift do
19
+
20
+ namespace :import do
21
+
22
+ desc "Populate a model's table in db with data from CSV file"
23
+ task :csv, [:model, :loader, :input, :verbose] => [:environment] do |t, args|
24
+
25
+ # in familiar ruby style args seems to have been become empty with rake 0.9.2 whatever i try
26
+ # so had to revert back to ENV
27
+ model = ENV['model']
28
+ input = ENV['input']
29
+
30
+ raise "USAGE: rake datashift:import:csv input=file.csv model=<Class>" unless(input)
31
+ raise "ERROR: Cannot process without AR Model - please supply model=<Class>" unless(model)
32
+ raise "ERROR: Could not find csv file #{args[:input]}" unless File.exists?(input)
33
+
34
+ require 'csv_loader'
35
+
36
+ begin
37
+ klass = Kernel.const_get(model)
38
+ rescue NameError
39
+ raise "ERROR: No such AR Model found - check valid model supplied via model=<Class>"
40
+ end
41
+
42
+ puts "INFO: Using CSV loader"
43
+
44
+ loader = DataShift::CsvLoader.new(klass)
45
+
46
+ loader.perform_load(input)
47
+ end
48
+ end
49
+
50
50
  end