Class: DataShift::Transformation::Factory
- Inherits:
-
Object
- Object
- DataShift::Transformation::Factory
- Includes:
- Logging
- Defined in:
- lib/datashift/transformation/factory.rb
Constant Summary collapse
- TRANSFORMERS_HASH_INSTANCE_NAMES =
%i[default override substitution prefix postfix].freeze
Instance Attribute Summary collapse
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#overrides ⇒ Object
readonly
Returns the value of attribute overrides.
-
#postfixes ⇒ Object
readonly
Returns the value of attribute postfixes.
-
#prefixes ⇒ Object
readonly
Returns the value of attribute prefixes.
-
#substitutions ⇒ Object
readonly
Returns the value of attribute substitutions.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
-
#configure_from(load_object_class, yaml_file, locale_key = 'data_flow_schema') ⇒ Object
Default values and over rides per class can be provided in YAML config file.
- #configure_from_yaml(load_object_class, yaml) ⇒ Object
- #hash_key(key) ⇒ Object
-
#initialize ⇒ Factory
constructor
A new instance of Factory.
- #set_substitution(method_binding, rule, replacement) ⇒ Object
- #set_substitution_on(key, operator, rule, replacement) ⇒ Object
Methods included from Logging
#logdir, #logdir=, #logger, #verbose
Constructor Details
#initialize ⇒ Factory
Returns a new instance of Factory.
82 83 84 |
# File 'lib/datashift/transformation/factory.rb', line 82 def initialize clear end |
Instance Attribute Details
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
79 80 81 |
# File 'lib/datashift/transformation/factory.rb', line 79 def defaults @defaults end |
#overrides ⇒ Object (readonly)
Returns the value of attribute overrides.
79 80 81 |
# File 'lib/datashift/transformation/factory.rb', line 79 def overrides @overrides end |
#postfixes ⇒ Object (readonly)
Returns the value of attribute postfixes.
80 81 82 |
# File 'lib/datashift/transformation/factory.rb', line 80 def postfixes @postfixes end |
#prefixes ⇒ Object (readonly)
Returns the value of attribute prefixes.
80 81 82 |
# File 'lib/datashift/transformation/factory.rb', line 80 def prefixes @prefixes end |
#substitutions ⇒ Object (readonly)
Returns the value of attribute substitutions.
79 80 81 |
# File 'lib/datashift/transformation/factory.rb', line 79 def substitutions @substitutions end |
Class Method Details
.instance(locale = :en) ⇒ Object
71 72 73 |
# File 'lib/datashift/transformation/factory.rb', line 71 def self.instance(locale = :en) @__instance__[locale] ||= new end |
.reset(locale = :en) ⇒ Object
75 76 77 |
# File 'lib/datashift/transformation/factory.rb', line 75 def self.reset(locale = :en) @__instance__[locale] = new end |
Instance Method Details
#clear ⇒ Object
86 87 88 89 90 |
# File 'lib/datashift/transformation/factory.rb', line 86 def clear TRANSFORMERS_HASH_INSTANCE_NAMES.each do|h| instance_variable_set("@#{h.to_s.pluralize}", ActiveSupport::HashWithIndifferentAccess.new({})) end end |
#configure_from(load_object_class, yaml_file, locale_key = 'data_flow_schema') ⇒ Object
Default values and over rides per class can be provided in YAML config file.
The locale_key for situations where the Class one level down, for example as per our own Template for Datashift Import/Export Configuration which has format :
key:
klass:
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/datashift/transformation/factory.rb', line 100 def configure_from(load_object_class, yaml_file, locale_key = 'data_flow_schema') data = Configuration.parse_yaml(yaml_file) class_name = load_object_class.name data = data[locale_key] if(locale_key) configure_from_yaml(load_object_class, data[class_name]) if(data[class_name]) end |
#configure_from_yaml(load_object_class, yaml) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/datashift/transformation/factory.rb', line 111 def configure_from_yaml(load_object_class, yaml) setter_method_map = { defaults: :set_default_on, overrides: :set_override_on, substitutions: :set_substitution_on_list, prefixes: :set_prefix_on, postfixes: :set_postfix_on } setter_method_map.each do |key, call| settings = yaml[key.to_s] next unless settings && settings.is_a?(Hash) settings.each do |operator, value| logger.info("Configuring Transform [#{key}] for [#{operator.inspect}] to [#{value}]") send( call, load_object_class, operator, value) end end end |
#hash_key(key) ⇒ Object
133 134 135 136 137 |
# File 'lib/datashift/transformation/factory.rb', line 133 def hash_key(key) return key if(key.is_a? String) return key.class_name if(key.is_a? MethodBinding) key.name # Class name end |
#set_substitution(method_binding, rule, replacement) ⇒ Object
203 204 205 |
# File 'lib/datashift/transformation/factory.rb', line 203 def set_substitution( method_binding, rule, replacement ) set_substitution_on( method_binding, method_binding.operator, rule, replacement) end |
#set_substitution_on(key, operator, rule, replacement) ⇒ Object
207 208 209 |
# File 'lib/datashift/transformation/factory.rb', line 207 def set_substitution_on(key, operator, rule, replacement ) substitutions_for(key)[operator] = Struct::Substitution.new(rule, replacement) end |