Sha256: 2ca8e6d4fb2dee493d678d7dac7aa5f273bc7707a0bc32c350bb3c73d2f11d03

Contents?: true

Size: 1.29 KB

Versions: 18

Compression:

Stored size: 1.29 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 = {})
            wrapped_input = InputWithSchema.new(relation, options.fetch(:input) { input })
            super(relation, options.merge(input: wrapped_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

18 entries across 18 versions & 1 rubygems

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