Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Permit inline :must =>

#12

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.

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

State: new
Milestone: none
Assigned to: Sean O'Halpin Sean O'Halpin

Activity

  1. kentnl@cpan.org
    kentnl@cpan.org

    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.

    January 28th, 2016 @ 05:48 AM

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.