Class: Eatr::Schema

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

Defined Under Namespace

Classes: Field

Instance Method Summary collapse

Constructor Details

#initialize(schema_hash) ⇒ Schema

Returns a new instance of Schema.



42
43
44
# File 'lib/eatr/schema.rb', line 42

def initialize(schema_hash)
  @schema = schema_hash
end

Instance Method Details

#fieldsObject



46
47
48
# File 'lib/eatr/schema.rb', line 46

def fields
  @fields ||= @schema.fetch('fields').map { |f| Field.new(f) }
end

#flat_fieldsObject



50
51
52
53
# File 'lib/eatr/schema.rb', line 50

def flat_fields
  @flat_fields ||= fields.select(&:name).
    concat(fields.flat_map(&:children))
end

#nameObject



55
56
57
# File 'lib/eatr/schema.rb', line 55

def name
  @schema.fetch('name', 'schema')
end

#remove_namespaces?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/eatr/schema.rb', line 63

def remove_namespaces?
  @schema.fetch('remove_namespaces', false)
end

#table_nameObject



59
60
61
# File 'lib/eatr/schema.rb', line 59

def table_name
  @schema.fetch('table_name', name)
end

#to_structObject



67
68
69
70
71
72
73
# File 'lib/eatr/schema.rb', line 67

def to_struct
  @struct_klass ||= begin
                      Object.const_get("Struct::#{constant_name}", false)
                    rescue NameError
                      Struct.new(constant_name, *field_names)
                    end
end

#transformation_pipelineObject



75
76
77
# File 'lib/eatr/schema.rb', line 75

def transformation_pipeline
  Pipeline.new(TransformationSet.new(@schema.fetch('transformations', [])))
end