Sha256: 6b0c5f71fff53869acd8646f9759f7e13d7df4c8b2fc1f36f0a470c3d4586264

Contents?: true

Size: 754 Bytes

Versions: 5

Compression:

Stored size: 754 Bytes

Contents

gem 'dry-types', '>= 1.0.0'
require "dry-types"

module Representable
  module Coercion
    module Types
      include Dry::Types()
    end
    class Coercer
      def initialize(type)
        @type = type
      end

      def call(input, _options)
        @type.call(input)
      end
    end


    def self.included(base)
      base.class_eval do
        extend ClassMethods
        register_feature Coercion
      end
    end


    module ClassMethods
      def property(name, options={}, &block)
        super.tap do |definition|
          return definition unless type = options[:type]

          definition.merge!(render_filter: coercer = Coercer.new(type))
          definition.merge!(parse_filter: coercer)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/representable-3.2.0/lib/representable/coercion.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/representable-3.2.0/lib/representable/coercion.rb
representable-3.2.0 lib/representable/coercion.rb
representable-3.1.1 lib/representable/coercion.rb
representable-3.1.0 lib/representable/coercion.rb