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
- #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
38 39 40 |
# File 'lib/strong_json/types.rb', line 38 def any StrongJSON::Type::Base.new(:any) end |
#any? ⇒ Boolean
42 43 44 |
# File 'lib/strong_json/types.rb', line 42 def any? optional(any) end |
#array(type = any) ⇒ Object
13 14 15 |
# File 'lib/strong_json/types.rb', line 13 def array(type = any) Type::Array.new(type) end |
#array?(ty) ⇒ Boolean
78 79 80 |
# File 'lib/strong_json/types.rb', line 78 def array?(ty) optional(array(ty)) end |
#boolean ⇒ Object
34 35 36 |
# File 'lib/strong_json/types.rb', line 34 def boolean StrongJSON::Type::Base.new(:boolean) end |
#boolean? ⇒ Boolean
70 71 72 |
# File 'lib/strong_json/types.rb', line 70 def boolean? optional(boolean) end |
#enum(*types, detector: nil) ⇒ Object
54 55 56 |
# File 'lib/strong_json/types.rb', line 54 def enum(*types, detector: nil) StrongJSON::Type::Enum.new(types, detector) end |
#enum?(*types, detector: nil) ⇒ Boolean
91 92 93 |
# File 'lib/strong_json/types.rb', line 91 def enum?(*types, detector: nil) optional(enum(*types, detector: detector)) end |
#hash(type) ⇒ Object
95 96 97 |
# File 'lib/strong_json/types.rb', line 95 def hash(type) StrongJSON::Type::Hash.new(type) end |
#hash?(type) ⇒ Boolean
99 100 101 |
# File 'lib/strong_json/types.rb', line 99 def hash?(type) optional(hash(type)) end |
#literal(value) ⇒ Object
50 51 52 |
# File 'lib/strong_json/types.rb', line 50 def literal(value) StrongJSON::Type::Literal.new(value) end |
#literal?(value) ⇒ Boolean
87 88 89 |
# File 'lib/strong_json/types.rb', line 87 def literal?(value) optional(literal(value)) end |
#number ⇒ Object
30 31 32 |
# File 'lib/strong_json/types.rb', line 30 def number StrongJSON::Type::Base.new(:number) end |
#number? ⇒ Boolean
66 67 68 |
# File 'lib/strong_json/types.rb', line 66 def number? optional(number) end |
#numeric ⇒ Object
26 27 28 |
# File 'lib/strong_json/types.rb', line 26 def numeric StrongJSON::Type::Base.new(:numeric) end |
#numeric? ⇒ Boolean
62 63 64 |
# File 'lib/strong_json/types.rb', line 62 def numeric? optional(numeric) end |
#object(fields = {}) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/strong_json/types.rb', line 4 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
83 84 85 |
# File 'lib/strong_json/types.rb', line 83 def object?(fields={}) optional(object(fields)) end |
#optional(type = any) ⇒ Object
18 19 20 |
# File 'lib/strong_json/types.rb', line 18 def optional(type = any) Type::Optional.new(type) end |
#string ⇒ Object
22 23 24 |
# File 'lib/strong_json/types.rb', line 22 def string StrongJSON::Type::Base.new(:string) end |
#string? ⇒ Boolean
58 59 60 |
# File 'lib/strong_json/types.rb', line 58 def string? optional(string) end |
#symbol ⇒ Object
46 47 48 |
# File 'lib/strong_json/types.rb', line 46 def symbol StrongJSON::Type::Base.new(:symbol) end |
#symbol? ⇒ Boolean
74 75 76 |
# File 'lib/strong_json/types.rb', line 74 def symbol? optional(symbol) end |