Class: Migsupo::Loader::SchemaRbLoader
- Inherits:
-
Object
- Object
- Migsupo::Loader::SchemaRbLoader
- Defined in:
- lib/migsupo/loader/schema_rb_loader.rb
Overview
Loads the current schema state from db/schema.rb without a live DB connection. db/schema.rb uses the same create_table DSL as Schemafile, so we reuse DslContext.
Instance Method Summary collapse
-
#initialize(schema_rb_path:, ignored_tables: []) ⇒ SchemaRbLoader
constructor
A new instance of SchemaRbLoader.
- #load_schema ⇒ Object
Constructor Details
#initialize(schema_rb_path:, ignored_tables: []) ⇒ SchemaRbLoader
Returns a new instance of SchemaRbLoader.
8 9 10 11 |
# File 'lib/migsupo/loader/schema_rb_loader.rb', line 8 def initialize(schema_rb_path:, ignored_tables: []) @schema_rb_path = schema_rb_path @ignored_tables = ignored_tables end |
Instance Method Details
#load_schema ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/migsupo/loader/schema_rb_loader.rb', line 13 def load_schema source = File.read(@schema_rb_path) context = Parser::DslContext.new context.instance_eval(source, @schema_rb_path, 1) schema = context.to_schema_definition filtered_tables = schema.tables.reject { |name, _| @ignored_tables.include?(name) } Schema::SchemaDefinition.new(tables: filtered_tables) end |