Sha256: 6e7ecd75795787c92a6a5df5b4310c3b0061d2a26470b5511825e31b3850b224

Contents?: true

Size: 832 Bytes

Versions: 5

Compression:

Stored size: 832 Bytes

Contents

module DataMaps
  module Dsl
    module Mapping
      # Structure to describe a field mapping
      class FieldMappingDsl < Struct.new(:from, :conditions, :converter)
        include DataMaps::Concerns::Configurable

        def initialize(options = {})
          self.from = options[:from]
          self.conditions = []
          self.converter = []
        end

        def add_condition(&block)
          dsl = DataMaps::Dsl::Mapping::ConditionsDsl.new
          dsl.configure(&block) if block_given?
          self.conditions << dsl.to_h
        end

        def add_converter(converter, options = nil)
          self.converter << { apply: converter, option: options }
        end

        # Serialize DSL to an Hash
        def to_h
          data = super
          data.stringify_keys
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
data_maps-0.3.4 lib/data_maps/dsl/mapping/field_dsl.rb
data_maps-0.3.3 lib/data_maps/dsl/mapping/field_dsl.rb
data_maps-0.3.2 lib/data_maps/dsl/mapping/field_dsl.rb
data_maps-0.3.1 lib/data_maps/dsl/mapping/field_dsl.rb
data_maps-0.3.0 lib/data_maps/dsl/mapping/field_dsl.rb