lib/modaldiagrams/modaldiagrams.rb in modaldiagrams-1.1.1 vs lib/modaldiagrams/modaldiagrams.rb in modaldiagrams-1.1.2

- old
+ new

@@ -4,24 +4,10 @@ require 'modalsettings' require 'modalsupport' module ModalDiagrams - # Field type abbreviations - TYPE = { - :date=>'d', - :datetime=>'dt', - :timestamp=>'ts', - :boolean=>'b', - :integer=>'i', - :string=>'s', - :text=>'tx', - :float=>'f', - :decimal=>'d', - :geometry=>'g' - } - class <<self def enable_clusters if defined?(::Rails) ::ActiveRecord::Base.class_eval do @@ -55,11 +41,11 @@ models = dbmodels(model_selection_options.merge(:exclude_sti_models => true)) models.each do |cls| if cls.respond_to?(:reflect_on_all_associations) && ActiveRecord::Base.connection.table_exists?(cls.table_name) # Note: Don't use content_columns ignores columns ending with _id which I use for enum fields - columns = cls.columns.reject { |c| c.primary || c.name =~ /(_count)$/ || c.name == cls.inheritance_column || c.name =~ /^(created_at|updated_at)$/ }.map{|c| "#{c.name} : #{TYPE[c.type]}"} + columns = cls.columns.reject { |c| c.primary || c.name =~ /(_count)$/ || c.name == cls.inheritance_column || c.name =~ /^(created_at|updated_at)$/ }.map{|c| field_spec(cfg, c)} columns_to_ignore = cls.reflect_on_all_associations.map{|a| cols = [] if a.macro == :belongs_to cols << assoc_foreign_key(a) cols << assoc_foreign_type(a) if a.options[:polymorphic] @@ -160,11 +146,11 @@ cluster = cls.cluster.to_s else cluster = "" end if cfg.sti_fields && sti_class.respond_to?(:fields_info) && sti_class.fields_info!=:omitted - columns = sti_class.fields_info.map{|c| "#{c.name} : #{TYPE[c.type]}"} + columns = sti_class.fields_info.map{|c| field_spec(cfg, c)} columns = columns.to(cfg.max_attributes) + ['...'] if columns.size > cfg.max_attributes else columns = nil end classes[cluster] ||= [] @@ -326,9 +312,14 @@ end end def add_diagram_footer(f) f.puts "}\n" + end + + def field_spec(cfg, c) + type = cfg.type_abbreviations[c.type] || c.type + "#{c.name} : #{type}" end end end