diff --git a/lib/rails_erd.rb b/lib/rails_erd.rb index eadfc409..fff7318a 100644 --- a/lib/rails_erd.rb +++ b/lib/rails_erd.rb @@ -55,6 +55,8 @@ def default_options :only_recursion_depth, nil, :prepend_primary, false, :cluster, false, + :table_names, false, + :native_types, false ] end diff --git a/lib/rails_erd/cli.rb b/lib/rails_erd/cli.rb index 9566d1bd..ea3cb539 100644 --- a/lib/rails_erd/cli.rb +++ b/lib/rails_erd/cli.rb @@ -80,6 +80,16 @@ desc "Control how edges are represented. See http://www.graphviz.org/doc/info/attrs.html#d:splines for values." end + option :table_names do + long "--table_names=BOOLEAN" + desc "Label each entity with the table name instead of the ActiveRecord class name." + end + + option :native_types do + long "--native_types=BOOLEAN" + desc "Display the db-native types instead of the Rails migration ones." + end + separator "" separator "Output options:" diff --git a/lib/rails_erd/diagram/templates/node.html.erb b/lib/rails_erd/diagram/templates/node.html.erb index de637640..980d3c71 100644 --- a/lib/rails_erd/diagram/templates/node.html.erb +++ b/lib/rails_erd/diagram/templates/node.html.erb @@ -1,6 +1,6 @@ <% if options.orientation == :horizontal %>{<% end %> - +
<%= entity.name %>
<%= entity.label %>
<% if attributes.any? %> | diff --git a/lib/rails_erd/diagram/templates/node.record.erb b/lib/rails_erd/diagram/templates/node.record.erb index 2d9f69d6..367f7f03 100644 --- a/lib/rails_erd/diagram/templates/node.record.erb +++ b/lib/rails_erd/diagram/templates/node.record.erb @@ -1,4 +1,4 @@ -<% if options.orientation == :horizontal %>{<% end %><%= entity.name %><% if attributes.any? %> +<% if options.orientation == :horizontal %>{<% end %><%= entity.label %><% if attributes.any? %> |<% attributes.each do |attribute| %><%= attribute %> (<%= attribute.type_description %>) -<% end %><% end %><% if options.orientation == :horizontal %>}<% end %> \ No newline at end of file +<% end %><% end %><% if options.orientation == :horizontal %>}<% end %> diff --git a/lib/rails_erd/domain/attribute.rb b/lib/rails_erd/domain/attribute.rb index ac02dae3..b0b83e17 100644 --- a/lib/rails_erd/domain/attribute.rb +++ b/lib/rails_erd/domain/attribute.rb @@ -49,7 +49,7 @@ def name # The type of the attribute, equal to the Rails migration type. Can be any # of +:string+, +:integer+, +:boolean+, +:text+, etc. def type - column.type or column.sql_type.downcase.to_sym + !RailsERD.options[:native_types] and column.type or column.sql_type.downcase.to_sym end # Returns +true+ if this attribute is a content column, that is, if it @@ -120,6 +120,7 @@ def to_s # @private :nodoc: # :boolean, :null => false:: boolean * def type_description type.to_s.dup.tap do |desc| + desc << "[]" if column.array? desc << " #{limit_description}" if limit_description desc << " ∗" if mandatory? && !primary_key? # Add a hair space + low asterisk (Unicode characters) desc << " U" if unique? && !primary_key? && !foreign_key? # Add U if unique but non-key diff --git a/lib/rails_erd/domain/entity.rb b/lib/rails_erd/domain/entity.rb index 853218fb..fbd07a0e 100644 --- a/lib/rails_erd/domain/entity.rb +++ b/lib/rails_erd/domain/entity.rb @@ -38,6 +38,10 @@ def initialize(domain, name, model = nil) # @private :nodoc: @domain, @name, @model = domain, name, model end + def label + RailsERD.options[:table_names] ? model.table_name : name + end + # Returns an array of attributes for this entity. def attributes @attributes ||= generalized? ? [] : Attribute.from_model(domain, model)