Class: TableSync::Utils::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/table_sync/utils/schema.rb,
lib/table_sync/utils/schema/validator.rb,
lib/table_sync/utils/schema/builder/sequel.rb,
lib/table_sync/utils/schema/validator/type.rb,
lib/table_sync/utils/schema/builder/active_record.rb

Defined Under Namespace

Modules: Builder Classes: Validator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Schema

Returns a new instance of Schema.



10
11
12
# File 'lib/table_sync/utils/schema.rb', line 10

def initialize(schema)
  @schema = schema
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



8
9
10
# File 'lib/table_sync/utils/schema.rb', line 8

def schema
  @schema
end

Instance Method Details

#validate(data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/table_sync/utils/schema.rb', line 14

def validate(data)
  errors = nil
  data.each do |row|
    schema.each do |key, value|
      if (error = value.validate(row[key]))
        errors ||= {}
        errors[key] = error
      end
    end

    return errors.freeze unless errors.nil?
  end
  errors
end