datashift 0.16.0 → 0.40.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,142 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2016
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Mar 2016
|
4
|
+
# License:: MIT.
|
5
|
+
#
|
6
|
+
require 'thor'
|
7
|
+
|
8
|
+
# Note, not DataShift, case sensitive, create namespace for command line : datashift
|
9
|
+
module Datashift
|
10
|
+
|
11
|
+
class Import < Thor
|
12
|
+
|
13
|
+
include DataShift::Logging
|
14
|
+
|
15
|
+
=begin - These class_option don't seem to currently bet fit for purpose for example
|
16
|
+
|
17
|
+
>>thor help datashift:import:csv
|
18
|
+
|
19
|
+
No value provided for required options '--model', '--input'
|
20
|
+
=end
|
21
|
+
|
22
|
+
=begin -
|
23
|
+
class_option :model, aliases: '-m', required: true, desc: 'The related active record model'
|
24
|
+
|
25
|
+
class_option :input, aliases: '-i', required: true, desc: 'The input file'
|
26
|
+
|
27
|
+
class_option :loader, aliases: '-l', required: false, desc: 'Loader class to use'
|
28
|
+
|
29
|
+
class_option :verbose, aliases: '-v', type: :boolean, desc: 'Verbose logging'
|
30
|
+
|
31
|
+
class_option :config, aliases: '-c', desc: 'YAML config file with defaults, over-rides etc'
|
32
|
+
=end
|
33
|
+
|
34
|
+
|
35
|
+
desc "load", "Import data from file for specific active record model"
|
36
|
+
|
37
|
+
method_option :model, aliases: '-m', required: true, desc: 'The related active record model'
|
38
|
+
|
39
|
+
method_option :input, aliases: '-i', required: true, desc: 'The input file'
|
40
|
+
|
41
|
+
method_option :loader, aliases: '-l', required: false, desc: 'Loader class to use'
|
42
|
+
|
43
|
+
method_option :verbose, aliases: '-v', type: :boolean, desc: 'Verbose logging'
|
44
|
+
|
45
|
+
method_option :config, aliases: '-c', desc: 'YAML config file with defaults, over-rides etc'
|
46
|
+
|
47
|
+
def load()
|
48
|
+
start_connections
|
49
|
+
|
50
|
+
importer = if(options[:loader])
|
51
|
+
logger.info("Attempting to use supplied Loader : #{options[:loader]}")
|
52
|
+
DataShift::MapperUtils::class_from_string(options[:loader]).new
|
53
|
+
else
|
54
|
+
logger.info("No Loader specified - finding appropriate Loader for file type")
|
55
|
+
DataShift::Loader::Factory.get_loader(options[:input])
|
56
|
+
end
|
57
|
+
|
58
|
+
import(importer)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
desc "excel", "Import .xls file for specifiec active record model"
|
63
|
+
|
64
|
+
method_option :model, aliases: '-m', required: true, desc: 'The related active record model'
|
65
|
+
|
66
|
+
method_option :input, aliases: '-i', required: true, desc: 'The input file'
|
67
|
+
|
68
|
+
method_option :loader, aliases: '-l', required: false, desc: 'Loader class to use'
|
69
|
+
|
70
|
+
method_option :verbose, aliases: '-v', type: :boolean, desc: 'Verbose logging'
|
71
|
+
|
72
|
+
method_option :config, aliases: '-c', desc: 'YAML config file with defaults, over-rides etc'
|
73
|
+
|
74
|
+
def excel()
|
75
|
+
|
76
|
+
start_connections
|
77
|
+
|
78
|
+
importer = if(options[:loader])
|
79
|
+
logger.info("Attempting to use supplied Loader : #{options[:loader]}")
|
80
|
+
DataShift::MapperUtils::class_from_string(options[:loader]).new
|
81
|
+
else
|
82
|
+
logger.info("No Loader specified - using standard Excel Loader")
|
83
|
+
DataShift::ExcelLoader.new
|
84
|
+
end
|
85
|
+
|
86
|
+
import(importer)
|
87
|
+
end
|
88
|
+
|
89
|
+
desc "csv", "Import CSV file for specified active record model"
|
90
|
+
|
91
|
+
method_option :model, aliases: '-m', required: true, desc: 'The related active record model'
|
92
|
+
|
93
|
+
method_option :input, aliases: '-i', required: true, desc: 'The input file'
|
94
|
+
|
95
|
+
method_option :loader, aliases: '-l', required: false, desc: 'Loader class to use'
|
96
|
+
|
97
|
+
method_option :verbose, aliases: '-v', type: :boolean, desc: 'Verbose logging'
|
98
|
+
|
99
|
+
method_option :config, aliases: '-c', desc: 'YAML config file with defaults, over-rides etc'
|
100
|
+
|
101
|
+
def csv()
|
102
|
+
|
103
|
+
start_connections
|
104
|
+
|
105
|
+
importer = if(options[:loader])
|
106
|
+
logger.info("Attempting to use supplied Loader : #{options[:loader]}")
|
107
|
+
DataShift::MapperUtils::class_from_string(options[:loader]).new
|
108
|
+
else
|
109
|
+
logger.info("No Loader specified - using standard Csv Loader")
|
110
|
+
DataShift::CsvLoader.new
|
111
|
+
end
|
112
|
+
|
113
|
+
import(importer)
|
114
|
+
end
|
115
|
+
|
116
|
+
no_commands do
|
117
|
+
def start_connections
|
118
|
+
|
119
|
+
if File.exist?(File.expand_path('config/environment.rb'))
|
120
|
+
begin
|
121
|
+
require File.expand_path('config/environment.rb')
|
122
|
+
rescue => e
|
123
|
+
logger.error("Failed to initialise ActiveRecord : #{e.message}")
|
124
|
+
raise ConnectionError.new("Failed to initialise ActiveRecord : #{e.message}")
|
125
|
+
end
|
126
|
+
|
127
|
+
else
|
128
|
+
raise PathError.new('No config/environment.rb found - cannot initialise ActiveRecord')
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def import(importer)
|
133
|
+
logger.info "Datashift: Starting Import from #{options[:input]}"
|
134
|
+
|
135
|
+
importer.configure_from( options[:config] ) if(options[:config])
|
136
|
+
|
137
|
+
importer.run(options[:input], options[:model])
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
@@ -1,39 +1,31 @@
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2016
|
2
2
|
# Author :: Tom Statter
|
3
|
-
# Date ::
|
3
|
+
# Date :: March 2016
|
4
4
|
# License:: MIT.
|
5
5
|
#
|
6
6
|
# Usage::
|
7
7
|
#
|
8
|
-
# To pull Datashift commands into your main application :
|
9
|
-
#
|
10
|
-
# require 'datashift'
|
11
|
-
#
|
12
|
-
# DataShift::load_commands
|
13
|
-
#
|
14
8
|
# thor help datashift:paperclip:attach
|
15
9
|
#
|
16
|
-
require '
|
10
|
+
require 'thor'
|
17
11
|
|
18
12
|
# Note, not DataShift, case sensitive, create namespace for command line : datashift
|
19
13
|
module Datashift
|
20
|
-
|
21
|
-
class Paperclip < Thor
|
22
|
-
|
23
|
-
include DataShift::Logging
|
14
|
+
|
15
|
+
class Paperclip < Thor
|
24
16
|
|
25
17
|
desc "attach", "Create paperclip attachments and attach to a Model from files in a directory.
|
26
18
|
This is specifically for the use case where the paperclip attachments are stored in a class, such as Image, Icon, Asset,
|
27
19
|
and this class has a relationship, such as belongs_to, with another class, such as Product, User, Document.
|
28
|
-
|
20
|
+
|
29
21
|
Each matching file is used to create an instance of the paperclip attachment, given by :attachment_klass.
|
30
|
-
|
22
|
+
|
31
23
|
The class with the relationship, can be specified via :attach_to_klass
|
32
24
|
|
33
|
-
Examples
|
25
|
+
Examples
|
34
26
|
Owner has_many pdfs and mp3 files as Digitals .... :attachment_klass = Digital and :attach_to_klass = Owner
|
35
27
|
User has a single Image used as an avatar ... attachment_klass = Image and :attach_to_klass = User
|
36
|
-
|
28
|
+
|
37
29
|
The file name is used to lookup the instance of :attach_to_klass to assign the new attachment to, via :attach_to_find_by_field
|
38
30
|
|
39
31
|
So say we have a file called smithj_avatar.gif, and we want to lookup Users by login
|
@@ -42,83 +34,91 @@ module Datashift
|
|
42
34
|
|
43
35
|
Once instance of :attach_to_klass found, the new attachment is assigned.
|
44
36
|
|
45
|
-
The attribute to assign new attachment to is gtiven by :attach_to_field
|
46
|
-
|
37
|
+
The attribute to assign new attachment to is gtiven by :attach_to_field
|
38
|
+
|
47
39
|
Examples
|
48
40
|
:attach_to_field => digitals : Owner.digitals = attachment(Digital)
|
49
41
|
:attach_to_field => avatar : User.avatar = attachment(Image)"
|
50
|
-
|
42
|
+
|
51
43
|
|
52
44
|
# :dummy => dummy run without actual saving to DB
|
53
45
|
method_option :input, :aliases => '-i', :required => true, :desc => "The input path containing images "
|
54
|
-
|
46
|
+
|
55
47
|
method_option :glob, :aliases => '-g', :desc => 'The glob to use to find files e.g. \'{*.jpg,*.gif,*.png}\' '
|
56
48
|
method_option :recursive, :aliases => '-r', :type => :boolean, :desc => "Scan sub directories of input for images"
|
57
|
-
|
49
|
+
|
58
50
|
method_option :attachment_klass, :required => true, :aliases => '-a', :desc => "Ruby Class name of the Attachment e.g Image, Icon"
|
59
|
-
|
60
|
-
method_option :attach_to_klass, :required => true, :aliases => '-k', :desc => "A class that has a relationship with the attachment (has_many, has_one, belongs_to)"
|
51
|
+
|
52
|
+
method_option :attach_to_klass, :required => true, :aliases => '-k', :desc => "A class that has a relationship with the attachment (has_many, has_one, belongs_to)"
|
61
53
|
method_option :attach_to_find_by_field, :required => true, :aliases => '-l', :desc => "The field to use to find the :attach_to_klass record"
|
62
54
|
method_option :attach_to_field, :required => true, :aliases => '-f', :desc => "Attachment belongs to field e.g Product.image, Blog.digital"
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
method_option :split_file_name_on, :type => :string,
|
55
|
+
|
56
|
+
|
57
|
+
# => :attach_to_find_by_field
|
58
|
+
# For the :attach_to_klass, this is the field used to search for the parent
|
59
|
+
# object to assign the new attachment to.
|
60
|
+
# Examples
|
61
|
+
# Owner has a unique 'name' field ... :attach_to_find_by_field = :name
|
62
|
+
# User has a unique 'login' field ... :attach_to_klass = :login
|
63
|
+
#
|
64
|
+
# => :attach_to_field
|
65
|
+
# Attribute/association to assign attachment to on :attach_to_klass.
|
66
|
+
# Examples
|
67
|
+
# :attach_to_field => digitals : Owner.digitals = attachment
|
68
|
+
# :attach_to_field => avatar : User.avatar = attachment
|
69
|
+
|
70
|
+
method_option :split_file_name_on, :type => :string,
|
71
|
+
:desc => "delimiter to progressivley split file_name for lookup", :default => ' '
|
72
|
+
|
79
73
|
method_option :case_sensitive, :type => :boolean, :desc => "Use case sensitive where clause to find :attach_to_klass"
|
80
74
|
method_option :use_like, :type => :boolean, :desc => "Use :lookup_field LIKE 'string%' instead of :lookup_field = 'string' in where clauses to find :attach_to_klass"
|
81
|
-
|
82
|
-
method_option :dummy, :aliases => '-d', :type => :boolean, :desc => "Dummy run, do not actually save attachment"
|
83
|
-
|
75
|
+
|
84
76
|
method_option :skip_when_assoc, :aliases => '-x', :type => :boolean, :desc => "Do not process if :attach_to_klass already has an attachment"
|
85
|
-
|
77
|
+
|
86
78
|
method_option :verbose, :aliases => '-v', :type => :boolean, :desc => "Verbose logging"
|
87
79
|
|
88
80
|
def attach()
|
89
81
|
|
90
82
|
@attachment_path = options[:input]
|
91
|
-
|
92
|
-
unless(File.
|
83
|
+
|
84
|
+
unless(File.exist?(@attachment_path))
|
93
85
|
puts "ERROR: Supplied Path [#{@attachment_path}] not accesible"
|
94
86
|
exit(-1)
|
95
87
|
end
|
96
|
-
|
97
|
-
|
98
|
-
|
88
|
+
|
89
|
+
start_connections
|
90
|
+
|
99
91
|
require 'paperclip/attachment_loader'
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
attachment_klazz = ModelMapper::class_from_string( options[:attach_to_klass] )
|
109
|
-
raise "Cannot find Attach to Class #{options[:attach_to_klass]}" unless klazz
|
110
|
-
|
111
|
-
opts = options.dup
|
112
|
-
|
113
|
-
opts[:attach_to_klass] = attachment_klazz # Pass in real Ruby class not string class name
|
114
|
-
|
115
|
-
loader = DataShift::Paperclip::AttachmentLoader.new(klazz, nil, opts)
|
116
|
-
|
92
|
+
|
93
|
+
puts "Using Field #{options[:attach_to_find_by_field]} to lookup matching [#{options[:attach_to_klass]}]"
|
94
|
+
|
95
|
+
loader = DataShift::Paperclip::AttachmentLoader.new
|
96
|
+
|
97
|
+
loader.init_from_options(options)
|
98
|
+
|
117
99
|
logger.info "Loading attachments from #{@attachment_path}"
|
118
100
|
|
119
|
-
loader.
|
120
|
-
|
101
|
+
loader.run(@attachment_path, options[:attachment_klass])
|
102
|
+
end
|
103
|
+
|
104
|
+
no_commands do
|
105
|
+
|
106
|
+
def start_connections
|
107
|
+
|
108
|
+
if File.exist?(File.expand_path('config/environment.rb'))
|
109
|
+
begin
|
110
|
+
require File.expand_path('config/environment.rb')
|
111
|
+
rescue => e
|
112
|
+
logger.error("Failed to initialise ActiveRecord : #{e.message}")
|
113
|
+
raise ConnectionError.new("Failed to initialise ActiveRecord : #{e.message}")
|
114
|
+
end
|
115
|
+
|
116
|
+
else
|
117
|
+
raise PathError.new('No config/environment.rb found - cannot initialise ActiveRecord')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
121
|
end
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
end
|
@@ -1,45 +1,45 @@
|
|
1
|
-
namespace :datashift
|
2
|
-
|
3
|
-
namespace :db do
|
1
|
+
namespace :datashift do
|
4
2
|
|
5
|
-
|
3
|
+
namespace :db do
|
6
4
|
|
7
|
-
|
8
|
-
|
5
|
+
SYSTEM_TABLE_EXCLUSION_LIST = ['schema_migrations'].freeze
|
6
|
+
|
7
|
+
desc 'Purge the current database'
|
8
|
+
task :purge, [:exclude_system_tables] => [:environment] do |_t, args|
|
9
9
|
require 'highline/import'
|
10
10
|
|
11
|
-
if
|
12
|
-
agree(
|
11
|
+
if Rails.env.production?
|
12
|
+
agree('WARNING: In Production database, REALLY PURGE ? [y]:')
|
13
13
|
end
|
14
14
|
|
15
15
|
config = ActiveRecord::Base.configurations[Rails.env || 'development']
|
16
16
|
case config['adapter']
|
17
|
-
when
|
17
|
+
when 'mysql', 'mysql2', 'jdbcmysql'
|
18
18
|
ActiveRecord::Base.establish_connection(config)
|
19
19
|
ActiveRecord::Base.connection.tables.each do |table|
|
20
|
-
next if
|
20
|
+
next if args[:exclude_system_tables] && SYSTEM_TABLE_EXCLUSION_LIST.include?(table)
|
21
21
|
puts "purging table: #{table}"
|
22
22
|
ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
|
23
23
|
end
|
24
|
-
when
|
25
|
-
dbfile = config[
|
24
|
+
when 'sqlite', 'sqlite3'
|
25
|
+
dbfile = config['database'] || config['dbfile']
|
26
26
|
File.delete(dbfile) if File.exist?(dbfile)
|
27
|
-
when
|
28
|
-
dropfkscript = "#{config[
|
29
|
-
`osql -E -S #{config[
|
30
|
-
`osql -E -S #{config[
|
31
|
-
when
|
27
|
+
when 'sqlserver'
|
28
|
+
dropfkscript = "#{config['host']}.#{config['database']}.DP1".tr('\\', '-')
|
29
|
+
`osql -E -S #{config['host']} -d #{config['database']} -i db\\#{dropfkscript}`
|
30
|
+
`osql -E -S #{config['host']} -d #{config['database']} -i db\\#{Rails.env}_structure.sql`
|
31
|
+
when 'oci', 'oracle'
|
32
32
|
ActiveRecord::Base.establish_connection(config)
|
33
33
|
ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
|
34
34
|
ActiveRecord::Base.connection.execute(ddl)
|
35
35
|
end
|
36
|
-
when
|
36
|
+
when 'firebird'
|
37
37
|
ActiveRecord::Base.establish_connection(config)
|
38
38
|
ActiveRecord::Base.connection.recreate_database!
|
39
39
|
else
|
40
|
-
raise "Task not supported by '#{config[
|
40
|
+
raise "Task not supported by '#{config['adapter']}'"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2016
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: April 2016
|
4
|
+
# License:: MIT.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
require 'datashift'
|
8
|
+
|
9
|
+
# Note, not DataShift, case sensitive, create namespace for command line : datashift
|
10
|
+
module Datashift
|
11
|
+
|
12
|
+
class Tools < Thor
|
13
|
+
|
14
|
+
include DataShift::Logging
|
15
|
+
|
16
|
+
desc 'file_rename', 'Clone a folder of files, consistently renaming each in the process'
|
17
|
+
|
18
|
+
method_option :path, :aliases => '-p', required: true, desc: "The path to the original files"
|
19
|
+
method_option :output, :aliases => '-o', required: true, desc: "The resulting zip file name"
|
20
|
+
method_option :offset, required: false, type: :numeric, desc: "A numeric offset to add to the file name"
|
21
|
+
method_option :width, required: false, type: :numeric, desc: "A numeric width tp pad the file name"
|
22
|
+
method_option :prefix, required: false, desc: "A strign prefix to add to file name"
|
23
|
+
method_option :commit, required: false, type: :boolean, desc: "Actually perform copy"
|
24
|
+
|
25
|
+
def file_rename
|
26
|
+
|
27
|
+
cache = options[:path]
|
28
|
+
|
29
|
+
if File.exist?(cache)
|
30
|
+
puts "Renaming files from #{cache}"
|
31
|
+
Dir.glob(File.join(cache, '*')) do |name|
|
32
|
+
path, base_name = File.split(name)
|
33
|
+
id = base_name.slice!(/\w+/)
|
34
|
+
|
35
|
+
id = id.to_i + options[:offset].to_i if options[:offset]
|
36
|
+
id = "%0#{width}d" % id.to_i if options[:width]
|
37
|
+
id = options[:prefix] + id.to_s if options[:prefix]
|
38
|
+
|
39
|
+
destination = File.join( options[:output], "#{id}#{base_name}")
|
40
|
+
puts "File Rename: cp #{name} #{destination}"
|
41
|
+
|
42
|
+
File.send( 'cp', name, destination) if options[:commit]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "zip", "Create zip of files"
|
48
|
+
|
49
|
+
method_option :path, :aliases => '-p', required: true, desc: "The path to the digital files"
|
50
|
+
method_option :output, :aliases => '-o', required: true, desc: "The resulting zip file name"
|
51
|
+
|
52
|
+
def zip
|
53
|
+
|
54
|
+
require 'zip/zip'
|
55
|
+
require 'zip/zipfilesystem'
|
56
|
+
|
57
|
+
output = options[:output]
|
58
|
+
|
59
|
+
Zip::ZipOutputStream.open(output) do |zos|
|
60
|
+
Dir[File.join(options[:path], '**', '*.*')].each do |p|
|
61
|
+
zos.put_next_entry(File.basename(p))
|
62
|
+
zos.print IO.read(p)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "zip_matching", "Create zip of matching digital files e.g zip up pdf, jpg and png versions of a file"
|
68
|
+
|
69
|
+
method_option :path, :aliases => '-p', required: true, desc: "The path to the digital files"
|
70
|
+
method_option :results, :aliases => '-r', required: true, desc: "The path to store resulting zip files"
|
71
|
+
|
72
|
+
def zip_matching()
|
73
|
+
|
74
|
+
require 'zip/zip'
|
75
|
+
require 'zip/zipfilesystem'
|
76
|
+
|
77
|
+
ready_to_zip = {}
|
78
|
+
Dir[File.join(options[:path], '**', '*.*')].each do |p|
|
79
|
+
next if File.directory? p
|
80
|
+
|
81
|
+
basename = File.basename(p, '.*')
|
82
|
+
ready_to_zip[basename] ||= []
|
83
|
+
ready_to_zip[basename] << p
|
84
|
+
end
|
85
|
+
|
86
|
+
output = options[:results]
|
87
|
+
|
88
|
+
FileUtils::mkdir_p(output) unless File.exist?(output)
|
89
|
+
|
90
|
+
puts "Creating #{ready_to_zip.keys.size} new zips"
|
91
|
+
ready_to_zip.each do |basename, paths|
|
92
|
+
|
93
|
+
z= File.join(output, basename + '.zip')
|
94
|
+
puts "zipping to #{z}"
|
95
|
+
|
96
|
+
Zip::ZipOutputStream.open(z) do |zos|
|
97
|
+
paths.each do |file|
|
98
|
+
zos.put_next_entry(File.basename(file))
|
99
|
+
zos.print IO.read(file)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|