Class: DataShift::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/datashift/configuration.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/datashift/configuration.rb', line 128

def initialize
  @with = [:assignment, :enum]
  @exclude = []
  @remove_columns = []

  @mandatory = []

  @strict_inbound_mapping = false
  @verbose = false
  @dummy_run = false
  @force_inclusion_of_columns = []
  @exclude_associations = []

  @expand_associations = false

  # default to more efficient attribute writing - no write to DB/no validations run
  @update_and_validate = false

  @image_path_prefix = nil
end

Class Attribute Details

.configuration=(value) ⇒ Object (writeonly)

Sets the attribute configuration

Parameters:

  • value

    the value to set the attribute configuration to.



161
162
163
# File 'lib/datashift/configuration.rb', line 161

def configuration=(value)
  @configuration = value
end

Instance Attribute Details

#dummy_runBoolean

Do everything except commit changes. For import save will not be called on the final object Defaults to ‘false`. Set to `true` to cause extensive progress messages to be logged

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


79
80
81
# File 'lib/datashift/configuration.rb', line 79

def dummy_run
  @dummy_run
end

#excludeArray<#call>

When calling the export with associations methods the default is to include ALL all association TYPES as defined by

ModelMethod.supported_types_enum

This can be used to reduce this down to only export specific types

Parameters:

  • List (Array<#call>)

    of association Types to EXCLUDE (:has_one etc)

Returns:



31
32
33
# File 'lib/datashift/configuration.rb', line 31

def exclude
  @exclude
end

#exclude_associationsArray<#call>

When importing/exporting associations default is to include ALL associations of included TYPES

Specify associations by name to remove

Parameters:

  • List (Array<#call>)

    of association Names to EXCLUDE

Returns:



95
96
97
# File 'lib/datashift/configuration.rb', line 95

def exclude_associations
  @exclude_associations
end

#expand_associationsBoolean

Expand association data into multiple columns

Parameters:

  • (Boolean)

Returns:

  • (Boolean)


86
87
88
# File 'lib/datashift/configuration.rb', line 86

def expand_associations
  @expand_associations
end

#force_inclusion_of_columnsArray

List of external columns that do not map to any operator but should be included in processing.

Example use cases

Provides the opportunity for loaders to provide specific methods to handle columns
that do not map directly to a model's operators or associations

Enable handling delegated methods i.e no direct association but method is on a model through it's delegate

Parameters:

  • value (Array)

Returns:

  • (Array)


108
109
110
# File 'lib/datashift/configuration.rb', line 108

def force_inclusion_of_columns
  @force_inclusion_of_columns
end

#image_path_prefixPath

A directory path to be used to prefix all inbound PATHs

Parameters:

  • (Path)

Returns:

  • (Path)


122
123
124
# File 'lib/datashift/configuration.rb', line 122

def image_path_prefix
  @image_path_prefix
end

#include_all_columnsBoolean

All external columns should be included in processing whether or not they automatically map to an operator

Parameters:

  • (Boolean)

Returns:

  • (Boolean)


115
116
117
# File 'lib/datashift/configuration.rb', line 115

def include_all_columns
  @include_all_columns
end

#mandatoryArray<#call>

List of headers/columns that are Mandatory i.e must be present in the inbound data

Parameters:

  • List (Array<#call>)

    of headers/columns that are Mandatory

Returns:



43
44
45
# File 'lib/datashift/configuration.rb', line 43

def mandatory
  @mandatory
end

#remove_columnsArray<#call>

Parameters:

  • List (Array<#call>)

    of columns to remove from files

Returns:



36
37
38
# File 'lib/datashift/configuration.rb', line 36

def remove_columns
  @remove_columns
end

#remove_railsBoolean

Default is false - i.e id, created_at etc are included by default

Parameters:

  • Remove (Boolean)

    standard Rails cols like :id, created_at etc

Returns:

  • (Boolean)


49
50
51
# File 'lib/datashift/configuration.rb', line 49

def remove_rails
  @remove_rails
end

#strict_inbound_mappingBoolean

When performing import, default is to ignore any columns that cannot be mapped (via headers) To raise an error instead, set this to true Defaults to ‘false`.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


56
57
58
# File 'lib/datashift/configuration.rb', line 56

def strict_inbound_mapping
  @strict_inbound_mapping
end

#update_and_validateBoolean

When performing writes use update methods that write immediately to DB and use validations.

Validations can ensure business logic, but can be less efficient as writes to DB once per column

Default is to use more efficient but less strict attribute writing - no write to DB/No validations run

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


66
67
68
# File 'lib/datashift/configuration.rb', line 66

def update_and_validate
  @update_and_validate
end

#verboseBoolean

Controls the amount of information written to the log Defaults to ‘false`. Set to `true` to cause extensive progress messages to be logged

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


72
73
74
# File 'lib/datashift/configuration.rb', line 72

def verbose
  @verbose
end

#withArray<#call>

List of association TYPES to INCLUDE [:assignment, :enum, :belongs_to, :has_one, :has_many, :method] Defaults to [:assignment, :enum]

Parameters:

  • List (Array<#call>)

    of association Types to include (:has_one etc)

Returns:



20
21
22
# File 'lib/datashift/configuration.rb', line 20

def with
  @with
end

Class Method Details

.callDataShift::Configuration

Returns DataShift’s current configuration.

Returns:



150
151
152
# File 'lib/datashift/configuration.rb', line 150

def self.call
  @configuration ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Modify DataShift’s current configuration “‘ DataShift::Configuration.call do |config|

config.verbose = false

end “‘

Yield Parameters:



171
172
173
# File 'lib/datashift/configuration.rb', line 171

def self.configure
  yield call
end

.from_hash(options) ⇒ Object

Modify DataShift’s current Export configuration from an options hash



221
222
223
224
225
226
227
# File 'lib/datashift/configuration.rb', line 221

def self.from_hash( options )
  DataShift::Configuration.configure do |config|
    options.each do |key, value|
      config.send("#{key}=", value) if(config.respond_to?(key))
    end
  end
end

.rails_columnsObject



124
125
126
# File 'lib/datashift/configuration.rb', line 124

def self.rails_columns
  @rails_standard_columns ||= [:id, :created_at, :created_on, :updated_at, :updated_on]
end

.resetObject



154
155
156
# File 'lib/datashift/configuration.rb', line 154

def self.reset
  @configuration = Configuration.new
end

Instance Method Details

#op_type_in_scope?(model_method) ⇒ Boolean

Returns:

  • (Boolean)


199
200
201
# File 'lib/datashift/configuration.rb', line 199

def op_type_in_scope?( model_method )
  op_types_in_scope.include? model_method.operator_type
end

#op_types_in_scopeObject

Prepare the operators types in scope based on number of configuration attributes Default is assignment only

Responds to Configuration params :

with: [:assignment, :enum, :belongs_to, :has_one, :has_many, :method]

with: :all -> all op types

exclude: - Remove any of [::assignment, :enum, :belongs_to, :has_one, :has_many, :method]


186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/datashift/configuration.rb', line 186

def op_types_in_scope

  types_in_scope = if with_all?
                     ModelMethod.supported_types_enum.dup
                   else
                     [*@with].dup
                   end

  types_in_scope -= [*@exclude]

  types_in_scope
end

#prep_remove_listObject

Take options and create a list of symbols to remove from headers

Rails columns like id, created_at etc are included by default Specify option :remove_rails to remove them from output



212
213
214
215
216
217
218
# File 'lib/datashift/configuration.rb', line 212

def prep_remove_list
  remove_list = [*remove_columns].compact.collect { |x| x.to_s.downcase.to_sym }

  remove_list += DataShift::Configuration.rails_columns if remove_rails

  remove_list
end

#with_all?Boolean

Returns:

  • (Boolean)


203
204
205
# File 'lib/datashift/configuration.rb', line 203

def with_all?
  [*@with].include?(:all)
end