Class: Tchae::Validator
Direct Known Subclasses
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
- #execute(input) ⇒ Object
-
#initialize(proc, msg: nil) ⇒ Validator
constructor
A new instance of Validator.
- #return_error(input, eklass) ⇒ Object
- #valid_or_raise_exception(input, eklass) ⇒ Object
- #valid_or_return_error(input, eklass) ⇒ Object
- #wrapped_result_or_error(result, eklass) ⇒ Object
Constructor Details
#initialize(proc, msg: nil) ⇒ Validator
Returns a new instance of Validator.
117 118 119 120 |
# 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 |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
115 116 117 |
# File 'lib/tchae/core.rb', line 115 def @message end |
Instance Method Details
#execute(input) ⇒ Object
122 123 124 |
# File 'lib/tchae/core.rb', line 122 def execute(input) input.instance_exec(&@proc) end |
#return_error(input, eklass) ⇒ Object
136 137 138 |
# File 'lib/tchae/core.rb', line 136 def return_error(input, eklass) eklass.new(input) end |
#valid_or_raise_exception(input, eklass) ⇒ Object
126 127 128 129 130 |
# 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) ⇒ Object
132 133 134 |
# 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) ⇒ Object
140 141 142 |
# 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 |