Class: AnyVali::StringSchema
- Inherits:
-
Schema
- Object
- Schema
- AnyVali::StringSchema
show all
- Defined in:
- lib/anyvali/schemas/string_schema.rb
Constant Summary
Constants inherited
from Schema
AnyVali::Schema::RESERVED_METADATA_KEYS
Instance Attribute Summary
Attributes inherited from Schema
#coerce_config, #constraints, #custom_validators, #default_value, #has_default, #kind, #metadata
Instance Method Summary
collapse
Methods inherited from Schema
#coerce, #default, #describe, #export, #parse, #portable?, #refine, #safe_parse, #to_node, type_name, #with_metadata
Constructor Details
#initialize(constraints: {}, **kwargs) ⇒ StringSchema
Returns a new instance of StringSchema.
5
6
7
|
# File 'lib/anyvali/schemas/string_schema.rb', line 5
def initialize(constraints: {}, **kwargs)
super(kind: "string", constraints: constraints, **kwargs)
end
|
Instance Method Details
#ends_with(suffix) ⇒ Object
26
27
28
|
# File 'lib/anyvali/schemas/string_schema.rb', line 26
def ends_with(suffix)
dup_with(constraints: @constraints.merge("endsWith" => suffix))
end
|
34
35
36
|
# File 'lib/anyvali/schemas/string_schema.rb', line 34
def format(fmt)
dup_with(constraints: @constraints.merge("format" => fmt))
end
|
#includes(substr) ⇒ Object
30
31
32
|
# File 'lib/anyvali/schemas/string_schema.rb', line 30
def includes(substr)
dup_with(constraints: @constraints.merge("includes" => substr))
end
|
#max_length(n) ⇒ Object
13
14
15
|
# File 'lib/anyvali/schemas/string_schema.rb', line 13
def max_length(n)
dup_with(constraints: @constraints.merge("maxLength" => n))
end
|
#min_length(n) ⇒ Object
9
10
11
|
# File 'lib/anyvali/schemas/string_schema.rb', line 9
def min_length(n)
dup_with(constraints: @constraints.merge("minLength" => n))
end
|
#pattern(re) ⇒ Object
17
18
19
20
|
# File 'lib/anyvali/schemas/string_schema.rb', line 17
def pattern(re)
pat = re.is_a?(Regexp) ? re.source : re
dup_with(constraints: @constraints.merge("pattern" => pat))
end
|
#starts_with(prefix) ⇒ Object
22
23
24
|
# File 'lib/anyvali/schemas/string_schema.rb', line 22
def starts_with(prefix)
dup_with(constraints: @constraints.merge("startsWith" => prefix))
end
|