Module: StrongJSON::Types

Included in:
StrongJSON
Defined in:
lib/strong_json/types.rb

Instance Method Summary collapse

Instance Method Details

#anyObject



31
32
33
# File 'lib/strong_json/types.rb', line 31

def any
  StrongJSON::Type::Base.new(:any)
end

#any?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/strong_json/types.rb', line 35

def any?
  optional(any)
end

#array(type = any) ⇒ Object



7
8
9
# File 'lib/strong_json/types.rb', line 7

def array(type = any)
  Type::Array.new(type)
end

#array?(ty) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/strong_json/types.rb', line 79

def array?(ty)
  optional(array(ty))
end

#booleanObject



27
28
29
# File 'lib/strong_json/types.rb', line 27

def boolean
  StrongJSON::Type::Base.new(:boolean)
end

#boolean?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/strong_json/types.rb', line 67

def boolean?
  optional(boolean)
end

#enum(*types) ⇒ Object



51
52
53
# File 'lib/strong_json/types.rb', line 51

def enum(*types)
  StrongJSON::Type::Enum.new(types)
end

#ignoredObject



75
76
77
# File 'lib/strong_json/types.rb', line 75

def ignored
  StrongJSON::Type::Base.new(:ignored)
end

#literal(value) ⇒ Object



47
48
49
# File 'lib/strong_json/types.rb', line 47

def literal(value)
  StrongJSON::Type::Literal.new(value)
end

#literal?(value) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/strong_json/types.rb', line 87

def literal?(value)
  optional(literal(value))
end

#numberObject



23
24
25
# File 'lib/strong_json/types.rb', line 23

def number
  StrongJSON::Type::Base.new(:number)
end

#number?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/strong_json/types.rb', line 63

def number?
  optional(number)
end

#numericObject



19
20
21
# File 'lib/strong_json/types.rb', line 19

def numeric
  StrongJSON::Type::Base.new(:numeric)
end

#numeric?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/strong_json/types.rb', line 59

def numeric?
  optional(numeric)
end

#object(fields = {}) ⇒ Object



3
4
5
# File 'lib/strong_json/types.rb', line 3

def object(fields = {})
  Type::Object.new(fields)
end

#object?(fields) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/strong_json/types.rb', line 83

def object?(fields)
  optional(object(fields))
end

#optional(type = any) ⇒ Object



11
12
13
# File 'lib/strong_json/types.rb', line 11

def optional(type = any)
  Type::Optional.new(type)
end

#prohibitedObject



39
40
41
# File 'lib/strong_json/types.rb', line 39

def prohibited
  StrongJSON::Type::Base.new(:prohibited)
end

#stringObject



15
16
17
# File 'lib/strong_json/types.rb', line 15

def string
  StrongJSON::Type::Base.new(:string)
end

#string?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/strong_json/types.rb', line 55

def string?
  optional(string)
end

#symbolObject



43
44
45
# File 'lib/strong_json/types.rb', line 43

def symbol
  StrongJSON::Type::Base.new(:symbol)
end

#symbol?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/strong_json/types.rb', line 71

def symbol?
  optional(symbol)
end