Module: Typical::DSL

Extended by:
Define
Defined in:
lib/typical/dsl.rb

Defined Under Namespace

Modules: Define

Constant Summary collapse

BUILTIN_SCALAR_TYPES =
[
  Integer,
  Float,
  Object,
  Range,
  Regexp,
  String,
  Symbol,
  Time,
].freeze

Instance Method Summary collapse

Instance Method Details

#Array!(*types) ⇒ Object



50
51
52
# File 'lib/typical/dsl.rb', line 50

def Array!(*types)
  Type::Array.new(types)
end

#Array?(*types) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/typical/dsl.rb', line 54

def Array?(*types)
  Array!(*types) | null
end

#Hash!(types = {}) ⇒ Object



33
34
35
# File 'lib/typical/dsl.rb', line 33

def Hash!(types = {})
  Type::Hash.new(types)
end

#Hash?(types = {}) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/typical/dsl.rb', line 37

def Hash?(types = {})
  Hash!(types) | null
end

#nullObject



29
30
31
# File 'lib/typical/dsl.rb', line 29

def null
  Type.new(NilClass)
end

#Reference!(reference) ⇒ Object



58
59
60
# File 'lib/typical/dsl.rb', line 58

def Reference!(reference)
  Type::Reference.new(reference)
end

#Reference?(reference) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/typical/dsl.rb', line 62

def Reference?(reference)
  Reference!(reference) | null
end

#Set!(*types) ⇒ Object



41
42
43
# File 'lib/typical/dsl.rb', line 41

def Set!(*types)
  Type::Set.new(*types)
end

#Set?(*types) ⇒ Boolean

TODO: It actually appears that mongo/mongoid does not return ‘null` for set fields.

Returns:

  • (Boolean)


46
47
48
# File 'lib/typical/dsl.rb', line 46

def Set?(*types)
  Set!(*types) | null
end