Class: Schema

Inherits:
Struct
  • Object
show all
Defined in:
lib/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#streamObject

Returns the value of attribute stream

Returns:

  • (Object)

    the current value of stream



2
3
4
# File 'lib/schema.rb', line 2

def stream
  @stream
end

Instance Method Details

#datetime(name) ⇒ Object



11
12
13
14
15
16
# File 'lib/schema.rb', line 11

def datetime(name)
  properties[name.to_sym] = {
    type: [:string, :null],
    format: 'date-time'
  }
end

#propertiesObject



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

def properties
  @properties ||= {}
end

#string(name, options = {}) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/schema.rb', line 3

def string(name, options={})
  if options[:nil]
    properties[name.to_sym] = { type: [:string, :null] }
  else
    properties[name.to_sym] = { type: :string }
  end
end

#timestampsObject



18
19
20
21
# File 'lib/schema.rb', line 18

def timestamps
  datetime :created_at
  datetime :updated_at
end

#to_hashObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/schema.rb', line 27

def to_hash
  {
    type: :SCHEMA,
    stream: stream,
    key_properties: [:id],
    schema: {
      properties: properties
    }
  }
end