Class: DataShift::Configuration
- Inherits:
-
Object
- Object
- DataShift::Configuration
- Defined in:
- lib/datashift/configuration.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.configuration ⇒ Object
writeonly
Sets the attribute configuration.
Instance Attribute Summary collapse
-
#dummy_run ⇒ Boolean
Do everything except commit changes.
-
#exclude ⇒ Array<#call>
When calling the export with associations methods the default is to include ALL all association TYPES as defined by ModelMethod.supported_types_enum.
-
#exclude_associations ⇒ Array<#call>
When importing/exporting associations default is to include ALL associations of included TYPES.
-
#expand_associations ⇒ Boolean
Expand association data into multiple columns.
-
#force_inclusion_of_columns ⇒ Array
List of external columns that do not map to any operator but should be included in processing.
-
#image_path_prefix ⇒ Path
A directory path to be used to prefix all inbound PATHs.
-
#include_all_columns ⇒ Boolean
All external columns should be included in processing whether or not they automatically map to an operator.
-
#mandatory ⇒ Array<#call>
List of headers/columns that are Mandatory i.e must be present in the inbound data.
- #remove_columns ⇒ Array<#call>
-
#remove_rails ⇒ Boolean
Default is false - i.e id, created_at etc are included by default.
-
#strict_inbound_mapping ⇒ Boolean
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`.
-
#update_and_validate ⇒ Boolean
When performing writes use update methods that write immediately to DB and use validations.
-
#verbose ⇒ Boolean
Controls the amount of information written to the log Defaults to ‘false`.
-
#with ⇒ Array<#call>
List of association
TYPES
to INCLUDE [:assignment, :enum, :belongs_to, :has_one, :has_many, :method] Defaults to [:assignment, :enum].
Class Method Summary collapse
-
.call ⇒ DataShift::Configuration
DataShift’s current configuration.
-
.configure {|config| ... } ⇒ Object
Modify DataShift’s current configuration “‘ DataShift::Configuration.call do |config| config.verbose = false end “`.
-
.from_hash(options) ⇒ Object
Modify DataShift’s current Export configuration from an options hash.
- .parse_yaml(yaml_file) ⇒ Object
- .rails_columns ⇒ Object
- .reset ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #op_type_in_scope?(model_method) ⇒ Boolean
-
#op_types_in_scope ⇒ Object
Prepare the operators types in scope based on number of configuration attributes Default is assignment only.
-
#prep_remove_list ⇒ Object
Take options and create a list of symbols to remove from headers.
- #with_all? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/datashift/configuration.rb', line 136 def initialize @with = %i[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
169 170 171 |
# File 'lib/datashift/configuration.rb', line 169 def configuration=(value) @configuration = value end |
Instance Attribute Details
#dummy_run ⇒ Boolean
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
87 88 89 |
# File 'lib/datashift/configuration.rb', line 87 def dummy_run @dummy_run end |
#exclude ⇒ Array<#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
39 40 41 |
# File 'lib/datashift/configuration.rb', line 39 def exclude @exclude end |
#exclude_associations ⇒ Array<#call>
When importing/exporting associations default is to include ALL associations of included TYPES
Specify associations by name to remove
103 104 105 |
# File 'lib/datashift/configuration.rb', line 103 def exclude_associations @exclude_associations end |
#expand_associations ⇒ Boolean
Expand association data into multiple columns
94 95 96 |
# File 'lib/datashift/configuration.rb', line 94 def @expand_associations end |
#force_inclusion_of_columns ⇒ Array
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
116 117 118 |
# File 'lib/datashift/configuration.rb', line 116 def force_inclusion_of_columns @force_inclusion_of_columns end |
#image_path_prefix ⇒ Path
A directory path to be used to prefix all inbound PATHs
130 131 132 |
# File 'lib/datashift/configuration.rb', line 130 def image_path_prefix @image_path_prefix end |
#include_all_columns ⇒ Boolean
All external columns should be included in processing whether or not they automatically map to an operator
123 124 125 |
# File 'lib/datashift/configuration.rb', line 123 def include_all_columns @include_all_columns end |
#mandatory ⇒ Array<#call>
List of headers/columns that are Mandatory i.e must be present in the inbound data
51 52 53 |
# File 'lib/datashift/configuration.rb', line 51 def mandatory @mandatory end |
#remove_columns ⇒ Array<#call>
44 45 46 |
# File 'lib/datashift/configuration.rb', line 44 def remove_columns @remove_columns end |
#remove_rails ⇒ Boolean
Default is false - i.e id, created_at etc are included by default
57 58 59 |
# File 'lib/datashift/configuration.rb', line 57 def remove_rails @remove_rails end |
#strict_inbound_mapping ⇒ Boolean
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`.
64 65 66 |
# File 'lib/datashift/configuration.rb', line 64 def strict_inbound_mapping @strict_inbound_mapping end |
#update_and_validate ⇒ Boolean
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
74 75 76 |
# File 'lib/datashift/configuration.rb', line 74 def update_and_validate @update_and_validate end |
#verbose ⇒ Boolean
Controls the amount of information written to the log Defaults to ‘false`. Set to `true` to cause extensive progress messages to be logged
80 81 82 |
# File 'lib/datashift/configuration.rb', line 80 def verbose @verbose end |
#with ⇒ Array<#call>
List of association TYPES
to INCLUDE [:assignment, :enum, :belongs_to, :has_one, :has_many, :method] Defaults to [:assignment, :enum]
28 29 30 |
# File 'lib/datashift/configuration.rb', line 28 def with @with end |
Class Method Details
.call ⇒ DataShift::Configuration
Returns DataShift’s current configuration.
158 159 160 |
# File 'lib/datashift/configuration.rb', line 158 def self.call @configuration ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
Modify DataShift’s current configuration “‘ DataShift::Configuration.call do |config|
config.verbose = false
end “‘
179 180 181 |
# File 'lib/datashift/configuration.rb', line 179 def self.configure yield call end |
.from_hash(options) ⇒ Object
Modify DataShift’s current Export configuration from an options hash
229 230 231 232 233 234 235 |
# File 'lib/datashift/configuration.rb', line 229 def self.from_hash( ) DataShift::Configuration.configure do |config| .each do |key, value| config.send("#{key}=", value) if(config.respond_to?(key)) end end end |
.parse_yaml(yaml_file) ⇒ Object
15 16 17 18 19 |
# File 'lib/datashift/configuration.rb', line 15 def self.parse_yaml( yaml_file ) bound_template = ERB.new( IO.read(yaml_file)).result YAML.safe_load(bound_template, [Date, Time, Symbol] ) end |
.rails_columns ⇒ Object
132 133 134 |
# File 'lib/datashift/configuration.rb', line 132 def self.rails_columns @rails_standard_columns ||= %i[id created_at created_on updated_at updated_on] end |
.reset ⇒ Object
162 163 164 |
# File 'lib/datashift/configuration.rb', line 162 def self.reset @configuration = Configuration.new end |
Instance Method Details
#op_type_in_scope?(model_method) ⇒ Boolean
207 208 209 |
# File 'lib/datashift/configuration.rb', line 207 def op_type_in_scope?( model_method ) op_types_in_scope.include? model_method.operator_type end |
#op_types_in_scope ⇒ Object
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]
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/datashift/configuration.rb', line 194 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_list ⇒ Object
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
220 221 222 223 224 225 226 |
# File 'lib/datashift/configuration.rb', line 220 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
211 212 213 |
# File 'lib/datashift/configuration.rb', line 211 def with_all? [*@with].include?(:all) end |