Sha256: 81a2456643ed68b7490c617fee632c1252cf9fd01ed94d6d138137721e5c7347
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
module Inspector module Constraints autoload :Base, 'inspector/constraints/base' autoload :False, 'inspector/constraints/false' autoload :True, 'inspector/constraints/true' autoload :Empty, 'inspector/constraints/empty' autoload :Predicate, 'inspector/constraints/predicate' autoload :Have, 'inspector/constraints/have' autoload :Email, 'inspector/constraints/email' autoload :Eq, 'inspector/constraints/eq' autoload :Valid, 'inspector/constraints/valid' def be_false False.new end def be_true True.new end def be_empty Empty.new end def have_at_least(n) Have::AtLeast.new(n) end def have_at_most(n) Have::AtMost.new(n) end def have(n) Have::Exactly.new(n) end alias :have_exactly :have def be_email Email.new end alias :be_an_email :be_email def eq(expected) Eq.new(expected) end def validate(options = {}) Valid.new(options[:as]) end # be_empty => value.empty? # be_nil => value.nil? def method_missing(method, *args, &block) prefix, *predicate = method.to_s.split("_") predicate.shift if ["a", "an"].include?(predicate.first) return Inspector::Constraints::Predicate.new(predicate.join("_"), *args, &block) if prefix == "be" # return Inspector::Constraints::Has.new(method, *args, &block) if method.to_s =~ /^have_/ super end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
object-inspector-0.1.0 | lib/inspector/constraints.rb |