datashift 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -5
- data/LICENSE.txt +26 -26
- data/README.markdown +326 -305
- data/README.rdoc +19 -19
- data/Rakefile +86 -93
- data/VERSION +1 -1
- data/datashift.gemspec +163 -152
- data/lib/applications/jruby/jexcel_file.rb +410 -408
- data/lib/applications/jruby/word.rb +79 -79
- data/lib/datashift.rb +183 -152
- data/lib/datashift/exceptions.rb +11 -11
- data/lib/datashift/file_definitions.rb +353 -353
- data/lib/datashift/mapping_file_definitions.rb +87 -87
- data/lib/datashift/method_detail.rb +293 -275
- data/lib/datashift/method_dictionary.rb +208 -209
- data/lib/datashift/method_mapper.rb +90 -90
- data/lib/datashift/model_mapper.rb +27 -0
- data/lib/exporters/csv_exporter.rb +36 -0
- data/lib/exporters/excel_exporter.rb +116 -0
- data/lib/exporters/exporter_base.rb +15 -0
- data/lib/generators/csv_generator.rb +36 -36
- data/lib/generators/excel_generator.rb +106 -122
- data/lib/generators/generator_base.rb +13 -13
- data/lib/helpers/core_ext/to_b.rb +24 -24
- data/lib/helpers/rake_utils.rb +42 -0
- data/lib/helpers/spree_helper.rb +194 -153
- data/lib/java/poi-3.7/LICENSE +507 -507
- data/lib/java/poi-3.7/NOTICE +21 -21
- data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -115
- data/lib/loaders/csv_loader.rb +98 -98
- data/lib/loaders/excel_loader.rb +155 -155
- data/lib/loaders/loader_base.rb +420 -420
- data/lib/loaders/spreadsheet_loader.rb +136 -136
- data/lib/loaders/spree/image_loader.rb +67 -63
- data/lib/loaders/spree/product_loader.rb +289 -248
- data/lib/thor/generate_excel.thor +54 -0
- data/sandbox/app/controllers/application_controller.rb +3 -0
- data/sandbox/config/application.rb +43 -0
- data/sandbox/config/database.yml +34 -0
- data/sandbox/config/environment.rb +7 -0
- data/sandbox/config/environments/development.rb +30 -0
- data/spec/csv_loader_spec.rb +30 -30
- data/spec/datashift_spec.rb +26 -26
- data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -85
- data/spec/excel_exporter_spec.rb +78 -78
- data/spec/excel_generator_spec.rb +78 -78
- data/spec/excel_loader_spec.rb +223 -223
- data/spec/file_definitions.rb +141 -141
- data/spec/fixtures/ProjectsDefaults.yml +29 -29
- data/spec/fixtures/config/database.yml +27 -27
- data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
- data/spec/fixtures/datashift_test_models_db.sqlite +0 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +4 -4
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -4
- data/spec/fixtures/spree/SpreeProducts.csv +4 -4
- data/spec/fixtures/spree/SpreeProducts.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsMultiColumn.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsWithImages.csv +4 -4
- data/spec/fixtures/spree/SpreeZoneExample.csv +5 -5
- data/spec/fixtures/test_model_defs.rb +57 -57
- data/spec/loader_spec.rb +120 -120
- data/spec/method_dictionary_spec.rb +242 -242
- data/spec/method_mapper_spec.rb +41 -41
- data/spec/spec_helper.rb +154 -116
- data/spec/spree_exporter_spec.rb +67 -0
- data/spec/spree_generator_spec.rb +77 -64
- data/spec/spree_loader_spec.rb +363 -324
- data/spec/spree_method_mapping_spec.rb +218 -214
- data/tasks/config/seed_fu_product_template.erb +15 -15
- data/tasks/config/tidy_config.txt +12 -12
- data/tasks/{excel_generator.rake → export/excel_generator.rake} +101 -78
- data/tasks/file_tasks.rake +36 -36
- data/tasks/import/csv.rake +50 -49
- data/tasks/import/excel.rake +74 -71
- data/tasks/spree/image_load.rake +108 -108
- data/tasks/spree/product_loader.rake +43 -43
- data/tasks/word_to_seedfu.rake +166 -166
- data/test/helper.rb +18 -18
- data/test/test_interact.rb +7 -7
- metadata +16 -8
- data/datashift-0.1.0.gem +0 -0
- data/tasks/db_tasks.rake +0 -66
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2012
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Mar 2012
|
4
|
+
# License:: MIT.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Usage::
|
8
|
+
#
|
9
|
+
# To pull Datashift commands into your main application :
|
10
|
+
#
|
11
|
+
# require 'datashift'
|
12
|
+
#
|
13
|
+
# DataShift::load_commands
|
14
|
+
#
|
15
|
+
# Cmd Line:
|
16
|
+
#
|
17
|
+
# => bundle exec thor datashift:generate:excel --model <active record class> --result <output_template.xls>
|
18
|
+
#
|
19
|
+
|
20
|
+
module Datashift
|
21
|
+
|
22
|
+
class Generate < Thor
|
23
|
+
|
24
|
+
desc "excel --model <Class> --result <file.xls>", "generate a template from an active record model"
|
25
|
+
method_option :model, :aliases => '-m', :required => true, :desc => "The active record model to export"
|
26
|
+
method_option :result, :aliases => '-r', :required => true, :desc => "Create template of model in supplied file"
|
27
|
+
|
28
|
+
def excel()
|
29
|
+
|
30
|
+
# TODO - We're assuming run from a rails app/top level dir...
|
31
|
+
# ...can we make this more robust ? e.g what about when using active record but not in Rails app,
|
32
|
+
require File.expand_path('config/environment.rb')
|
33
|
+
|
34
|
+
|
35
|
+
require 'excel_generator'
|
36
|
+
|
37
|
+
model = options[:model]
|
38
|
+
result = options[:result]
|
39
|
+
|
40
|
+
begin
|
41
|
+
# support modules e.g "Spree::Property")
|
42
|
+
klass = ModelMapper::class_from_string(model) #Kernel.const_get(model)
|
43
|
+
rescue NameError => e
|
44
|
+
puts e
|
45
|
+
raise "ERROR: No such Model [#{model}] found - check valid model supplied via -model <Class>"
|
46
|
+
end
|
47
|
+
|
48
|
+
gen = DataShift::ExcelGenerator.new(result)
|
49
|
+
|
50
|
+
gen.generate(klass)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rails/all'
|
2
|
+
|
3
|
+
module SpreeHelper
|
4
|
+
class Application < Rails::Application
|
5
|
+
|
6
|
+
config.to_prepare do
|
7
|
+
end
|
8
|
+
|
9
|
+
# Settings in config/environments/* take precedence over those specified here.
|
10
|
+
# Application configuration should go into files in config/initializers
|
11
|
+
# -- all .rb files in that directory are automatically loaded.
|
12
|
+
|
13
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
14
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
15
|
+
|
16
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
17
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
18
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
19
|
+
|
20
|
+
# Activate observers that should always be running.
|
21
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
22
|
+
|
23
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
24
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
25
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
26
|
+
|
27
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
28
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
29
|
+
# config.i18n.default_locale = :de
|
30
|
+
|
31
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
32
|
+
config.encoding = "utf-8"
|
33
|
+
|
34
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
35
|
+
config.filter_parameters += [:password]
|
36
|
+
|
37
|
+
# Enable the asset pipeline
|
38
|
+
config.assets.enabled = true
|
39
|
+
|
40
|
+
# Version of your assets, change this if you want to expire all your assets
|
41
|
+
config.assets.version = '1.0'
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Used by spec helper to build test databases
|
2
|
+
# These entires can be used in call to db_connect ( see spec_helper )
|
3
|
+
|
4
|
+
<% adapter = 'sqlite3' %>
|
5
|
+
<% adapter = 'jdbcsqlite3' if(Guards::jruby? ) %>
|
6
|
+
|
7
|
+
test_mysql:
|
8
|
+
adapter: jdbcmysql
|
9
|
+
database: datashift_test_models_db
|
10
|
+
username: test
|
11
|
+
password: test
|
12
|
+
host: localhost
|
13
|
+
|
14
|
+
test_memory:
|
15
|
+
adapter: <%= adapter %>
|
16
|
+
database: :memory
|
17
|
+
|
18
|
+
test_file:
|
19
|
+
adapter: <%= adapter %>
|
20
|
+
database: <%= File.join($DataShiftFixturePath, 'datashift_test_models_db.sqlite') %>
|
21
|
+
encoding: utf8
|
22
|
+
host: localhost
|
23
|
+
|
24
|
+
test_spree_standalone:
|
25
|
+
adapter: <%= adapter %>
|
26
|
+
database: <%= File.join($DataShiftFixturePath, 'datashift_Spree_db.sqlite') %>
|
27
|
+
encoding: utf8
|
28
|
+
host: localhost
|
29
|
+
|
30
|
+
development:
|
31
|
+
adapter: <%= adapter %>
|
32
|
+
database: <%= File.join($DataShiftFixturePath, 'datashift_Spree_db.sqlite') %>
|
33
|
+
encoding: utf8
|
34
|
+
host: localhost
|
@@ -0,0 +1,30 @@
|
|
1
|
+
SpreeHelper::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
|
25
|
+
# Do not compress assets
|
26
|
+
config.assets.compress = false
|
27
|
+
|
28
|
+
# Expands the lines which load the assets
|
29
|
+
config.assets.debug = true
|
30
|
+
end
|
data/spec/csv_loader_spec.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
-
# Author :: Tom Statter
|
3
|
-
# Date :: Aug 2011
|
4
|
-
# License:: MIT
|
5
|
-
#
|
6
|
-
# Details:: Specs for Excel aspect of Active Record Loader
|
7
|
-
#
|
8
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
9
|
-
|
10
|
-
require 'erb'
|
11
|
-
require 'excel_loader'
|
12
|
-
|
13
|
-
describe 'CSV Loader' do
|
14
|
-
|
15
|
-
before(:all) do
|
16
|
-
|
17
|
-
# load our test model definitions - Project etc
|
18
|
-
require File.join($DataShiftFixturePath, 'test_model_defs')
|
19
|
-
|
20
|
-
db_connect( 'test_file' ) # , test_memory, test_mysql
|
21
|
-
migrate_up
|
22
|
-
@klazz = Project
|
23
|
-
end
|
24
|
-
|
25
|
-
before(:each) do
|
26
|
-
MethodDictionary.clear
|
27
|
-
MethodDictionary.find_operators( @klazz )
|
28
|
-
MethodDictionary.find_operators( @assoc_klazz )
|
29
|
-
end
|
30
|
-
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2011
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
# Details:: Specs for Excel aspect of Active Record Loader
|
7
|
+
#
|
8
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
9
|
+
|
10
|
+
require 'erb'
|
11
|
+
require 'excel_loader'
|
12
|
+
|
13
|
+
describe 'CSV Loader' do
|
14
|
+
|
15
|
+
before(:all) do
|
16
|
+
|
17
|
+
# load our test model definitions - Project etc
|
18
|
+
require File.join($DataShiftFixturePath, 'test_model_defs')
|
19
|
+
|
20
|
+
db_connect( 'test_file' ) # , test_memory, test_mysql
|
21
|
+
migrate_up
|
22
|
+
@klazz = Project
|
23
|
+
end
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
MethodDictionary.clear
|
27
|
+
MethodDictionary.find_operators( @klazz )
|
28
|
+
MethodDictionary.find_operators( @assoc_klazz )
|
29
|
+
end
|
30
|
+
|
31
31
|
end
|
data/spec/datashift_spec.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
-
# Author :: Tom Statter
|
3
|
-
# Date :: Oct 2011
|
4
|
-
# License:: MIT
|
5
|
-
#
|
6
|
-
# Details:: Specs for high level apsects of DataShift library
|
7
|
-
#
|
8
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
9
|
-
|
10
|
-
describe 'DataShift' do
|
11
|
-
|
12
|
-
before(:each) do
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should provide gem version" do
|
16
|
-
DataShift::gem_version
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should provide gem name" do
|
20
|
-
DataShift::gem_name.should == 'datashift'
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should provide root_path" do
|
24
|
-
DataShift.root_path.should_not be_empty
|
25
|
-
end
|
26
|
-
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Oct 2011
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
# Details:: Specs for high level apsects of DataShift library
|
7
|
+
#
|
8
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
9
|
+
|
10
|
+
describe 'DataShift' do
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should provide gem version" do
|
16
|
+
DataShift::gem_version
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should provide gem name" do
|
20
|
+
DataShift::gem_name.should == 'datashift'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should provide root_path" do
|
24
|
+
DataShift.root_path.should_not be_empty
|
25
|
+
end
|
26
|
+
|
27
27
|
end
|
@@ -1,85 +1,85 @@
|
|
1
|
-
# Author :: Tom Statter
|
2
|
-
# Date :: Aug 2011
|
3
|
-
# License:: MIT
|
4
|
-
#
|
5
|
-
# Details:: Migration to create a test database that exercises all aspects of Active Record models
|
6
|
-
#
|
7
|
-
|
8
|
-
class CreateTestBed < ActiveRecord::Migration
|
9
|
-
|
10
|
-
def self.up
|
11
|
-
|
12
|
-
# has many :milestones
|
13
|
-
create_table :projects do |t|
|
14
|
-
t.string :title
|
15
|
-
t.string :value_as_string
|
16
|
-
t.text :value_as_text
|
17
|
-
t.boolean :value_as_boolean, :default => false
|
18
|
-
t.datetime :value_as_datetime, :default => nil
|
19
|
-
t.integer :value_as_integer, :default => 0
|
20
|
-
t.decimal :value_as_double, :precision => 8, :scale => 2, :default => 0.0
|
21
|
-
t.timestamps
|
22
|
-
end
|
23
|
-
|
24
|
-
# belongs_to :project, project => has_many
|
25
|
-
create_table :milestones do |t|
|
26
|
-
t.string :name
|
27
|
-
t.datetime :datetime, :default => nil
|
28
|
-
t.decimal :cost, :precision => 8, :scale => 2, :default => 0.0
|
29
|
-
t.references :project
|
30
|
-
t.timestamps
|
31
|
-
end
|
32
|
-
|
33
|
-
# belongs_to :project, project => has_one
|
34
|
-
create_table :owners do |t|
|
35
|
-
t.string :name
|
36
|
-
t.references :project
|
37
|
-
t.timestamps
|
38
|
-
end
|
39
|
-
|
40
|
-
# has_belongs_to_many :project
|
41
|
-
create_table :categories do |t|
|
42
|
-
t.string :reference
|
43
|
-
t.timestamps
|
44
|
-
end
|
45
|
-
|
46
|
-
# testing has_belongs_to_many (hence no id)
|
47
|
-
create_table :categories_projects, :id => false do |t|
|
48
|
-
t.references :category
|
49
|
-
t.references :project
|
50
|
-
end
|
51
|
-
|
52
|
-
create_table :versions do |t|
|
53
|
-
t.string :name
|
54
|
-
t.timestamps
|
55
|
-
end
|
56
|
-
|
57
|
-
# testing project has_many release + versions :through
|
58
|
-
create_table :loader_releases do |t|
|
59
|
-
t.string :name
|
60
|
-
t.references :project
|
61
|
-
t.references :version
|
62
|
-
t.timestamps
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
create_table :long_and_complex_table_linked_to_versions do |t|
|
67
|
-
t.references :version
|
68
|
-
end
|
69
|
-
|
70
|
-
create_table :empties do |t|
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.down
|
76
|
-
drop_table :projects
|
77
|
-
drop_table :categories
|
78
|
-
drop_table :loader_releases
|
79
|
-
drop_table :versions
|
80
|
-
drop_table :categories_projectss
|
81
|
-
drop_table :milestones
|
82
|
-
drop_table :long_and_complex_table_linked_to_versions
|
83
|
-
drop_table :empties
|
84
|
-
end
|
85
|
-
end
|
1
|
+
# Author :: Tom Statter
|
2
|
+
# Date :: Aug 2011
|
3
|
+
# License:: MIT
|
4
|
+
#
|
5
|
+
# Details:: Migration to create a test database that exercises all aspects of Active Record models
|
6
|
+
#
|
7
|
+
|
8
|
+
class CreateTestBed < ActiveRecord::Migration
|
9
|
+
|
10
|
+
def self.up
|
11
|
+
|
12
|
+
# has many :milestones
|
13
|
+
create_table :projects do |t|
|
14
|
+
t.string :title
|
15
|
+
t.string :value_as_string
|
16
|
+
t.text :value_as_text
|
17
|
+
t.boolean :value_as_boolean, :default => false
|
18
|
+
t.datetime :value_as_datetime, :default => nil
|
19
|
+
t.integer :value_as_integer, :default => 0
|
20
|
+
t.decimal :value_as_double, :precision => 8, :scale => 2, :default => 0.0
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
|
24
|
+
# belongs_to :project, project => has_many
|
25
|
+
create_table :milestones do |t|
|
26
|
+
t.string :name
|
27
|
+
t.datetime :datetime, :default => nil
|
28
|
+
t.decimal :cost, :precision => 8, :scale => 2, :default => 0.0
|
29
|
+
t.references :project
|
30
|
+
t.timestamps
|
31
|
+
end
|
32
|
+
|
33
|
+
# belongs_to :project, project => has_one
|
34
|
+
create_table :owners do |t|
|
35
|
+
t.string :name
|
36
|
+
t.references :project
|
37
|
+
t.timestamps
|
38
|
+
end
|
39
|
+
|
40
|
+
# has_belongs_to_many :project
|
41
|
+
create_table :categories do |t|
|
42
|
+
t.string :reference
|
43
|
+
t.timestamps
|
44
|
+
end
|
45
|
+
|
46
|
+
# testing has_belongs_to_many (hence no id)
|
47
|
+
create_table :categories_projects, :id => false do |t|
|
48
|
+
t.references :category
|
49
|
+
t.references :project
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table :versions do |t|
|
53
|
+
t.string :name
|
54
|
+
t.timestamps
|
55
|
+
end
|
56
|
+
|
57
|
+
# testing project has_many release + versions :through
|
58
|
+
create_table :loader_releases do |t|
|
59
|
+
t.string :name
|
60
|
+
t.references :project
|
61
|
+
t.references :version
|
62
|
+
t.timestamps
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
create_table :long_and_complex_table_linked_to_versions do |t|
|
67
|
+
t.references :version
|
68
|
+
end
|
69
|
+
|
70
|
+
create_table :empties do |t|
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.down
|
76
|
+
drop_table :projects
|
77
|
+
drop_table :categories
|
78
|
+
drop_table :loader_releases
|
79
|
+
drop_table :versions
|
80
|
+
drop_table :categories_projectss
|
81
|
+
drop_table :milestones
|
82
|
+
drop_table :long_and_complex_table_linked_to_versions
|
83
|
+
drop_table :empties
|
84
|
+
end
|
85
|
+
end
|