Sha256: 66c337ded32f45db127c4ae6b73daa276249c693f8994d217e19965bad514123

Contents?: true

Size: 733 Bytes

Versions: 1

Compression:

Stored size: 733 Bytes

Contents

module MiniCamel
  module Processor
    class ExposeFields < Base

      values do
        attribute :fields, [Symbol]
        attribute :from, Symbol
      end

      def call(exchange)
        from_value  = exchange.context_fetch(from)

        if from_value.is_a?(Hash)
          field_values = map_hash(from_value)
        else
          field_values = map_object(from_value)
        end

        exchange.update_context(field_values || {})
      end

      private

      def map_hash(from_value)
        fields.map{|field| {field => from_value[field]}}.reduce(&:merge)
      end

      def map_object(from_value)
        fields.map{|field| {field => from_value.public_send(field)}}.reduce(&:merge)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mini_camel-0.5.8 lib/mini_camel/processor/expose_fields.rb