Class: Eatr::Schema
- Inherits:
-
Object
- Object
- Eatr::Schema
- Defined in:
- lib/eatr/schema.rb
Defined Under Namespace
Classes: Field
Instance Method Summary collapse
- #fields ⇒ Object
- #flat_fields ⇒ Object
-
#initialize(schema_hash) ⇒ Schema
constructor
A new instance of Schema.
- #name ⇒ Object
- #remove_namespaces? ⇒ Boolean
- #table_name ⇒ Object
- #to_struct ⇒ Object
- #transformation_pipeline ⇒ Object
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
#fields ⇒ Object
46 47 48 |
# File 'lib/eatr/schema.rb', line 46 def fields @fields ||= @schema.fetch('fields').map { |f| Field.new(f) } end |
#flat_fields ⇒ Object
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 |
#name ⇒ Object
55 56 57 |
# File 'lib/eatr/schema.rb', line 55 def name @schema.fetch('name', 'schema') end |
#remove_namespaces? ⇒ Boolean
63 64 65 |
# File 'lib/eatr/schema.rb', line 63 def remove_namespaces? @schema.fetch('remove_namespaces', false) end |
#table_name ⇒ Object
59 60 61 |
# File 'lib/eatr/schema.rb', line 59 def table_name @schema.fetch('table_name', name) end |
#to_struct ⇒ Object
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_pipeline ⇒ Object
75 76 77 |
# File 'lib/eatr/schema.rb', line 75 def transformation_pipeline Pipeline.new(TransformationSet.new(@schema.fetch('transformations', []))) end |