Class: DistritoTracking::Schema

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

Constant Summary collapse

DEFAULT_SCHEMA =
{
  appName: String,
  event: {
    name: String,
    type: String
  },
  feature: {
    name: String
  },
  time: Time
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchema

Returns a new instance of Schema.



21
22
23
# File 'lib/distrito_tracking/schema.rb', line 21

def initialize
  @errors = {}
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
end

Instance Method Details

#inspectObject



33
34
35
# File 'lib/distrito_tracking/schema.rb', line 33

def inspect
  "#<DistritoTracking::Schema>"
end

#validate(data:) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/distrito_tracking/schema.rb', line 25

def validate(data:)
  errors[:data] = "Data provided is invalid" if data.empty? || !data.is_a?(Hash)

  iterate(data, DEFAULT_SCHEMA)

  @errors.empty?
end