Class: TableSchema::Types::Object

Inherits:
Base
  • Object
show all
Defined in:
lib/tableschema/types/object.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cast, #initialize, #test

Methods included from Helpers

#deep_symbolize_keys, #get_class_for_type, #read_file, #type_class_lookup

Constructor Details

This class inherits a constructor from TableSchema::Types::Base

Class Method Details

.supported_constraintsObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/tableschema/types/object.rb', line 9

def self.supported_constraints
  [
    'required',
    'unique',
    'pattern',
    'enum',
    'minLength',
    'maxLength',
  ]
end

Instance Method Details

#cast_default(value) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tableschema/types/object.rb', line 24

def cast_default(value)
  return value if value.is_a?(type)
  parsed = JSON.parse(value, symbolize_names: true)
  if parsed.is_a?(Hash)
    return parsed
  else
    raise TableSchema::InvalidObjectType.new("#{value} is not a valid object")
  end
rescue
  raise TableSchema::InvalidObjectType.new("#{value} is not a valid object")
end

#nameObject



5
6
7
# File 'lib/tableschema/types/object.rb', line 5

def name
  'object'
end

#typeObject



20
21
22
# File 'lib/tableschema/types/object.rb', line 20

def type
  ::Hash
end