lib/rails_erd/domain/attribute.rb in rails-erd-0.4.5 vs lib/rails_erd/domain/attribute.rb in rails-erd-1.0.0
- old
+ new
@@ -29,11 +29,11 @@
end
# The type of the attribute, equal to the Rails migration type. Can be any
# of +:string+, +:integer+, +:boolean+, +:text+, etc.
def type
- column.type
+ column.type or column.sql_type.downcase.to_sym
end
# Returns +true+ if this attribute is a content column, that is, if it
# is not a primary key, foreign key, timestamp, or inheritance column.
def content?
@@ -98,23 +98,29 @@
end
# Returns any non-standard limit for this attribute. If a column has no
# limit or uses a default database limit, this method returns +nil+.
def limit
- column.limit if column.limit != @model.connection.native_database_types[type][:limit]
+ column.limit.to_i if column.limit != native_type[:limit] and column.limit.respond_to?(:to_i)
end
# Returns any non-standard scale for this attribute (decimal types only).
def scale
- column.scale if column.scale != @model.connection.native_database_types[type][:scale]
+ column.scale.to_i if column.scale != native_type[:scale] and column.scale.respond_to?(:to_i)
end
# Returns a string that describes the limit for this attribute, such as
# +(128)+, or +(5,2)+ for decimal types. Returns nil if no non-standard
# limit was set.
def limit_description # @private :nodoc:
return "(#{limit},#{scale})" if limit and scale
return "(#{limit})" if limit
+ end
+
+ private
+
+ def native_type
+ @model.connection.native_database_types[type] or {}
end
end
end
end