Skip to content

Instantly share code, notes, and snippets.

@CroneKorkN
Last active December 15, 2018 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CroneKorkN/37a3b78405ff74bfe9399ec263b8939b to your computer and use it in GitHub Desktop.
Save CroneKorkN/37a3b78405ff74bfe9399ec263b8939b to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
integer_attributes = ["order", "progress"]
require "nokogiri"
x = Nokogiri::XML File.read "swift3_db.xml"
referencing = x.xpath("//mxCell").find_all{|e| e["source"]}.collect{|e| e["source"]}
p referencing.sort
result = {}
x.xpath("//mxCell").find_all{|e| e["parent"] == "1" && !e["target"]}.each do |model|
next if model["value"] =~ /\</
model["value"]
result[model["value"]] = x.xpath("//mxCell").find_all{|attr|
attr["parent"] == model["id"] and not (
attr["source"] or
attr["value"] =~ /\</ or
attr["value"].chomp == "id"
)
}.collect{|attr|
attr["value"].chomp + if referencing.include? attr["id"]
if referencing.find_all{|r| r == attr["id"]}.length > 1
":references{polymorphic}"
else
":references"
end
elsif integer_attributes.include? attr["value"]
":integer"
else
":string"
end
}
end
result.each do |name, attributes|
puts "rails g scaffold #{name.ljust(result.keys.sort_by(&:length).last.length, " ")} #{attributes.join(" ")}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment