lib/polytrix/validator.rb in polytrix-0.1.0.pre vs lib/polytrix/validator.rb in polytrix-0.1.0

- old
+ new

@@ -1,20 +1,24 @@ +require 'rspec/expectations' + module Polytrix class Validator + include RSpec::Matchers + UNIVERSAL_MATCHER = // - attr_reader :suite, :sample, :callback + attr_reader :suite, :sample, :level, :callback def initialize(scope = {}, &validator) @suite = scope[:suite] ||= UNIVERSAL_MATCHER @sample = scope[:sample] ||= UNIVERSAL_MATCHER @callback = validator end def should_validate?(challenge) - !!(@suite.match(challenge.suite) && @sample.match(challenge.name)) + !!(@suite.match(challenge.suite.to_s) && @sample.match(challenge.name.to_s)) end - # def validate(challenge) - # instance_exec challenge, @callback if should_validate?(challenge) - # end + def validate(challenge) + instance_exec challenge, &@callback if should_validate?(challenge) + end end end