Module: StrongJSON::Types
- Included in:
- StrongJSON
- Defined in:
- lib/strong_json/types.rb
Instance Method Summary collapse
- #any ⇒ Object
- #any? ⇒ Boolean
- #array(type = any) ⇒ Object
- #array?(ty) ⇒ Boolean
- #boolean ⇒ Object
- #boolean? ⇒ Boolean
- #enum(*types, detector: nil) ⇒ Object
- #enum?(*types, detector: nil) ⇒ Boolean
- #hash(type) ⇒ Object
- #hash?(type) ⇒ Boolean
- #integer ⇒ Object
- #integer? ⇒ Boolean
- #literal(value) ⇒ Object
- #literal?(value) ⇒ Boolean
- #number ⇒ Object
- #number? ⇒ Boolean
- #numeric ⇒ Object
- #numeric? ⇒ Boolean
- #object(fields = {}) ⇒ Object
- #object?(fields = {}) ⇒ Boolean
- #optional(type = any) ⇒ Object
- #string ⇒ Object
- #string? ⇒ Boolean
- #symbol ⇒ Object
- #symbol? ⇒ Boolean
Instance Method Details
#any ⇒ Object
39 40 41 |
# File 'lib/strong_json/types.rb', line 39 def any StrongJSON::Type::Base.new(:any) end |
#any? ⇒ Boolean
43 44 45 |
# File 'lib/strong_json/types.rb', line 43 def any? optional(any) end |
#array(type = any) ⇒ Object
11 12 13 |
# File 'lib/strong_json/types.rb', line 11 def array(type = any) Type::Array.new(type) end |
#array?(ty) ⇒ Boolean
83 84 85 |
# File 'lib/strong_json/types.rb', line 83 def array?(ty) optional(array(ty)) end |
#boolean ⇒ Object
35 36 37 |
# File 'lib/strong_json/types.rb', line 35 def boolean StrongJSON::Type::Base.new(:boolean) end |
#boolean? ⇒ Boolean
75 76 77 |
# File 'lib/strong_json/types.rb', line 75 def boolean? optional(boolean) end |
#enum(*types, detector: nil) ⇒ Object
55 56 57 |
# File 'lib/strong_json/types.rb', line 55 def enum(*types, detector: nil) StrongJSON::Type::Enum.new(types, detector) end |
#enum?(*types, detector: nil) ⇒ Boolean
95 96 97 |
# File 'lib/strong_json/types.rb', line 95 def enum?(*types, detector: nil) optional(enum(*types, detector: detector)) end |
#hash(type) ⇒ Object
99 100 101 |
# File 'lib/strong_json/types.rb', line 99 def hash(type) StrongJSON::Type::Hash.new(type) end |
#hash?(type) ⇒ Boolean
103 104 105 |
# File 'lib/strong_json/types.rb', line 103 def hash?(type) optional(hash(type)) end |
#integer ⇒ Object
31 32 33 |
# File 'lib/strong_json/types.rb', line 31 def integer StrongJSON::Type::Base.new(:integer) end |
#integer? ⇒ Boolean
67 68 69 |
# File 'lib/strong_json/types.rb', line 67 def integer? optional(integer) end |
#literal(value) ⇒ Object
51 52 53 |
# File 'lib/strong_json/types.rb', line 51 def literal(value) StrongJSON::Type::Literal.new(value) end |
#literal?(value) ⇒ Boolean
91 92 93 |
# File 'lib/strong_json/types.rb', line 91 def literal?(value) optional(literal(value)) end |
#number ⇒ Object
27 28 29 |
# File 'lib/strong_json/types.rb', line 27 def number StrongJSON::Type::Base.new(:number) end |
#number? ⇒ Boolean
71 72 73 |
# File 'lib/strong_json/types.rb', line 71 def number? optional(number) end |
#numeric ⇒ Object
23 24 25 |
# File 'lib/strong_json/types.rb', line 23 def numeric StrongJSON::Type::Base.new(:numeric) end |
#numeric? ⇒ Boolean
63 64 65 |
# File 'lib/strong_json/types.rb', line 63 def numeric? optional(numeric) end |
#object(fields = {}) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/strong_json/types.rb', line 3 def object(fields = {}) if fields.empty? Type::Object.new(fields, on_unknown: :ignore, exceptions: Set.new) else Type::Object.new(fields, on_unknown: :reject, exceptions: Set.new) end end |
#object?(fields = {}) ⇒ Boolean
87 88 89 |
# File 'lib/strong_json/types.rb', line 87 def object?(fields={}) optional(object(fields)) end |
#optional(type = any) ⇒ Object
15 16 17 |
# File 'lib/strong_json/types.rb', line 15 def optional(type = any) Type::Optional.new(type) end |
#string ⇒ Object
19 20 21 |
# File 'lib/strong_json/types.rb', line 19 def string StrongJSON::Type::Base.new(:string) end |
#string? ⇒ Boolean
59 60 61 |
# File 'lib/strong_json/types.rb', line 59 def string? optional(string) end |
#symbol ⇒ Object
47 48 49 |
# File 'lib/strong_json/types.rb', line 47 def symbol StrongJSON::Type::Base.new(:symbol) end |
#symbol? ⇒ Boolean
79 80 81 |
# File 'lib/strong_json/types.rb', line 79 def symbol? optional(symbol) end |