Sha256: faaf158a18d3aeebc1055d089b812c9467142a0ab732a3fa0b890a2ac3b56b9c

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

module Hanami
  module Model
    module Plugins
      # Transform input values into database specific types (primitives).
      #
      # @since 0.7.0
      # @api private
      module Schema
        # Takes the input and applies the values transformations.
        #
        # @since 0.7.0
        # @api private
        class InputWithSchema < WrappingInput
          # @since 0.7.0
          # @api private
          def initialize(relation, input)
            super
            @schema = relation.input_schema
          end

          # Processes the input
          #
          # @since 0.7.0
          # @api private
          def [](value)
            @schema[@input[value]]
          end
        end

        # Class interface
        #
        # @since 0.7.0
        # @api private
        module ClassMethods
          # Builds the input processor
          #
          # @since 0.7.0
          # @api private
          def build(relation, options = {})
            input(InputWithSchema.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

5 entries across 5 versions & 1 rubygems

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