Class: SchemaToDbml
- Inherits:
-
Object
- Object
- SchemaToDbml
- Defined in:
- lib/schema_to_dbml.rb,
lib/schema_to_dbml/version.rb
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
File.join(__dir__, 'schema_to_dbml/configs/custom_config.yml')
- VERSION =
'0.0.7'
Class Method Summary collapse
- .configuration ⇒ Object
- .load_configuration_from_yaml(file_path: DEFAULT_CONFIG_FILE) ⇒ Object
- .merge_with_defaults(file_path, yaml_data) ⇒ Object
Instance Method Summary collapse
- #convert(schema:) ⇒ Object
- #generate(schema:) ⇒ Object
-
#initialize(build_dbml_content: BuildDbmlContent.new, schema_converter: SchemaConverter.new) ⇒ SchemaToDbml
constructor
A new instance of SchemaToDbml.
Constructor Details
#initialize(build_dbml_content: BuildDbmlContent.new, schema_converter: SchemaConverter.new) ⇒ SchemaToDbml
Returns a new instance of SchemaToDbml.
39 40 41 42 43 44 45 |
# File 'lib/schema_to_dbml.rb', line 39 def initialize( build_dbml_content: BuildDbmlContent.new, schema_converter: SchemaConverter.new ) @build_dbml_content = build_dbml_content @schema_converter = schema_converter end |
Class Method Details
.configuration ⇒ Object
17 18 19 |
# File 'lib/schema_to_dbml.rb', line 17 def configuration @configuration ||= Configuration.new end |
.load_configuration_from_yaml(file_path: DEFAULT_CONFIG_FILE) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/schema_to_dbml.rb', line 21 def load_configuration_from_yaml(file_path: DEFAULT_CONFIG_FILE) raise Errors::ConfigurationFileNotFoundError unless File.exist?(file_path) yaml_data = YAML.load_file(file_path) yaml_data = merge_with_defaults(file_path, yaml_data) configuration.configure_from_hash(yaml_data) end |
.merge_with_defaults(file_path, yaml_data) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/schema_to_dbml.rb', line 30 def merge_with_defaults(file_path, yaml_data) return yaml_data unless file_path != DEFAULT_CONFIG_FILE default_settings = YAML.load_file(DEFAULT_CONFIG_FILE) default_settings.deep_merge!(yaml_data) end |
Instance Method Details
#convert(schema:) ⇒ Object
53 54 55 56 57 |
# File 'lib/schema_to_dbml.rb', line 53 def convert(schema:) converted = schema_converter.convert(schema_content: schema_content(schema)) build_dbml_content.build(converted:) end |
#generate(schema:) ⇒ Object
47 48 49 50 51 |
# File 'lib/schema_to_dbml.rb', line 47 def generate(schema:) content = convert(schema:) File.write(self.class.configuration.custom_dbml_file_path, content) end |