Module: Spanner::Translator::Schema
- Defined in:
- lib/spanner/translator/schema.rb
Overview
Access a Rails formatted db/schema.rb file and return create_table source
Class Method Summary collapse
-
.extract_create_table(table_name) ⇒ Object
extract the Ruby
create_tablestatement for the given table name. -
.extract_create_table_ast(table_name) ⇒ Object
extract the Parser::AST for the given table name, see https://github.com/whitequark/parser/blob/master/doc/AST_FORMAT.md.
- .legacy_schema ⇒ Object
- .legacy_schema_path ⇒ Object
Class Method Details
.extract_create_table(table_name) ⇒ Object
extract the Ruby create_table statement for the given table name
22 23 24 |
# File 'lib/spanner/translator/schema.rb', line 22 def extract_create_table(table_name) legacy_schema.match(/create_table "#{table_name}".*?end$/m)[0] end |
.extract_create_table_ast(table_name) ⇒ Object
extract the Parser::AST for the given table name, see https://github.com/whitequark/parser/blob/master/doc/AST_FORMAT.md
28 29 30 31 |
# File 'lib/spanner/translator/schema.rb', line 28 def extract_create_table_ast(table_name) source = extract_create_table(table_name) RuboCop::AST::ProcessedSource.new(source, RUBY_VERSION.to_f).ast end |
.legacy_schema ⇒ Object
15 16 17 18 19 |
# File 'lib/spanner/translator/schema.rb', line 15 def legacy_schema raise Spanner::Translator::Error, "db/schema.rb not found" unless File.exist?(legacy_schema_path) @legacy_schema ||= File.read(legacy_schema_path) end |
.legacy_schema_path ⇒ Object
11 12 13 |
# File 'lib/spanner/translator/schema.rb', line 11 def legacy_schema_path Spanner::Translator.configuration.db_schema end |