Class: Waves::Matchers::Traits

Inherits:
Object
  • Object
show all
Defined in:
lib/waves/matchers/traits.rb

Overview

TODO:

Umm.. what all can exist here? –rue

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ Traits

Returns a new instance of Traits.

Raises:

  • (ArgumentError)


8
9
10
11
# File 'lib/waves/matchers/traits.rb', line 8

def initialize(pattern)
  raise ArgumentError, "No traits given!" unless pattern
  @pattern = pattern
end

Instance Method Details

#[](request) ⇒ Object

Proc-like interface



21
22
23
# File 'lib/waves/matchers/traits.rb', line 21

def [](request)
  call request
end

#call(request) ⇒ Object



13
14
15
16
17
# File 'lib/waves/matchers/traits.rb', line 13

def call( request )
  @pattern.all? do | key, val |
    ( val.is_a? Proc and val.call( request.traits[ key ] ) ) or val === request.traits[ key ]
  end
end