Module: StrongJSON::Types

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

Instance Method Summary collapse

Instance Method Details

#anyObject



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

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

#any?Boolean

Returns:

  • (Boolean)


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

def any?
  optional(any)
end

#array(type = any) ⇒ Object



9
10
11
# File 'lib/strong_json/types.rb', line 9

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

#array?(ty) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#booleanObject



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

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

#boolean?Boolean

Returns:

  • (Boolean)


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

def boolean?
  optional(boolean)
end

#enum(*types) ⇒ Object



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

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

#enum?(*types) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/strong_json/types.rb', line 94

def enum?(*types)
  optional(enum(*types))
end

#ignoredObject



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

def ignored
  StrongJSON::Type::Base.new(:ignored)
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

Returns:

  • (Boolean)


90
91
92
# File 'lib/strong_json/types.rb', line 90

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

#numberObject



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

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

#number?Boolean

Returns:

  • (Boolean)


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

def number?
  optional(number)
end

#numericObject



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

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

#numeric?Boolean

Returns:

  • (Boolean)


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

def numeric?
  optional(numeric)
end

#object(fields = {}) ⇒ Object



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

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

#object?(fields) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#optional(type = any) ⇒ Object



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

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

#prohibitedObject



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

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

#stringObject



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

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

#string?Boolean

Returns:

  • (Boolean)


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

def string?
  optional(string)
end

#symbolObject



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

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

#symbol?Boolean

Returns:

  • (Boolean)


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

def symbol?
  optional(symbol)
end