class Tchae::Validator
Attributes
message[R]
Public Class Methods
new(proc, msg: nil)
click to toggle source
# File lib/tchae/core.rb, line 117 def initialize(proc, msg: nil) @proc = proc @message = msg.nil? ? "does not fulfill #{proc}.to_s" : msg end
Public Instance Methods
execute(input)
click to toggle source
# File lib/tchae/core.rb, line 122 def execute(input) input.instance_exec(&@proc) end
return_error(input, eklass)
click to toggle source
# File lib/tchae/core.rb, line 136 def return_error(input, eklass) eklass.new(input) end
valid_or_raise_exception(input, eklass)
click to toggle source
# File lib/tchae/core.rb, line 126 def valid_or_raise_exception(input, eklass) raise eklass unless execute(input) input end
valid_or_return_error(input, eklass)
click to toggle source
# File lib/tchae/core.rb, line 132 def valid_or_return_error(input, eklass) execute(input) ? input : return_error(input, eklass) end
wrapped_result_or_error(result, eklass)
click to toggle source
# File lib/tchae/core.rb, line 140 def wrapped_result_or_error(result, eklass) execute(result) ? Return(result) : Return(nil, return_error(result, eklass)) end