Class: Sus::RespondTo::WithOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/sus/respond_to.rb

Overview

Represents a constraint on method keyword options.

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ WithOptions

Initialize a new WithOptions constraint.



45
46
47
# File 'lib/sus/respond_to.rb', line 45

def initialize(options)
	@options = options
end

Instance Method Details

#call(assertions, subject) ⇒ Object

Evaluate this constraint against method parameters.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/sus/respond_to.rb', line 58

def call(assertions, subject)
	options = {}
	@options.each{|name| options[name] = nil}
	
	subject.each do |type, name|
		options[name] = type					
	end
	
	assertions.nested(self) do |assertions|
		options.each do |name, type|
			assertions.assert(type != nil, "option #{name}: is required")
		end
	end
end

Print a representation of this constraint.



51
52
53
# File 'lib/sus/respond_to.rb', line 51

def print(output)
	output.write("with options ", :variable, @options.inspect)
end