Sha256: 93488b5e8abb4dd2e79641984d83014e97eff868830b6f223b5aed0a78b35366

Contents?: true

Size: 1.09 KB

Versions: 21

Compression:

Stored size: 1.09 KB

Contents

require 'transproc/all'

module Hanami
  module Model
    # Mapping
    #
    # @since 0.1.0
    # @api private
    class Mapping
      extend Transproc::Registry

      import Transproc::HashTransformations

      # @since 0.1.0
      # @api private
      def initialize(&blk)
        @attributes   = {}
        @r_attributes = {}
        instance_eval(&blk)
        @processor = @attributes.empty? ? ::Hash : t(:rename_keys, @attributes)
      end

      # @api private
      def t(name, *args)
        self.class[name, *args]
      end

      # @api private
      def model(entity)
      end

      # @api private
      def register_as(name)
      end

      # @api private
      def attribute(name, options)
        from = options.fetch(:from, name)

        @attributes[name]   = from
        @r_attributes[from] = name
      end

      # @api private
      def process(input)
        @processor[input]
      end

      # @api private
      def reverse?
        @r_attributes.any?
      end

      # @api private
      def translate(attribute)
        @r_attributes.fetch(attribute)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hanami-model-1.3.2 lib/hanami/model/mapping.rb
hanami-model-1.3.1 lib/hanami/model/mapping.rb
hanami-model-1.3.0 lib/hanami/model/mapping.rb
hanami-model-1.3.0.beta1 lib/hanami/model/mapping.rb
hanami-model-1.2.0 lib/hanami/model/mapping.rb
hanami-model-1.2.0.rc2 lib/hanami/model/mapping.rb
hanami-model-1.2.0.rc1 lib/hanami/model/mapping.rb
hanami-model-1.2.0.beta2 lib/hanami/model/mapping.rb
hanami-model-1.2.0.beta1 lib/hanami/model/mapping.rb
hanami-model-1.1.0 lib/hanami/model/mapping.rb
hanami-model-1.1.0.rc1 lib/hanami/model/mapping.rb
hanami-model-1.0.4 lib/hanami/model/mapping.rb
hanami-model-1.0.3 lib/hanami/model/mapping.rb
hanami-model-1.1.0.beta3 lib/hanami/model/mapping.rb
hanami-model-1.1.0.beta2 lib/hanami/model/mapping.rb
hanami-model-1.1.0.beta1 lib/hanami/model/mapping.rb
hanami-model-1.0.2 lib/hanami/model/mapping.rb
hanami-model-1.0.1 lib/hanami/model/mapping.rb
hanami-model-1.0.0 lib/hanami/model/mapping.rb
hanami-model-1.0.0.rc1 lib/hanami/model/mapping.rb