Class: Totes::Query

Inherits:
Noop
  • Object
show all
Defined in:
lib/totes/query.rb

Defined Under Namespace

Classes: OperationsWrapper

Instance Method Summary collapse

Constructor Details

#initialize(subject) ⇒ Query

Returns a new instance of Query.



6
7
8
# File 'lib/totes/query.rb', line 6

def initialize(subject)
  @subject = Totes::Subject.new(subject)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



26
27
28
# File 'lib/totes/query.rb', line 26

def method_missing(name, *args, &block)
  Totes::Query.new(@subject.__send__ name, *args, &block)
end

Instance Method Details

#must(*args, &block) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/totes/query.rb', line 10

def must(*args, &block)
  if matcher = args[0]
    __try__ { matcher.test(@subject, fail_on: false) }
  else
    OperationsWrapper.new(self, :must)
  end
end

#wont(*args, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/totes/query.rb', line 18

def wont(*args, &block)
  if matcher = args[0]
    __try__ { matcher.test(@subject, fail_on: true) }
  else
    OperationsWrapper.new(self, :wont)
  end
end