#12 new
kentnl@cpan.org

Permit inline :must =>

Reported by kentnl@cpan.org | January 27th, 2016 @ 09:36 PM

I initially thought perhaps I could get away with something like:


  require 'doodle'

  class TypeCheck
    def TypeCheck.fixed_length(length)
      ["be length == %d" % [length], lambda { |value|  value.to_s.length == length } ]
    end
    def TypeCheck.boolean
      ["be true or false", lambda { |value| value.kind_of?(TrueClass) or value.kind_of?(FalseClass) }]
    end
  end

  class TestCaseX < Doodle 
    has :a_char, :kind => String, :must => TypeCheck.fixed_length(1)
    has :a_bool, :must => TypeCheck.boolean
  end

  TestCaseX.new( :a_char => "Whatever the heck I want", :a_bool => "False-or-not" )

The idea being able to fake a Type Constraint system and get reusable composable validation. (I've been using Perl's Moose for a long time :) )

But alas, not only does it not work as expected, I don't even get warnings/errors that :must is being discarded wholesale.

:from is similarly without warning/error, but asking to mimic the parts of Moose Type constraints here might be too much to ask.

Comments and changes to this ticket

  • kentnl@cpan.org

    kentnl@cpan.org January 28th, 2016 @ 05:48 AM

    Fwiw, I'm also poking at a few type constraint systems and hope its possible to have some kind of adapter class that allows using these type constraints under doodle.

    Contracts for instance takes the approach the from the other direction, but I think their underlying mechanic might lend itself to re-use with a few tweaks.

    https://github.com/egonSchiele/contracts.ruby/issues/222

    But it would be good if we don't trap ourselves to a single type system because there's so many of them and none of them have really matured to the point where we can say "This is the way forward" IMHO.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

This site is for tracking issues for the doodle rubygem.

doodle is a Ruby gem for creating extended attribute accessors with defaults, conversions and validations.

See http://doodle.rubyforge.org/ for more details.

People watching this ticket

Pages