Sha256: 8fc5f7549b8ae9b6f5de9d5b31d18da6b4ae0656982a7b32b84c7157985deaf3

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

module Hanami
  module Model
    module Plugins
      # Transform output into model domain types (entities).
      #
      # @since 0.7.0
      # @api private
      module Mapping
        # Takes the output and applies the transformations
        #
        # @since 0.7.0
        # @api private
        class InputWithMapping < WrappingInput
          # @since 0.7.0
          # @api private
          def initialize(relation, input)
            super
            @mapping = Hanami::Model.configuration.mappings[relation.name.to_sym]
          end

          # Processes the output
          #
          # @since 0.7.0
          # @api private
          def [](value)
            @mapping.process(@input[value])
          end
        end

        # Class interface
        #
        # @since 0.7.0
        # @api private
        module ClassMethods
          # Builds the output processor
          #
          # @since 0.7.0
          # @api private
          def build(relation, options = {})
            input(InputWithMapping.new(relation, input))
            super(relation, options.merge(input: input))
          end
        end

        # @since 0.7.0
        # @api private
        def self.included(klass)
          super

          klass.extend ClassMethods
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hanami-model-1.0.0 lib/hanami/model/plugins/mapping.rb
hanami-model-1.0.0.rc1 lib/hanami/model/plugins/mapping.rb
hanami-model-1.0.0.beta3 lib/hanami/model/plugins/mapping.rb
hanami-model-1.0.0.beta2 lib/hanami/model/plugins/mapping.rb
hanami-model-1.0.0.beta1 lib/hanami/model/plugins/mapping.rb
hanami-model-0.7.0 lib/hanami/model/plugins/mapping.rb