datashift 0.16.0 → 0.40.0
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.
- checksums.yaml +4 -4
- data/{LICENSE.txt → LICENSE} +0 -0
- data/Rakefile +1 -20
- data/datashift.thor +125 -0
- data/lib/applications/apache_poi_extensions.rb +21 -52
- data/lib/applications/excel.rb +64 -57
- data/lib/applications/hssf_row_extensions.rb +66 -0
- data/lib/applications/jexcel_file.rb +99 -95
- data/lib/applications/jexcel_file_extensions.rb +76 -83
- data/lib/applications/jruby/word.rb +36 -36
- data/lib/applications/ruby_poi_translations.rb +34 -32
- data/lib/applications/spreadsheet_extensions.rb +21 -19
- data/lib/datashift.rb +49 -59
- data/lib/datashift/binder.rb +217 -0
- data/lib/datashift/column_packer.rb +21 -72
- data/lib/datashift/configuration.rb +317 -0
- data/lib/datashift/context_factory.rb +88 -0
- data/lib/datashift/core_ext/array.rb +15 -0
- data/lib/datashift/core_ext/csv_ext.rb +46 -0
- data/lib/datashift/core_ext/string.rb +49 -0
- data/lib/datashift/core_ext/to_b.rb +11 -0
- data/lib/datashift/delimiters.rb +55 -61
- data/lib/datashift/doc_context.rb +137 -0
- data/lib/datashift/excel_base.rb +93 -81
- data/lib/datashift/exceptions.rb +30 -28
- data/lib/datashift/file_definitions.rb +44 -39
- data/lib/datashift/guards.rb +5 -5
- data/lib/datashift/header.rb +25 -0
- data/lib/datashift/headers.rb +94 -0
- data/lib/datashift/inbound_data/column.rb +44 -0
- data/lib/datashift/inbound_data/lookup_support.rb +33 -0
- data/lib/datashift/inbound_data/method_binding.rb +139 -0
- data/lib/datashift/load_object.rb +37 -12
- data/lib/datashift/logging.rb +54 -27
- data/lib/datashift/mandatory.rb +39 -0
- data/lib/datashift/mapping/data_flow_schema.rb +198 -0
- data/lib/datashift/{model_mapper.rb → mapping/mapper_utils.rb} +30 -10
- data/lib/datashift/model_methods/catalogue.rb +183 -0
- data/lib/datashift/model_methods/collection.rb +140 -0
- data/lib/datashift/model_methods/model_method.rb +162 -0
- data/lib/datashift/model_methods/model_methods_manager.rb +76 -0
- data/lib/datashift/model_methods/operator.rb +62 -0
- data/lib/datashift/node_collection.rb +26 -0
- data/lib/datashift/node_context.rb +68 -0
- data/lib/datashift/populator.rb +308 -282
- data/lib/datashift/progress_monitor.rb +91 -0
- data/lib/datashift/querying.rb +110 -52
- data/lib/datashift/templates/import_export_config.erb +55 -0
- data/lib/datashift/transformation/factory.rb +219 -0
- data/lib/datashift/transformation/remove.rb +44 -0
- data/lib/datashift/version.rb +3 -0
- data/lib/exporters/configuration.rb +84 -0
- data/lib/exporters/csv_exporter.rb +54 -52
- data/lib/exporters/excel_exporter.rb +80 -61
- data/lib/exporters/exporter_base.rb +8 -8
- data/lib/generators/config_generator.rb +218 -0
- data/lib/generators/csv_generator.rb +13 -70
- data/lib/generators/excel_generator.rb +23 -111
- data/lib/generators/generator_base.rb +15 -70
- data/lib/loaders/configuration.rb +90 -0
- data/lib/loaders/csv_loader.rb +63 -101
- data/lib/loaders/excel_loader.rb +71 -156
- data/lib/loaders/failure_data.rb +40 -0
- data/lib/loaders/file_loader.rb +16 -0
- data/lib/loaders/loader_base.rb +82 -410
- data/lib/loaders/loader_factory.rb +42 -0
- data/lib/loaders/paperclip/attachment_loader.rb +157 -140
- data/lib/loaders/paperclip/datashift_paperclip.rb +18 -35
- data/lib/loaders/paperclip/image_loading.rb +40 -35
- data/lib/loaders/reporters/basic_stdout_reporter.rb +40 -0
- data/lib/loaders/reporters/reporter.rb +26 -0
- data/lib/tasks/config.thor +65 -0
- data/{tasks → lib/tasks}/config/seed_fu_product_template.erb +0 -0
- data/{tasks → lib/tasks}/config/tidy_config.txt +0 -0
- data/lib/tasks/export.thor +192 -0
- data/lib/tasks/generate.thor +190 -0
- data/lib/tasks/import.thor +142 -0
- data/lib/{thor → tasks}/paperclip.thor +69 -69
- data/{tasks → lib/tasks/to_convert_to_thor}/db_tasks.rake +20 -20
- data/lib/tasks/tools.thor +109 -0
- data/spec/MissingAttachmentRecords/DEMO_001_ror_bag.jpeg +0 -0
- data/spec/MissingAttachmentRecords/DEMO_002_Powerstation.jpeg +0 -0
- data/spec/MissingAttachmentRecords/DEMO_003_ror_mug.jpeg +0 -0
- data/spec/MissingAttachmentRecords/DEMO_004_ror_ringer.jpeg +0 -0
- data/spec/datashift/binder_spec.rb +266 -0
- data/spec/datashift/config_generator_spec.rb +186 -0
- data/spec/datashift/configuration.rb +66 -0
- data/spec/datashift/context_factory_spec.rb +63 -0
- data/spec/datashift/data_flow_schema_spec.rb +150 -0
- data/spec/datashift/datashift_spec.rb +52 -0
- data/spec/datashift/excel_base_spec.rb +57 -0
- data/spec/datashift/excel_spec.rb +188 -0
- data/spec/datashift/failure_data_spec.rb +27 -0
- data/spec/{file_definitions.rb → datashift/file_definitions.rb} +9 -10
- data/spec/datashift/headers_spec.rb +56 -0
- data/spec/datashift/inbound_data_spec.rb +47 -0
- data/spec/datashift/mapper_utils_spec.rb +38 -0
- data/spec/datashift/method_binding_spec.rb +60 -0
- data/spec/datashift/model_method_spec.rb +109 -0
- data/spec/datashift/model_methods_catalogue.rb +111 -0
- data/spec/datashift/model_methods_collection_spec.rb +138 -0
- data/spec/datashift/model_methods_manager_spec.rb +329 -0
- data/spec/datashift/populator_spec.rb +117 -0
- data/spec/datashift/thor_spec.rb +314 -0
- data/spec/datashift/transformation/factory_spec.rb +195 -0
- data/spec/datashift/transformation/transformer_remove_spec.rb +43 -0
- data/spec/dummy/Gemfile +53 -0
- data/spec/dummy/Gemfile.lock +197 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/javascripts/categories.js +2 -0
- data/spec/dummy/app/assets/javascripts/digitals.js +2 -0
- data/spec/dummy/app/assets/javascripts/empties.js +2 -0
- data/spec/dummy/app/assets/javascripts/loader_releases.js +2 -0
- data/spec/dummy/app/assets/javascripts/long_and_complex_table_linked_to_versions.js +2 -0
- data/spec/dummy/app/assets/javascripts/milestones.js +2 -0
- data/spec/dummy/app/assets/javascripts/owners.js +2 -0
- data/spec/dummy/app/assets/javascripts/projects.js +2 -0
- data/spec/dummy/app/assets/javascripts/users.js +2 -0
- data/spec/dummy/app/assets/javascripts/versions.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/categories.css +4 -0
- data/spec/dummy/app/assets/stylesheets/digitals.css +4 -0
- data/spec/dummy/app/assets/stylesheets/empties.css +4 -0
- data/spec/dummy/app/assets/stylesheets/loader_releases.css +4 -0
- data/spec/dummy/app/assets/stylesheets/long_and_complex_table_linked_to_versions.css +4 -0
- data/spec/dummy/app/assets/stylesheets/milestones.css +4 -0
- data/spec/dummy/app/assets/stylesheets/owners.css +4 -0
- data/spec/dummy/app/assets/stylesheets/projects.css +4 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/dummy/app/assets/stylesheets/users.css +4 -0
- data/spec/dummy/app/assets/stylesheets/versions.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/categories_controller.rb +58 -0
- data/spec/dummy/app/controllers/digitals_controller.rb +58 -0
- data/spec/dummy/app/controllers/empties_controller.rb +58 -0
- data/spec/dummy/app/controllers/loader_releases_controller.rb +58 -0
- data/spec/dummy/app/controllers/long_and_complex_table_linked_to_versions_controller.rb +58 -0
- data/spec/dummy/app/controllers/milestones_controller.rb +58 -0
- data/spec/dummy/app/controllers/owners_controller.rb +58 -0
- data/spec/dummy/app/controllers/projects_controller.rb +58 -0
- data/spec/dummy/app/controllers/users_controller.rb +58 -0
- data/spec/dummy/app/controllers/versions_controller.rb +58 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/categories_helper.rb +2 -0
- data/spec/dummy/app/helpers/digitals_helper.rb +2 -0
- data/spec/dummy/app/helpers/empties_helper.rb +2 -0
- data/spec/dummy/app/helpers/loader_releases_helper.rb +2 -0
- data/spec/dummy/app/helpers/long_and_complex_table_linked_to_versions_helper.rb +2 -0
- data/spec/dummy/app/helpers/milestones_helper.rb +2 -0
- data/spec/dummy/app/helpers/owners_helper.rb +2 -0
- data/spec/dummy/app/helpers/projects_helper.rb +2 -0
- data/spec/dummy/app/helpers/users_helper.rb +2 -0
- data/spec/dummy/app/helpers/versions_helper.rb +2 -0
- data/spec/dummy/app/models/category.rb +6 -0
- data/spec/dummy/app/models/digital.rb +22 -0
- data/spec/dummy/app/models/empty.rb +2 -0
- data/spec/dummy/app/models/loader_release.rb +10 -0
- data/spec/dummy/app/models/long_and_complex_table_linked_to_version.rb +6 -0
- data/spec/dummy/app/models/milestone.rb +15 -0
- data/spec/dummy/app/models/owner.rb +13 -0
- data/spec/dummy/app/models/project.rb +53 -0
- data/spec/dummy/app/models/user.rb +5 -0
- data/spec/dummy/app/models/version.rb +7 -0
- data/spec/dummy/app/views/categories/_form.html.erb +17 -0
- data/spec/dummy/app/views/categories/edit.html.erb +6 -0
- data/spec/dummy/app/views/categories/index.html.erb +25 -0
- data/spec/dummy/app/views/categories/new.html.erb +5 -0
- data/spec/dummy/app/views/categories/show.html.erb +4 -0
- data/spec/dummy/app/views/digitals/_form.html.erb +17 -0
- data/spec/dummy/app/views/digitals/edit.html.erb +6 -0
- data/spec/dummy/app/views/digitals/index.html.erb +25 -0
- data/spec/dummy/app/views/digitals/new.html.erb +5 -0
- data/spec/dummy/app/views/digitals/show.html.erb +4 -0
- data/spec/dummy/app/views/empties/_form.html.erb +17 -0
- data/spec/dummy/app/views/empties/edit.html.erb +6 -0
- data/spec/dummy/app/views/empties/index.html.erb +25 -0
- data/spec/dummy/app/views/empties/new.html.erb +5 -0
- data/spec/dummy/app/views/empties/show.html.erb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/loader_releases/_form.html.erb +17 -0
- data/spec/dummy/app/views/loader_releases/edit.html.erb +6 -0
- data/spec/dummy/app/views/loader_releases/index.html.erb +25 -0
- data/spec/dummy/app/views/loader_releases/new.html.erb +5 -0
- data/spec/dummy/app/views/loader_releases/show.html.erb +4 -0
- data/spec/dummy/app/views/long_and_complex_table_linked_to_versions/_form.html.erb +17 -0
- data/spec/dummy/app/views/long_and_complex_table_linked_to_versions/edit.html.erb +6 -0
- data/spec/dummy/app/views/long_and_complex_table_linked_to_versions/index.html.erb +25 -0
- data/spec/dummy/app/views/long_and_complex_table_linked_to_versions/new.html.erb +5 -0
- data/spec/dummy/app/views/long_and_complex_table_linked_to_versions/show.html.erb +4 -0
- data/spec/dummy/app/views/milestones/_form.html.erb +17 -0
- data/spec/dummy/app/views/milestones/edit.html.erb +6 -0
- data/spec/dummy/app/views/milestones/index.html.erb +25 -0
- data/spec/dummy/app/views/milestones/new.html.erb +5 -0
- data/spec/dummy/app/views/milestones/show.html.erb +4 -0
- data/spec/dummy/app/views/owners/_form.html.erb +17 -0
- data/spec/dummy/app/views/owners/edit.html.erb +6 -0
- data/spec/dummy/app/views/owners/index.html.erb +25 -0
- data/spec/dummy/app/views/owners/new.html.erb +5 -0
- data/spec/dummy/app/views/owners/show.html.erb +4 -0
- data/spec/dummy/app/views/projects/_form.html.erb +17 -0
- data/spec/dummy/app/views/projects/edit.html.erb +6 -0
- data/spec/dummy/app/views/projects/index.html.erb +25 -0
- data/spec/dummy/app/views/projects/new.html.erb +5 -0
- data/spec/dummy/app/views/projects/show.html.erb +4 -0
- data/spec/dummy/app/views/users/_form.html.erb +17 -0
- data/spec/dummy/app/views/users/edit.html.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +25 -0
- data/spec/dummy/app/views/users/new.html.erb +5 -0
- data/spec/dummy/app/views/users/show.html.erb +4 -0
- data/spec/dummy/app/views/versions/_form.html.erb +17 -0
- data/spec/dummy/app/views/versions/edit.html.erb +6 -0
- data/spec/dummy/app/views/versions/index.html.erb +25 -0
- data/spec/dummy/app/views/versions/new.html.erb +5 -0
- data/spec/dummy/app/views/versions/show.html.erb +4 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +9 -0
- data/spec/dummy/bin/rake +9 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/bin/spring +16 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +26 -0
- data/spec/dummy/config/boot.rb +3 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +76 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20110803201325_create_test_bed.rb +98 -0
- data/spec/dummy/db/migrate/20121009161700_add_digitals.rb +24 -0
- data/spec/dummy/db/migrate/20161005123106_create_digitals.rb +8 -0
- data/spec/dummy/db/migrate/20161005123106_create_long_and_complex_table_linked_to_versions.rb +8 -0
- data/spec/dummy/db/migrate/20161005123107_create_loader_releases.rb +8 -0
- data/spec/dummy/db/migrate/20161005123108_create_owners.rb +8 -0
- data/spec/dummy/db/migrate/20161005123109_create_empties.rb +8 -0
- data/spec/dummy/db/migrate/20161005123110_create_projects.rb +8 -0
- data/spec/dummy/db/migrate/20161005123111_create_users.rb +8 -0
- data/spec/dummy/db/migrate/20161005123111_create_versions.rb +8 -0
- data/spec/dummy/db/migrate/20161005123112_create_milestones.rb +8 -0
- data/spec/dummy/db/migrate/20161005123113_create_categories.rb +8 -0
- data/spec/dummy/db/schema.rb +93 -0
- data/spec/dummy/db/seeds.rb +9 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +69 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/sandbox_example.thor +4 -0
- data/spec/dummy/test/controllers/categories_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/digitals_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/empties_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/loader_releases_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/long_and_complex_table_linked_to_versions_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/milestones_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/owners_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/projects_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/users_controller_test.rb +49 -0
- data/spec/dummy/test/controllers/versions_controller_test.rb +49 -0
- data/spec/dummy/test/factories/categories.rb +5 -0
- data/spec/dummy/test/factories/digitals.rb +5 -0
- data/spec/dummy/test/factories/empties.rb +5 -0
- data/spec/dummy/test/factories/loader_releases.rb +5 -0
- data/spec/dummy/test/factories/long_and_complex_table_linked_to_versions.rb +5 -0
- data/spec/dummy/test/factories/milestones.rb +5 -0
- data/spec/dummy/test/factories/owners.rb +5 -0
- data/spec/dummy/test/factories/projects.rb +5 -0
- data/spec/dummy/test/factories/users.rb +5 -0
- data/spec/dummy/test/factories/versions.rb +5 -0
- data/spec/dummy/test/models/category_test.rb +7 -0
- data/spec/dummy/test/models/digital_test.rb +7 -0
- data/spec/dummy/test/models/empty_test.rb +7 -0
- data/spec/dummy/test/models/loader_release_test.rb +7 -0
- data/spec/dummy/test/models/long_and_complex_table_linked_to_version_test.rb +7 -0
- data/spec/dummy/test/models/milestone_test.rb +7 -0
- data/spec/dummy/test/models/owner_test.rb +7 -0
- data/spec/dummy/test/models/project_test.rb +7 -0
- data/spec/dummy/test/models/user_test.rb +7 -0
- data/spec/dummy/test/models/version_test.rb +7 -0
- data/spec/dummy/test/test_helper.rb +10 -0
- data/spec/exporters/csv_exporter_spec.rb +240 -0
- data/spec/exporters/csv_generator_spec.rb +139 -0
- data/spec/exporters/excel_exporter_spec.rb +193 -0
- data/spec/exporters/excel_generator_spec.rb +181 -0
- data/spec/exporters/generator_base_spec.rb +45 -0
- data/spec/factories/categories.rb +7 -0
- data/spec/factories/factories.rb +18 -0
- data/spec/factories/milestone.rb +16 -0
- data/spec/factories/projects.rb +41 -0
- data/spec/fixtures/BadAssociationName.xls +0 -0
- data/spec/fixtures/DemoNegativeTesting.xls +0 -0
- data/spec/fixtures/ProjectConfiguration.yml +18 -0
- data/spec/fixtures/ProjectsMultiCategories.xls +0 -0
- data/spec/fixtures/ProjectsMultiCategoriesHeaderLookup.xls +0 -0
- data/spec/fixtures/ProjectsSingleCategories.xls +0 -0
- data/spec/fixtures/ProjectsSingleCategories.xlsx +0 -0
- data/spec/fixtures/SimpleProjects.xls +0 -0
- data/spec/fixtures/config/database.yml +28 -0
- data/spec/fixtures/csv/BadAssociationName.csv +6 -0
- data/spec/fixtures/csv/DemoNegativeTesting.csv +6 -0
- data/spec/fixtures/csv/ProjectsMultiCategories.csv +5 -0
- data/spec/fixtures/csv/ProjectsMultiCategoriesHeaderLookup.csv +5 -0
- data/spec/fixtures/csv/ProjectsSingleCategories.csv +5 -0
- data/spec/fixtures/csv/SimpleProjects.csv +4 -0
- data/spec/fixtures/db/migrate/20110803201325_create_test_bed.rb +98 -0
- data/spec/fixtures/db/migrate/20121009161700_add_digitals.rb +24 -0
- data/spec/fixtures/db/seeds.rb +9 -0
- data/spec/fixtures/images/DEMO_001_ror_bag.jpeg +0 -0
- data/spec/fixtures/images/DEMO_002_Powerstation.jpeg +0 -0
- data/spec/fixtures/images/DEMO_003_ror_mug.jpeg +0 -0
- data/spec/fixtures/images/DEMO_004_ror_ringer.jpeg +0 -0
- data/spec/fixtures/load_datashift.thor +3 -0
- data/spec/fixtures/models/category.rb +6 -0
- data/spec/fixtures/models/digital.rb +22 -0
- data/spec/fixtures/models/empty.rb +2 -0
- data/spec/fixtures/models/loader_release.rb +10 -0
- data/spec/fixtures/models/long_and_complex_table_linked_to_version.rb +6 -0
- data/spec/fixtures/models/milestone.rb +15 -0
- data/spec/fixtures/models/owner.rb +13 -0
- data/spec/fixtures/models/project.rb +53 -0
- data/spec/fixtures/models/user.rb +5 -0
- data/spec/fixtures/models/version.rb +7 -0
- data/spec/fixtures/results/exp_project_assoc_headers.xls +0 -0
- data/spec/fixtures/results/exp_project_collection_spec.csv +2 -0
- data/spec/fixtures/results/exp_project_export.xls +0 -0
- data/spec/fixtures/results/exp_project_first_export.xls +0 -0
- data/spec/fixtures/results/exp_project_plus_assoc.xls +0 -0
- data/spec/fixtures/results/exp_project_plus_assoc_export_spec.csv +9 -0
- data/spec/fixtures/results/gen_project_plus_assoc_template.xls +0 -0
- data/spec/fixtures/results/gen_project_plus_some_assoc_template.xls +0 -0
- data/spec/fixtures/results/gen_project_template.xls +0 -0
- data/spec/fixtures/results/project_and_assoc_in_hash_export.xls +0 -0
- data/spec/fixtures/results/project_and_assoc_in_json_export.csv +9 -0
- data/spec/fixtures/results/project_and_assoc_in_json_export.xls +0 -0
- data/spec/fixtures/results/project_export_spec_with_custom_delim_,.csv +2 -0
- data/spec/fixtures/results/project_export_spec_with_custom_delim_/302/243.csv +2 -0
- data/spec/fixtures/results/project_export_spec_with_custom_delim_/302/247.csv +2 -0
- data/spec/fixtures/results/project_plus_assoc_template.csv +1 -0
- data/spec/fixtures/results/project_plus_some_assoc_template.csv +1 -0
- data/spec/fixtures/results/project_remove_export_spec.csv +2 -0
- data/spec/fixtures/results/project_template.csv +1 -0
- data/spec/fixtures/results/project_with_methods_export_spec.csv +2 -0
- data/spec/fixtures/results/thor_spec_gen_project.csv +1 -0
- data/spec/fixtures/sandbox_example.thor +4 -0
- data/spec/fixtures/simple_export_spec.xls +0 -0
- data/spec/fixtures/simple_template_spec.xls +0 -0
- data/spec/fixtures/test_model_defs.rb +7 -0
- data/spec/loaders/csv_loader_spec.rb +206 -0
- data/spec/loaders/data_flow_excel_loader_spec.rb +290 -0
- data/spec/loaders/excel_loader_failures_spec.rb +67 -0
- data/spec/loaders/excel_loader_spec.rb +294 -0
- data/spec/loaders/loader_base_spec.rb +29 -0
- data/spec/loaders/paperclip_loader_spec.rb +106 -0
- data/spec/log/datashift.log +14930 -0
- data/spec/private/digitals/1/DEMO_003_ror_mug.jpeg +0 -0
- data/spec/private/digitals/2/DEMO_002_Powerstation.jpeg +0 -0
- data/spec/private/digitals/3/DEMO_004_ror_ringer.jpeg +0 -0
- data/spec/private/digitals/4/DEMO_001_ror_bag.jpeg +0 -0
- data/spec/spec_helper.rb +26 -230
- data/spec/support/clear_and_manage_contexts.rb +25 -0
- data/spec/support/database_cleaner.rb +32 -0
- data/spec/support/datashift_test_helpers.rb +153 -0
- data/spec/support/files_paths_helper.rb +13 -0
- data/spec/support/fixtures/results/mapping_template.yaml +15 -0
- data/spec/support/sandbox.rb +136 -0
- metadata +804 -85
- data/README.markdown +0 -274
- data/README.rdoc +0 -19
- data/VERSION +0 -1
- data/datashift.gemspec +0 -48
- data/lib/applications/jruby/old_pre_proxy_jexcel_file.rb +0 -437
- data/lib/datashift/data_transforms.rb +0 -83
- data/lib/datashift/mapping_file_definitions.rb +0 -88
- data/lib/datashift/mapping_service.rb +0 -91
- data/lib/datashift/method_detail.rb +0 -165
- data/lib/datashift/method_details_manager.rb +0 -95
- data/lib/datashift/method_dictionary.rb +0 -281
- data/lib/datashift/method_mapper.rb +0 -174
- data/lib/datashift/thor_base.rb +0 -38
- data/lib/generators/mapping_generator.rb +0 -112
- data/lib/helpers/core_ext/csv_file.rb +0 -33
- data/lib/helpers/core_ext/to_b.rb +0 -24
- data/lib/loaders/reporter.rb +0 -58
- data/lib/thor/export.thor +0 -175
- data/lib/thor/generate.thor +0 -191
- data/lib/thor/import.thor +0 -110
- data/lib/thor/mapping.thor +0 -65
- data/lib/thor/tools.thor +0 -84
- data/spec/Gemfile +0 -31
- data/spec/Gemfile.lock +0 -134
- data/spec/csv_exporter_spec.rb +0 -144
- data/spec/csv_generator_spec.rb +0 -159
- data/spec/csv_loader_spec.rb +0 -212
- data/spec/datashift_spec.rb +0 -55
- data/spec/excel_exporter_spec.rb +0 -199
- data/spec/excel_generator_spec.rb +0 -203
- data/spec/excel_loader_spec.rb +0 -237
- data/spec/excel_spec.rb +0 -203
- data/spec/loader_base_spec.rb +0 -166
- data/spec/mapping_spec.rb +0 -117
- data/spec/method_dictionary_spec.rb +0 -300
- data/spec/method_mapper_spec.rb +0 -100
- data/spec/model_mapper_spec.rb +0 -41
- data/spec/paperclip_loader_spec.rb +0 -92
- data/spec/populator_spec.rb +0 -128
- data/spec/thor_spec.rb +0 -90
- data/tasks/file_tasks.rake +0 -37
- data/tasks/word_to_seedfu.rake +0 -167
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# Date :: June 2012
|
|
4
4
|
# License:: MIT. Free, Open Source.
|
|
5
5
|
#
|
|
6
|
-
# => Provides facilities for bulk uploading/exporting attachments provided by PaperClip
|
|
6
|
+
# => Provides facilities for bulk uploading/exporting attachments provided by PaperClip
|
|
7
7
|
# gem
|
|
8
8
|
require 'datashift_paperclip'
|
|
9
9
|
require 'attachment_loader'
|
|
@@ -13,62 +13,67 @@ module DataShift
|
|
|
13
13
|
module ImageLoading
|
|
14
14
|
|
|
15
15
|
include DataShift::Logging
|
|
16
|
-
include DataShift::Paperclip
|
|
16
|
+
include DataShift::Paperclip
|
|
17
17
|
|
|
18
18
|
# Note the paperclip attachment model defines the storage path via something like :
|
|
19
|
-
#
|
|
19
|
+
#
|
|
20
20
|
# => :path => ":rails_root/public/blah/blahs/:id/:style/:basename.:extension"
|
|
21
|
-
#
|
|
22
|
-
# Options
|
|
23
|
-
#
|
|
21
|
+
#
|
|
22
|
+
# Options
|
|
23
|
+
#
|
|
24
24
|
# See also DataShift::paperclip create_paperclip_attachment for more options
|
|
25
|
-
#
|
|
25
|
+
#
|
|
26
26
|
# Example: Image is a model class with an attachment.
|
|
27
27
|
# Image table contains a viewable field which can contain other models,
|
|
28
28
|
# such as Product, User etc all of which can have an Image
|
|
29
|
-
#
|
|
30
|
-
# :viewable_record
|
|
31
|
-
#
|
|
29
|
+
#
|
|
30
|
+
# :viewable_record
|
|
31
|
+
#
|
|
32
32
|
def create_attachment(klass, attachment_path, record = nil, attach_to_record_field = nil, options = {})
|
|
33
33
|
|
|
34
34
|
logger.debug("ImageLoading::create_attachment on Class #{klass}")
|
|
35
35
|
|
|
36
|
-
image_attributes = { :
|
|
37
|
-
|
|
38
|
-
:position => (!options[:position] && record and record.respond_to?(:images)) ? record.images.length : 0
|
|
36
|
+
image_attributes = { attributes: { alt: (options[:alt] || ''),
|
|
37
|
+
position: (!options[:position] && record && record.respond_to?(:images)) ? record.images.length : 0
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
attachment_options = options.dup.merge(image_attributes)
|
|
43
|
-
|
|
42
|
+
|
|
44
43
|
logger.debug("Adding Attachment for #{klass.inspect}")
|
|
45
44
|
|
|
46
|
-
create_paperclip_attachment(klass, attachment_path,
|
|
45
|
+
attachment = create_paperclip_attachment(klass, attachment_path, attachment_options)
|
|
46
|
+
|
|
47
|
+
if(attachment && attach_to_record_field)
|
|
48
|
+
populator = DataShift::Populator.new
|
|
49
|
+
populator.prepare_and_assign(attach_to_record_field, record, attachment)
|
|
50
|
+
end
|
|
51
|
+
|
|
47
52
|
end
|
|
48
|
-
|
|
53
|
+
|
|
49
54
|
# Set of file extensions ImageMagik can process so default glob
|
|
50
55
|
# we use to find image files within directories
|
|
51
56
|
def self.image_magik_glob
|
|
52
|
-
@im_glob ||= %w
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
@im_glob ||= %w(*.3FR *.AAI *.AI *.ART *.ARW *.AVI *.AVS *.BGR *.BGRA
|
|
58
|
+
*.BIE *.BMP *.BMP2 *.BMP3 *.BRF *.CAL *.CALS *.CANVAS
|
|
59
|
+
*.CIN *.CIP *.CLIP *.CMYK *.CMYKA *.CR2 *.CRW *.CUR *.CUT *.DCM *.DCR *.DCX
|
|
60
|
+
*.DDS *.DFONT *.DJVU *.DNG *.DOT *.DPS *.DPX
|
|
61
|
+
*.EMF *.EPDF *.EPI *.EPS *.EPS2 *.EPS3 *.EPSF *.EPSI
|
|
62
|
+
*.EPT *.EPT2 *.EPT3 *.ERF *.EXR *.FITS *.FPX *.FTS *.G3 *.GIF *.GIF87
|
|
63
|
+
*.GRAY *.HALD *.HDR *.HRZ *.ICB *.ICO *.ICON *.IPL
|
|
64
|
+
*.ISOBRL *.J2C *.JBG *.JBIG *.JNG *.JP2 *.JPC *.JPEG *.JPG *.JPX *.K25 *.KDC
|
|
65
|
+
*.LABEL *.M2V *.M4V *.MAC *.MAP *.MAT *.MATTE *.MIFF *.MNG *.MONO
|
|
66
|
+
*.MOV *.MP4 *.MPC *.MPEG *.MPG *.MRW *.MSL *.MSVG *.MTV *.MVG *.NEF *.ORF *.OTB *.OTF *.PAL *.PALM
|
|
67
|
+
*.PAM *.PBM *.PCD *.PCDS *.PCL *.PCT *.PCX *.PDB *.PDF *.PDFA *.PEF
|
|
68
|
+
*.PES *.PFA *.PFB *.PFM *.PGM *.PGX *.PICON *.PICT *.PIX *.PJPEG *.PLASMA
|
|
69
|
+
*.PNG *.PNG24 *.PNG32 *.PNG8 *.PNM *.PPM *.PS *.PS2 *.PS3 *.PSB *.PSD *.PTIF *.PWP *.RAF *.RAS *.RGB
|
|
70
|
+
*.RGBA *.RGBO *.RLA *.RLE *.SCR *.SCT *.SFW *.SGI *.SR2 *.SRF
|
|
71
|
+
*.SUN *.SVG *.SVGZ *.TGA *.TIFF *.TIFF64 *.TILE *.TIM *.TTC *.TTF *.UBRL *.UIL *.UYVY *.VDA *.VICAR
|
|
72
|
+
*.VID *.VIFF *.VST *.WBMP *.WEBP *.WMF *.WMV *.WMZ *.WPG *.X3F
|
|
73
|
+
*.XBM *.XC *.XCF *.XPM *.XPS *.XV *.XWD *.YCbCr *.YCbCrA *.YUV
|
|
74
|
+
)
|
|
70
75
|
"{#{@im_glob.join(',')}}"
|
|
71
76
|
end
|
|
72
77
|
end
|
|
73
|
-
|
|
78
|
+
|
|
74
79
|
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2016
|
|
2
|
+
# Author :: Tom Statter
|
|
3
|
+
# License:: MIT
|
|
4
|
+
#
|
|
5
|
+
# Details:: Very basic report to dump out loading report stats
|
|
6
|
+
#
|
|
7
|
+
module DataShift
|
|
8
|
+
module Reporters
|
|
9
|
+
class BasicStdoutReporter < Reporter
|
|
10
|
+
|
|
11
|
+
def initialize(progress_monitor)
|
|
12
|
+
super progress_monitor
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def report
|
|
16
|
+
loaded_objects = progress_monitor.loaded_objects
|
|
17
|
+
|
|
18
|
+
loaded_objects.compact! if loaded_objects
|
|
19
|
+
|
|
20
|
+
inbound_str = progress_monitor.processed_object_count > 1 ? 'entries' : 'entry'
|
|
21
|
+
|
|
22
|
+
puts "\nProcessing Summary Report"
|
|
23
|
+
puts ">>>>>>>>>>>>>>>>>>>>>>>>>\n"
|
|
24
|
+
puts "Processed total of #{progress_monitor.processed_object_count} inbound #{inbound_str}"
|
|
25
|
+
puts "#{loaded_objects.size}\tdatabase objects were successfully processed."
|
|
26
|
+
puts "#{progress_monitor.success_inbound_count}\tinbound rows were successfully processed."
|
|
27
|
+
|
|
28
|
+
failed_inbound_count = progress_monitor.failed_inbound_count
|
|
29
|
+
|
|
30
|
+
if failed_inbound_count == 0
|
|
31
|
+
puts 'There were NO failures.'
|
|
32
|
+
else
|
|
33
|
+
puts "WARNING : There were Failures - Check logs\n#{failed_inbound_count} rows contained errors"
|
|
34
|
+
puts "#{progress_monitor.failed_objects.size} objects could not be saved to DB"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2016
|
|
2
|
+
# Author :: Tom Statter
|
|
3
|
+
# License:: MIT
|
|
4
|
+
#
|
|
5
|
+
# Details:: Base class for reporters on loading stats
|
|
6
|
+
#
|
|
7
|
+
module DataShift
|
|
8
|
+
module Reporters
|
|
9
|
+
class Reporter
|
|
10
|
+
|
|
11
|
+
include DataShift::Logging
|
|
12
|
+
|
|
13
|
+
# Holds the actual data r.e data rows/objects inbound
|
|
14
|
+
attr_accessor :progress_monitor
|
|
15
|
+
|
|
16
|
+
def initialize(progress_monitor = DataShift::ProgressMonitor.new)
|
|
17
|
+
@progress_monitor = progress_monitor
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# an abstract method
|
|
21
|
+
def report
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2016
|
|
2
|
+
# Author :: Tom Statter
|
|
3
|
+
# Date :: Mar 2016
|
|
4
|
+
# License:: MIT.
|
|
5
|
+
#
|
|
6
|
+
#
|
|
7
|
+
require 'thor'
|
|
8
|
+
|
|
9
|
+
# Note, not DataShift, case sensitive, create namespace for command line : datashift
|
|
10
|
+
|
|
11
|
+
module Datashift
|
|
12
|
+
|
|
13
|
+
class Config < Thor
|
|
14
|
+
|
|
15
|
+
DEFAULT_IMPORT_TEMPLTE ||= "import_mapping_template.yaml".freeze
|
|
16
|
+
|
|
17
|
+
include DataShift::Logging
|
|
18
|
+
|
|
19
|
+
desc "import", "Generate an Import configuration template (YAML)"
|
|
20
|
+
|
|
21
|
+
method_option :model, aliases: '-m', required: true, desc: "The active record model to use for mappings"
|
|
22
|
+
|
|
23
|
+
method_option :result, aliases: '-r', required: true,
|
|
24
|
+
desc: "Path or file to create resulting YAML config\nIf PATH, filename is [#{DEFAULT_IMPORT_TEMPLTE}]"
|
|
25
|
+
|
|
26
|
+
def import()
|
|
27
|
+
|
|
28
|
+
start_connections
|
|
29
|
+
|
|
30
|
+
result = options[:result]
|
|
31
|
+
|
|
32
|
+
if(File.directory?(result))
|
|
33
|
+
result = File.join(result, DEFAULT_IMPORT_TEMPLTE)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
logger.info "Datashift: Starting Import mapping template generation to [#{result}]"
|
|
37
|
+
|
|
38
|
+
mapper = DataShift::ConfigGenerator.new
|
|
39
|
+
|
|
40
|
+
puts "Creating new configuration file : [#{result}]"
|
|
41
|
+
mapper.write_import(result, options[:model], options)
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
no_commands do
|
|
46
|
+
|
|
47
|
+
def start_connections
|
|
48
|
+
|
|
49
|
+
if File.exist?(File.expand_path('config/environment.rb'))
|
|
50
|
+
begin
|
|
51
|
+
require File.expand_path('config/environment.rb')
|
|
52
|
+
rescue => e
|
|
53
|
+
logger.error("Failed to initialise ActiveRecord : #{e.message}")
|
|
54
|
+
raise ConnectionError.new("Failed to initialise ActiveRecord : #{e.message}")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
else
|
|
58
|
+
raise PathError.new('No config/environment.rb found - cannot initialise ActiveRecord')
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
end
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2016
|
|
2
|
+
# Author :: Tom Statter
|
|
3
|
+
# Date :: March 2016
|
|
4
|
+
# License:: MIT.
|
|
5
|
+
#
|
|
6
|
+
# Usage::
|
|
7
|
+
#
|
|
8
|
+
#
|
|
9
|
+
require 'thor'
|
|
10
|
+
|
|
11
|
+
# Note, for thor not DataShift, case sensitive, want namespace for cmd line to be : datashift
|
|
12
|
+
module Datashift
|
|
13
|
+
|
|
14
|
+
class Export < Thor
|
|
15
|
+
|
|
16
|
+
include DataShift::Logging
|
|
17
|
+
|
|
18
|
+
class_option :associations, aliases: '-a',
|
|
19
|
+
type: :boolean,
|
|
20
|
+
desc: 'Include associations. Can be further refined by :with & :exclude'
|
|
21
|
+
|
|
22
|
+
class_option :expand_associations, type: :boolean,
|
|
23
|
+
desc: 'Expand association data to multiple columns i.e 1 column per attribute'
|
|
24
|
+
|
|
25
|
+
class_option :methods, type: :array,
|
|
26
|
+
desc: 'List of additional methods to call on model, useful for situations like delegated methods'
|
|
27
|
+
|
|
28
|
+
class_option :with, type: :array,
|
|
29
|
+
desc: "Restrict association types. Choose from #{DataShift::ModelMethod.supported_types_enum.inspect}"
|
|
30
|
+
|
|
31
|
+
class_option :exclude, type: :array,
|
|
32
|
+
desc: "Exclude association types. Choose from #{DataShift::ModelMethod.supported_types_enum.inspect}"
|
|
33
|
+
|
|
34
|
+
class_option :remove, type: :array,
|
|
35
|
+
desc: "Don't include this list of supplied fields"
|
|
36
|
+
|
|
37
|
+
class_option :remove_rails, type: :boolean,
|
|
38
|
+
desc: "Remove standard Rails cols : #{DataShift::Configuration.rails_columns.inspect}"
|
|
39
|
+
|
|
40
|
+
class_option :json, type: :boolean,
|
|
41
|
+
desc: 'Export association data as json rather than hash'
|
|
42
|
+
|
|
43
|
+
desc "excel", "export any active record model (with optional associations)"
|
|
44
|
+
|
|
45
|
+
method_option :model, :aliases => '-m', :required => true, desc: "The active record model to export"
|
|
46
|
+
method_option :result, :aliases => '-r', :required => true, desc: "Create template of model in supplied file"
|
|
47
|
+
|
|
48
|
+
method_option :sheet_name, :type => :string, desc: "Name to use for Excel worksheet instead of model name"
|
|
49
|
+
|
|
50
|
+
def excel()
|
|
51
|
+
start_connections
|
|
52
|
+
|
|
53
|
+
export(DataShift::ExcelExporter.new)
|
|
54
|
+
|
|
55
|
+
puts "Datashift: Excel export COMPLETED to #{options[:result]}"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
desc "csv", "export any active record model (with optional associations)"
|
|
60
|
+
|
|
61
|
+
method_option :model, :aliases => '-m', :required => true, desc: "The active record model to export"
|
|
62
|
+
method_option :result, :aliases => '-r', :required => true, desc: "Create template of model in supplied file"
|
|
63
|
+
|
|
64
|
+
def csv()
|
|
65
|
+
start_connections
|
|
66
|
+
|
|
67
|
+
export(DataShift::CsvExporter.new)
|
|
68
|
+
|
|
69
|
+
puts "Datashift: CSV export COMPLETED to #{options[:result]}"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
desc "db", "Export every Active Record model"
|
|
74
|
+
|
|
75
|
+
method_option :model, :aliases => '-m', :required => true, desc: "The active record model to export"
|
|
76
|
+
method_option :result, :aliases => '-r', :required => true, desc: "Create template of model in supplied file"
|
|
77
|
+
|
|
78
|
+
method_option :csv, :aliases => '-c', desc: "Export to CSV instead - Excel is default."
|
|
79
|
+
|
|
80
|
+
method_option :prefix_map, :aliases => '-x', type: :hash, :default => {},
|
|
81
|
+
desc: "For namespaced tables/models specify the table prefix to module map e.g spree_:Spree"
|
|
82
|
+
|
|
83
|
+
method_option :modules, :aliases => '-m', type: :array, :default => [],
|
|
84
|
+
desc: "List of Modules to search for namespaced models"
|
|
85
|
+
|
|
86
|
+
def db()
|
|
87
|
+
|
|
88
|
+
start_connections
|
|
89
|
+
|
|
90
|
+
FileUtils::mkdir_p(options[:result]) unless File.directory?(options[:result])
|
|
91
|
+
|
|
92
|
+
raise "WARNING : One file per model - results expects a DIRECTORY" unless File.directory?(options[:result])
|
|
93
|
+
|
|
94
|
+
exporter = options[:csv] ? DataShift::CsvExporter.new : DataShift::ExcelExporter.new
|
|
95
|
+
|
|
96
|
+
DataShift::Exporters::Configuration.from_hash(options)
|
|
97
|
+
|
|
98
|
+
ext = options[:csv] ? '.csv' : '.xls'
|
|
99
|
+
|
|
100
|
+
modules = [nil] + options[:modules]
|
|
101
|
+
|
|
102
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
|
103
|
+
|
|
104
|
+
logger.info("Starting Export process for Table #{table}")
|
|
105
|
+
|
|
106
|
+
modules.each do |m|
|
|
107
|
+
@klass = DataShift::MapperUtils.table_to_arclass(table, m)
|
|
108
|
+
break if(@klass)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
options[:prefix_map].each do |p, m|
|
|
112
|
+
@klass = DataShift::MapperUtils.table_to_arclass(table.gsub(p, ''), m)
|
|
113
|
+
break if(@klass)
|
|
114
|
+
end unless(@klass)
|
|
115
|
+
|
|
116
|
+
if(@klass.nil?)
|
|
117
|
+
puts "ERROR: No Model found for Table [#{table}] - perhaps check modules/prefixes"
|
|
118
|
+
next
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
result = File.join(options[:result], "#{table}#{ext}")
|
|
122
|
+
|
|
123
|
+
puts "Datashift: Start export to #{result} for [#{table}]"
|
|
124
|
+
|
|
125
|
+
logger.info("Starting Export to #{result} for [#{@klass}]")
|
|
126
|
+
|
|
127
|
+
begin
|
|
128
|
+
|
|
129
|
+
if(options[:associations])
|
|
130
|
+
logger.info("Datashift: Exporting with associations")
|
|
131
|
+
exporter.export_with_associations(result, @klass, @klass.all)
|
|
132
|
+
else
|
|
133
|
+
exporter.export(result, @klass.all, :sheet_name => @klass.name)
|
|
134
|
+
end
|
|
135
|
+
rescue => e
|
|
136
|
+
puts e
|
|
137
|
+
puts e.backtrace
|
|
138
|
+
puts "Warning: Error during export, data may be incomplete"
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
no_commands do
|
|
144
|
+
|
|
145
|
+
def start_connections
|
|
146
|
+
|
|
147
|
+
if File.exist?(File.expand_path('config/environment.rb'))
|
|
148
|
+
begin
|
|
149
|
+
require File.expand_path('config/environment.rb')
|
|
150
|
+
rescue => e
|
|
151
|
+
logger.error("Failed to initialise ActiveRecord : #{e.message}")
|
|
152
|
+
raise ConnectionError.new("Failed to initialise ActiveRecord : #{e.message}")
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
else
|
|
156
|
+
raise PathError.new('No config/environment.rb found - cannot initialise ActiveRecord')
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def export(exporter)
|
|
161
|
+
model = options[:model]
|
|
162
|
+
result = options[:result]
|
|
163
|
+
|
|
164
|
+
DataShift::Configuration.from_hash(options)
|
|
165
|
+
|
|
166
|
+
logger.info "Datashift: Starting export with #{exporter.class.name} to #{result}"
|
|
167
|
+
|
|
168
|
+
klass = DataShift::MapperUtils::class_from_string(model) #Kernel.const_get(model)
|
|
169
|
+
|
|
170
|
+
raise "ERROR: No such Model [#{model}] found - check valid model supplied via -model <Class>" if(klass.nil?)
|
|
171
|
+
|
|
172
|
+
begin
|
|
173
|
+
|
|
174
|
+
if(options[:associations])
|
|
175
|
+
logger.info("Datashift: Exporting with associations")
|
|
176
|
+
exporter.export_with_associations(result, klass, klass.all)
|
|
177
|
+
else
|
|
178
|
+
exporter.export(result, klass.all, options)
|
|
179
|
+
end
|
|
180
|
+
rescue => e
|
|
181
|
+
puts e
|
|
182
|
+
puts e.backtrace
|
|
183
|
+
puts "Warning: Error during export, data may be incomplete"
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
end # no_commands
|
|
189
|
+
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
end
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2016
|
|
2
|
+
# Author :: Tom Statter
|
|
3
|
+
# Date :: Mar 2016
|
|
4
|
+
# License:: MIT.
|
|
5
|
+
#
|
|
6
|
+
# Usage::
|
|
7
|
+
#
|
|
8
|
+
# To pull Datashift commands into your main application :
|
|
9
|
+
#
|
|
10
|
+
# require 'datashift'
|
|
11
|
+
#
|
|
12
|
+
# DataShift::load_commands
|
|
13
|
+
#
|
|
14
|
+
#
|
|
15
|
+
require 'thor'
|
|
16
|
+
|
|
17
|
+
require 'csv_generator'
|
|
18
|
+
|
|
19
|
+
# Note, not DataShift, case sensitive, create namespace for command line : datashift
|
|
20
|
+
|
|
21
|
+
module Datashift
|
|
22
|
+
|
|
23
|
+
class Generate < Thor
|
|
24
|
+
|
|
25
|
+
include DataShift::Logging
|
|
26
|
+
|
|
27
|
+
class_option :associations, aliases: '-a',
|
|
28
|
+
type: :boolean,
|
|
29
|
+
desc: 'Include associations. Can be further refined by :with & :exclude'
|
|
30
|
+
|
|
31
|
+
class_option :expand_associations, type: :boolean,
|
|
32
|
+
desc: 'Expand association data to multiple columns i.e 1 column per attribute'
|
|
33
|
+
|
|
34
|
+
class_option :methods, type: :array,
|
|
35
|
+
desc: 'List of additional methods to call on model, useful for situations like delegated methods'
|
|
36
|
+
|
|
37
|
+
class_option :with, type: :array,
|
|
38
|
+
desc: "Restrict association types. Choose from #{DataShift::ModelMethod.supported_types_enum.inspect}"
|
|
39
|
+
|
|
40
|
+
class_option :exclude, type: :array,
|
|
41
|
+
desc: "Exclude association types. Choose from #{DataShift::ModelMethod.supported_types_enum.inspect}"
|
|
42
|
+
|
|
43
|
+
class_option :remove, type: :array,
|
|
44
|
+
desc: "Don't include this list of supplied fields"
|
|
45
|
+
|
|
46
|
+
class_option :remove_rails, type: :boolean,
|
|
47
|
+
desc: "Remove standard Rails cols : #{DataShift::Configuration.rails_columns.inspect}"
|
|
48
|
+
|
|
49
|
+
class_option :json, type: :boolean,
|
|
50
|
+
desc: 'Export association data as json rather than hash'
|
|
51
|
+
|
|
52
|
+
desc "excel", "generate a template from an active record model (with optional associations)"
|
|
53
|
+
|
|
54
|
+
method_option :model, :aliases => '-m', :required => true, :desc => "The active record model to export"
|
|
55
|
+
method_option :result, :aliases => '-r', :required => true, :desc => "Create template of model in supplied file"
|
|
56
|
+
|
|
57
|
+
def excel()
|
|
58
|
+
start_connections
|
|
59
|
+
|
|
60
|
+
generate( DataShift::ExcelGenerator.new)
|
|
61
|
+
|
|
62
|
+
puts "Datashift: Excel Template COMPLETED to #{options[:result]}"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
desc "csv", "generate a template from an active record model (with optional associations)"
|
|
67
|
+
method_option :model, :aliases => '-m', :required => true, :desc => "The active record model to export"
|
|
68
|
+
method_option :result, :aliases => '-r', :required => true, :desc => "Create template of model in supplied file"
|
|
69
|
+
|
|
70
|
+
def csv()
|
|
71
|
+
start_connections
|
|
72
|
+
|
|
73
|
+
generate( DataShift::CsvGenerator.new)
|
|
74
|
+
|
|
75
|
+
puts "Datashift: CSV Template COMPLETED to #{options[:result]}"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
desc "db", "Generate a template for every Active Record model"
|
|
79
|
+
|
|
80
|
+
method_option :path, :aliases => '-p', :required => true, desc: "Path in which to create export files"
|
|
81
|
+
method_option :csv, :aliases => '-c', desc: "Generate CSV template instead - Excel is default."
|
|
82
|
+
|
|
83
|
+
method_option :prefix_map, :aliases => '-x', type: :hash, :default => {},
|
|
84
|
+
desc: "For namespaced tables/models specify the table prefix to module map e.g spree_:Spree"
|
|
85
|
+
|
|
86
|
+
method_option :modules, :aliases => '-m', type: :array, :default => [],
|
|
87
|
+
desc: "List of Modules to search for namespaced models"
|
|
88
|
+
|
|
89
|
+
def db()
|
|
90
|
+
|
|
91
|
+
start_connections
|
|
92
|
+
|
|
93
|
+
unless File.directory?(options[:path])
|
|
94
|
+
puts "WARNING : No such PATH found #{options[:path]} - trying mkdir"
|
|
95
|
+
FileUtils::mkdir_p(options[:path])
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
generator = options[:csv] ? DataShift::CsvGenerator.new : DataShift::ExcelGenerator.new
|
|
99
|
+
|
|
100
|
+
DataShift::Exporters::Configuration.from_hash(options)
|
|
101
|
+
|
|
102
|
+
ext = options[:csv] ? '.csv' : '.xls'
|
|
103
|
+
|
|
104
|
+
modules = [nil] + options[:modules]
|
|
105
|
+
|
|
106
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
|
107
|
+
|
|
108
|
+
modules.each do |m|
|
|
109
|
+
@klass = DataShift::MapperUtils.table_to_arclass(table, m)
|
|
110
|
+
break if(@klass)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
options[:prefix_map].each do |p, m|
|
|
114
|
+
@klass = DataShift::MapperUtils.table_to_arclass(table.gsub(p, ''), m)
|
|
115
|
+
break if(@klass)
|
|
116
|
+
end unless(@klass)
|
|
117
|
+
|
|
118
|
+
if(@klass.nil?)
|
|
119
|
+
puts "ERROR: No Model found for Table [#{table}] - perhaps a prefix map required?"
|
|
120
|
+
next
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
result = File.join(options[:path], "#{table}#{ext}")
|
|
124
|
+
|
|
125
|
+
puts "Datashift: Start export to #{result} for [#{table}]"
|
|
126
|
+
begin
|
|
127
|
+
if(options[:associations])
|
|
128
|
+
logger.info("Datashift: Generating with associations")
|
|
129
|
+
generator.generate_with_associations(result, @klass)
|
|
130
|
+
else
|
|
131
|
+
generator.generate(result, @klass)
|
|
132
|
+
end
|
|
133
|
+
rescue => e
|
|
134
|
+
puts e
|
|
135
|
+
puts e.backtrace
|
|
136
|
+
puts "Warning: Error during export, data may be incomplete"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
no_commands do
|
|
143
|
+
|
|
144
|
+
def start_connections
|
|
145
|
+
|
|
146
|
+
if File.exist?(File.expand_path('config/environment.rb'))
|
|
147
|
+
begin
|
|
148
|
+
require File.expand_path('config/environment.rb')
|
|
149
|
+
rescue => e
|
|
150
|
+
logger.error("Failed to initialise ActiveRecord : #{e.message}")
|
|
151
|
+
raise ConnectionError.new("Failed to initialise ActiveRecord : #{e.message}")
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
else
|
|
155
|
+
raise PathError.new('No config/environment.rb found - cannot initialise ActiveRecord')
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def generate(generater)
|
|
160
|
+
model = options[:model]
|
|
161
|
+
result = options[:result]
|
|
162
|
+
|
|
163
|
+
DataShift::Exporters::Configuration.from_hash(options)
|
|
164
|
+
|
|
165
|
+
logger.info "Datashift: Starting template generation for #{generater.class.name} to #{result}"
|
|
166
|
+
|
|
167
|
+
klass = DataShift::MapperUtils::class_from_string(model) #Kernel.const_get(model)
|
|
168
|
+
|
|
169
|
+
raise "ERROR: No such Model [#{model}] found - check valid model supplied via -model <Class>" if(klass.nil?)
|
|
170
|
+
|
|
171
|
+
begin
|
|
172
|
+
|
|
173
|
+
if(options[:associations])
|
|
174
|
+
logger.info("Datashift: Generating template including associations")
|
|
175
|
+
generater.generate_with_associations(result, klass)
|
|
176
|
+
else
|
|
177
|
+
generater.generate(result, klass)
|
|
178
|
+
end
|
|
179
|
+
rescue => e
|
|
180
|
+
puts e
|
|
181
|
+
puts e.backtrace
|
|
182
|
+
puts "Warning: Error during export, data may be incomplete"
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
end # no_commands
|
|
188
|
+
|
|
189
|
+
end
|
|
190
|
+
end
|