Skip to content

Commit

Permalink
fix: annotating nested models & virtual models (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
swiknaba authored Sep 23, 2024
1 parent 273313c commit 3beaf3e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/cli/commands/new_app/files/db_rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def self.content(app_name, db_name)
modules = model_file.gsub("app/models/", "").gsub(".rb", "").split("/").map { |mod| Zeitwerk::Inflector.new.camelize(mod, model_path) }
const_name = modules.join("::")
model_klass = Object.const_get(const_name)
next unless model_klass.ancestors.include?(Kirei::Model)
table_name = model_klass.table_name
schema = db.schema(table_name)
Expand All @@ -183,7 +185,7 @@ def self.content(app_name, db_name)
file_contents = File.read(model_path)
# Remove existing schema info comments if present
updated_contents = file_contents.sub(/# == Schema Info\\n(.*?)(\\n#\\n)?\\n(?=\\s*class)/m, "")
updated_contents = file_contents.sub(/# == Schema Info\\n(.*?)(\\n#\\n)?\\n(?=\\s*(?:class|module))/m, "")
# Insert the new schema comments before the module/class definition
first_const = modules.first
Expand Down

0 comments on commit 3beaf3e

Please sign in to comment.