solnic / coercible

Powerful, flexible and configurable coercion library. And nothing more.
MIT License
137 stars 16 forks source link

coerce of Date to integer #26

Open kurbaitis opened 6 years ago

kurbaitis commented 6 years ago

Hello,

I use Virtus for building models and declare an attribute with type Integer. Virtus has dependency to coercible. The problem is that sometimes the model attribute receives a Date object and fails in your gem.

I believe it's something like this:

coercer = Coercible::Coercer.new
coercer[Date].to_integer('1')

This raises: ArgumentError: wrong number of arguments (given 3, expected 2)

The fix is to implement #to_integer in TimeCoercions like this monkey patch:

module Coercible
  class Coercer

    module TimeCoercions
      def to_integer(_); end
    end

  end
end

I guess it's not expected situation for the gem, but would be wonderful to see that it supports more use cases and I wouldn't need to monkey patch this.

Please let me know if you are still maintaining the gem so that we could agree about the final solution and make the gem even better.