Class: StructuredDataToSql::Json::Shredder
- Inherits:
-
Object
- Object
- StructuredDataToSql::Json::Shredder
- Defined in:
- lib/structured_data_to_sql/json/shredder.rb
Overview
Turns one JSON record into a tree of ShreddedRows following the convention-based rules: nested objects flatten into prefixed columns, arrays become child tables, GraphQL edges/node wrappers unwrap, and anything too deep or irregular falls back to a *_json text column.
Instance Attribute Summary collapse
-
#json_fallbacks ⇒ Object
readonly
Returns the value of attribute json_fallbacks.
Instance Method Summary collapse
-
#initialize(registry:, max_depth: 5, graphql_unwrap: true, json_column_paths: nil, forced_json_paths: nil) ⇒ Shredder
constructor
A new instance of Shredder.
- #shred(record, ordinal) ⇒ Object
Constructor Details
#initialize(registry:, max_depth: 5, graphql_unwrap: true, json_column_paths: nil, forced_json_paths: nil) ⇒ Shredder
Returns a new instance of Shredder.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/structured_data_to_sql/json/shredder.rb', line 98 def initialize( registry:, max_depth: 5, graphql_unwrap: true, json_column_paths: nil, forced_json_paths: nil ) @registry = registry @max_depth = max_depth @graphql_unwrap = graphql_unwrap @json_column_paths = (json_column_paths || []).to_set @forced_json_paths = forced_json_paths || Set.new @json_fallbacks = 0 end |
Instance Attribute Details
#json_fallbacks ⇒ Object (readonly)
Returns the value of attribute json_fallbacks.
113 114 115 |
# File 'lib/structured_data_to_sql/json/shredder.rb', line 113 def json_fallbacks @json_fallbacks end |
Instance Method Details
#shred(record, ordinal) ⇒ Object
115 116 117 |
# File 'lib/structured_data_to_sql/json/shredder.rb', line 115 def shred(record, ordinal) build_row("", record, ordinal, nil) end |