Sha256: 7d3d84b7fbec7f7f30fe0b0e19ebbdce607c8f179223fd8f4680ac7bd8c4f28f
Contents?: true
Size: 1.41 KB
Versions: 2
Compression:
Stored size: 1.41 KB
Contents
require "facets/string/camelcase" module WildcardMatchers module Matchers class << self def define_wildcard_matcher(name, &block) if block_given? define_method(name, &block) else define_method(name) do |*args| ::WildcardMatchers::Matchers.const_get(name.to_s.camelcase(:upper)).new(args) end end end def define_wildcard_matcher_with_proc(name, &block) raise "no block defined" unless block_given? define_method(name) do block end end end # is_a(klass) define_wildcard_matcher(:is_a) do |klass| klass end # is_a_string # is_a_integer # is_a_float # is_a_hash # is_a_array [ String, Integer, Float, Hash, Array ].each do |klass| define_wildcard_matcher("is_a_#{klass.to_s.downcase}") do klass end end # is_bool define_wildcard_matcher_with_proc(:is_bool) do |bool| TrueClass === bool or FalseClass === bool end # is_time define_wildcard_matcher_with_proc(:is_time) do |time| require "time" time.is_a?(Time) or (Time.parse(time) rescue false) end # TODO: DSL def is_a_member_of(*args) lambda do |item| args.flatten.any? {|expected| expected === item } end end end end require "wildcard_matchers/matchers/hash_includes" require "wildcard_matchers/matchers/is_uri"
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wildcard_matchers-0.1.3 | lib/wildcard_matchers/matchers.rb |
wildcard_matchers-0.1.2 | lib/wildcard_matchers/matchers.rb |