class SoberSwag::Reporting::Input::Pattern
Input
values that validate against a pattern
Attributes
input[R]
@return [#call] input type
pattern[R]
@return [#matches] regexp matcher
Public Class Methods
new(input, pattern)
click to toggle source
# File lib/sober_swag/reporting/input/pattern.rb, line 7 def initialize(input, pattern) @input = input @pattern = pattern end
Public Instance Methods
call(value)
click to toggle source
# File lib/sober_swag/reporting/input/pattern.rb, line 20 def call(value) val = input.call(value) return val if val.is_a?(Report::Base) if pattern.match?(value) value else Report::Value.new(["did not match pattern #{pattern}"]) end end
formatted_pattern()
click to toggle source
Try to format a pattern so it'll work nicely with JS.
# File lib/sober_swag/reporting/input/pattern.rb, line 40 def formatted_pattern pattern.to_s.gsub('?-mix:', '') end
swagger_schema()
click to toggle source
# File lib/sober_swag/reporting/input/pattern.rb, line 32 def swagger_schema single, found = input.swagger_schema [add_schema_key(single, { pattern: formatted_pattern }), found] end