lib/ymldot.rb in ymldot-0.0.3 vs lib/ymldot.rb in ymldot-0.0.4
- old
+ new
@@ -122,11 +122,13 @@
res
end
def config_to_dot
res = ""
- res << "graph[overlap=false, splines=true]\n"
+ res << "graph [overlap=false, splines=true]\n"
+ res << %Q!graph [size="#{@config["size"]["x"]/2.54},#{@config["size"]["y"]/2.54}"]\n! if @config["size"] && @config["size"]["x"] && @config["size"]["y"]
+ raise "Error: please seto 'font'" if @config["ja"] && @config["font"]
res << %Q!node [fontname="#{@config["font"]}"]! if @config["font"]
res
end
def entity_to_dot
@@ -175,48 +177,58 @@
end
def eval_relation_has_many(keys, tname)
keys.each do |rel|
raise "Error Relation! has many #{tname} to #{rel}" if @entity_dict[rel] == nil
- @entity_dict[rel].foreignkeys << "#{singularize(tname)}ID(FK)"
+ @entity_dict[rel].foreignkeys << append_fk_str(singularize(tname))
@many_relations << {:self => @entity_dict[tname], :have => @entity_dict[rel]}
end
end
def eval_relation_has_one(keys, tname)
keys.each do |rel|
raise "Error Relation! has one #{tname} to #{rel}" if @entity_dict[rel] == nil
- @entity_dict[rel].foreignkeys << "#{singularize(tname)}ID(FK)"
+ @entity_dict[rel].foreignkeys << append_fk_str(singularize(tname))
@one_relations << {:self => @entity_dict[tname], :have => @entity_dict[rel]}
end
end
def eval_relation_hmabt(keys, tname)
keys.each do |rel|
join_tname = "#{rel}_#{tname}"
return if @entity_dict.has_key? join_tname
join_tname = "#{tname}_#{rel}"
@entity_dict[join_tname] ||= Entity.new(join_tname, true)
- @entity_dict[join_tname].foreignkeys << "#{singularize(tname)}ID(FK)"
- @entity_dict[join_tname].foreignkeys << "#{singularize(rel)}ID(FK)"
+ @entity_dict[join_tname].foreignkeys << append_fk_str(singularize(tname))
+ @entity_dict[join_tname].foreignkeys << append_fk_str(singularize(rel))
# make new category
keys = []
- keys << "#{tname}ID(FK)"
- keys << "#{rel}ID(FK)"
+ keys << append_fk_str(tname)
+ keys << append_fk_str(rel)
@category << Tables.new([{"name" => join_tname, "columns" => keys}])
@many_relations << {:self => @entity_dict[tname], :have => @entity_dict[join_tname]}
@many_relations << {:self => @entity_dict[rel], :have => @entity_dict[join_tname]}
end
end
def eval_relation_polymorphic(keys, tname)
keys.each do |rel|
- @entity_dict[tname].foreignkeys << "#{singularize(rel["name"])}ID(FK)" if key = rel["name"]
+ @entity_dict[tname].foreignkeys << append_fk_str(singularize(rel["name"])) if key = rel["name"]
@entity_dict[tname].columns.unshift "#{singularize(rel["type"])}(type)" if key = rel["type"]
rel["tables"].each do |t|
@one_relations << {:self => @entity_dict[t], :have => @entity_dict[tname] }
end
+ end
+ end
+
+ def append_fk_str(key)
+ @config["lang"] ||= "en"
+ case @config["lang"]
+ when "en"
+ return "#{key}_id(FK)"
+ when "ja"
+ return "#{key}ID(FK)"
end
end
end