class Eatr::Schema
Public Class Methods
new(schema_hash)
click to toggle source
# File lib/eatr/schema.rb, line 46 def initialize(schema_hash) @schema = schema_hash end
Public Instance Methods
fields()
click to toggle source
# File lib/eatr/schema.rb, line 50 def fields @fields ||= @schema.fetch('fields').map { |f| Field.new(f) } end
flat_fields()
click to toggle source
# File lib/eatr/schema.rb, line 54 def flat_fields @flat_fields ||= fields.select(&:name). concat(fields.flat_map(&:children)) end
name()
click to toggle source
# File lib/eatr/schema.rb, line 59 def name @schema.fetch('name', 'schema') end
remove_namespaces?()
click to toggle source
# File lib/eatr/schema.rb, line 67 def remove_namespaces? @schema.fetch('remove_namespaces', false) end
table_name()
click to toggle source
# File lib/eatr/schema.rb, line 63 def table_name @schema.fetch('table_name', name) end
to_struct()
click to toggle source
# File lib/eatr/schema.rb, line 71 def to_struct @struct_klass ||= begin Object.const_get("Struct::#{constant_name}", false) rescue NameError Struct.new(constant_name, *field_names) end end
transformation_pipeline()
click to toggle source
# File lib/eatr/schema.rb, line 79 def transformation_pipeline Pipeline.new(TransformationSet.new(@schema.fetch('transformations', []))) end
Private Instance Methods
constant_name()
click to toggle source
# File lib/eatr/schema.rb, line 85 def constant_name constantize(name) end
constantize(underscore_name)
click to toggle source
# File lib/eatr/schema.rb, line 93 def constantize(underscore_name) underscore_name.split('_').map(&:capitalize).join end
field_names()
click to toggle source
# File lib/eatr/schema.rb, line 89 def field_names flat_fields.map { |f| f.name.to_sym } end