Class: Oval::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/oval/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.


48
49
# File 'lib/oval/base.rb', line 48

def initialize(*args)
end

Class Method Details

.[](*args) ⇒ Object

,subject = default_subject)


36
37
38
# File 'lib/oval/base.rb', line 36

def self.[](*args)#,subject = default_subject)
  return new(*args)
end

.ensure_equal(thing, decl, subject = nil) ⇒ Object


8
9
10
11
12
13
14
# File 'lib/oval/base.rb', line 8

def self.ensure_equal(thing, decl, subject = nil)
  unless (decl == Oval::Anything) or (thing == decl)
    raise Oval::ValueError,
      "Invalid value #{thing.inspect}#{for_subject(subject)}. Should be " +
      "equal #{decl.inspect}"
  end
end

.it_should(decl) ⇒ Object


25
26
27
28
29
30
31
32
33
34
# File 'lib/oval/base.rb', line 25

def self.it_should(decl)
  if decl.is_a? Oval::Base
    decl.it_should
  elsif decl == Oval::Anything
    Oval::Anything[].it_should
  else
    # "terminal symbol"
    "be equal #{decl.inspect}"
  end
end

.validate(thing, decl, subject = nil) ⇒ Object


16
17
18
19
20
21
22
23
# File 'lib/oval/base.rb', line 16

def self.validate(thing, decl, subject = nil)
  if decl.is_a? Oval::Base
    decl.validate(thing,subject)
  else
    # "terminal symbol"
    ensure_equal(thing, decl, subject)
  end
end

Instance Method Details

#it_shouldObject

Raises:

  • (NotImplementedError)

44
45
46
# File 'lib/oval/base.rb', line 44

def it_should()
  raise NotImplementedError, "This method should be overwritten by a subclass"
end

#validate(value, subject = nil) ⇒ Object

Raises:

  • (NotImplementedError)

40
41
42
# File 'lib/oval/base.rb', line 40

def validate(value, subject = nil)
  raise NotImplementedError, "This method should be overwritten by a subclass"
end