Skip to content

Options and configuration

tom statter edited this page Dec 29, 2016 · 8 revisions

Configuration

Inspiration : https://robots.thoughtbot.com/mygem-configure-block | http://brandonhilkert.com/blog/ruby-gem-configuration-patterns/

You can now configure datashift options with a typical initialisation block, for example

DataShift::Configuration.call do |c|
  c.verbose = false
  c.remove_columns = [:milestones, :versions]
  c.remove_rails = true
  c.with = :all
end

See lib/datashift/configuration.rb for up to date list of all options

Imports/export can also be directed from YAML configuration file, to setup column mappings, transformations and custom methods for columns/data that require non trivial processing.

There is a generator, to create a skeleton configuration file template for you :

thor help datashift:config:generate:import

Transformations

A transformation factory is available for setting up transformations directly in code, rather than via config.

Enables setting of default values, substitutions and transformations per column for Imports.

For example

        DataShift::Transformation.factory do |factory|
          factory.set_default_on(Project, "name", 'default name')
          factory.set_override_on(Project, "name", 'override name')
          factory.set_prefix_on(Project, "name", 'prefix name')
          factory.set_postfix_on(Project, "name", 'postfix name')

          factory.set_substitution_on(Project, "name", 'if its blah', 'substitution name')
        end

N.B The operator/column name (2nd parameter) must match the inbound HEADER

For example given a header SKU, for a class with real operator sku=, even though we know assignment will eventually use sku= this will not work :

`factory.set_prefix_on(Spree::Product, 'sku', 'SPEC_')`

But this will set the right prefix :

factory.set_prefix_on(Spree::Product, 'SKU', 'SPEC_')