lib/rails_erd/relationship.rb in rails-erd-0.1.1 vs lib/rails_erd/relationship.rb in rails-erd-0.2.0

- old
+ new

@@ -3,11 +3,11 @@ # based on Active Record associations. One relationship may represent more # than one association, however. Associations that share the same foreign # key are grouped together. class Relationship class << self - def from_associations(domain, associations) #:nodoc: + def from_associations(domain, associations) # @private :nodoc: assoc_groups = associations.group_by { |assoc| association_identity(assoc) } assoc_groups.collect { |_, assoc_group| Relationship.new(domain, assoc_group.to_a) } end private @@ -27,11 +27,11 @@ # The destination entity. It corresponds to the model that has defined # a +belongs_to+ association with the other model. attr_reader :destination - def initialize(domain, associations) #:nodoc: + def initialize(domain, associations) # @private :nodoc: @domain = domain @reverse_associations, @forward_associations = *associations.partition(&:belongs_to?) assoc = @forward_associations.first || @reverse_associations.first @source, @destination = @domain.entity_for(assoc.active_record), @domain.entity_for(assoc.klass) @@ -54,11 +54,11 @@ # Indicates if a relationship is indirect, that is, if it is defined # through other relationships. Indirect relationships are created in # Rails with <tt>has_many :through</tt> or <tt>has_one :through</tt> # association macros. def indirect? - @forward_associations.all?(&:through_reflection) + !@forward_associations.empty? and @forward_associations.all?(&:through_reflection) end # Indicates whether or not the relationship is defined by two inverse # associations (e.g. a +has_many+ and a corresponding +belongs_to+ # association). @@ -75,14 +75,14 @@ # that describe it. def strength associations.size end - def inspect #:nodoc: + def inspect # @private :nodoc: "#<#{self.class}:0x%.14x @source=#{source} @destination=#{destination}>" % (object_id << 1) end - def <=>(other) #:nodoc: + def <=>(other) # @private :nodoc: (source.name <=> other.source.name).nonzero? or (destination.name <=> other.destination.name) end end end