Class: DataShift::MappingService
- Includes:
- Logging
- Defined in:
- lib/datashift/mapping_service.rb
Instance Attribute Summary collapse
-
#map_file_name ⇒ Object
readonly
N.B :all_config, :key_config are OpenStruct data structure that provides definition of config entries as attributes with their accompanying values.
-
#mapped_class_name ⇒ Object
readonly
N.B :all_config, :key_config are OpenStruct data structure that provides definition of config entries as attributes with their accompanying values.
-
#mapping_entry ⇒ Object
readonly
Returns the value of attribute mapping_entry.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
-
#yaml_data ⇒ Object
readonly
Returns the value of attribute yaml_data.
Instance Method Summary collapse
-
#initialize(klass) ⇒ MappingService
constructor
A new instance of MappingService.
-
#method_missing(method, *args, &block) ⇒ Object
OpenStruct not a hash ..
- #read(file, key = nil) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(klass) ⇒ MappingService
Returns a new instance of MappingService.
28 29 30 |
# File 'lib/datashift/mapping_service.rb', line 28 def initialize( klass ) @mapped_class_name = klass.name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
OpenStruct not a hash .. supports form … config.path, config.full_name etc
54 55 56 57 |
# File 'lib/datashift/mapping_service.rb', line 54 def method_missing(method, *args, &block) #logger :debug, "method_missing called with : #{method}" @mapping_entry.send(method) end |
Instance Attribute Details
#map_file_name ⇒ Object (readonly)
N.B :all_config, :key_config are OpenStruct data structure that provides definition of config entries as attributes with their accompanying values. So if you had a top level config entries in the YAML called path & full_name, you can call
config.path
config.full_name etc
For a more Hash like representation use config.yaml or config
24 25 26 |
# File 'lib/datashift/mapping_service.rb', line 24 def map_file_name @map_file_name end |
#mapped_class_name ⇒ Object (readonly)
N.B :all_config, :key_config are OpenStruct data structure that provides definition of config entries as attributes with their accompanying values. So if you had a top level config entries in the YAML called path & full_name, you can call
config.path
config.full_name etc
For a more Hash like representation use config.yaml or config
24 25 26 |
# File 'lib/datashift/mapping_service.rb', line 24 def mapped_class_name @mapped_class_name end |
#mapping_entry ⇒ Object (readonly)
Returns the value of attribute mapping_entry.
26 27 28 |
# File 'lib/datashift/mapping_service.rb', line 26 def mapping_entry @mapping_entry end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
26 27 28 |
# File 'lib/datashift/mapping_service.rb', line 26 def raw_data @raw_data end |
#yaml_data ⇒ Object (readonly)
Returns the value of attribute yaml_data.
26 27 28 |
# File 'lib/datashift/mapping_service.rb', line 26 def yaml_data @yaml_data end |
Instance Method Details
#read(file, key = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/datashift/mapping_service.rb', line 32 def read( file, key = nil ) @map_file_name = file unless(map_file_name && File.exists?(map_file_name)) logger.error "Cannot open mapping file - #{map_file_name} - file does not exist." raise FileNotFound.new("Cannot open mapping file - #{map_file_name}") end begin # Load application configuration set_mapping( map_file_name ) set_key_config!( key ) if key rescue => e puts e.inspect logger.error "Failed to parse config file #{map_file_name} - bad YAML ?" raise e end end |