class Muack::Where
Constants
- None
Public Class Methods
new(spec)
click to toggle source
Calls superclass method
Muack::Satisfying::new
# File lib/muack/satisfying.rb, line 120 def initialize spec super([spec]) end
Public Instance Methods
match(actual_arg, spec=api_args.first)
click to toggle source
# File lib/muack/satisfying.rb, line 124 def match actual_arg, spec=api_args.first case spec when Hash actual_arg.kind_of?(Hash) && match_hash(actual_arg, spec) when Array actual_arg.kind_of?(Array) && match_array(actual_arg, spec) else raise UnknownSpec.new(spec) end end
Private Instance Methods
match_array(actual_arg, spec)
click to toggle source
# File lib/muack/satisfying.rb, line 142 def match_array actual_arg, spec spec.zip(actual_arg).all? do |(ev, av)| match_value(av, ev) end end
match_hash(actual_arg, spec)
click to toggle source
# File lib/muack/satisfying.rb, line 136 def match_hash actual_arg, spec (spec.keys | actual_arg.keys).all? do |key| match_value(actual_arg, spec, key) end end
match_value(av, ev, key=None)
click to toggle source
# File lib/muack/satisfying.rb, line 148 def match_value av, ev, key=None if key == None a, e = av, ev elsif av.key?(key) && ev.key?(key) a, e = av[key], ev[key] else return false end case e when Satisfying e.match(a) when Hash a.kind_of?(Hash) && match_hash(a, e) when Array a.kind_of?(Array) && match_array(a, e) else e == a end end