Class: Rumbly::Model::Relationship

Inherits:
Object
  • Object
show all
Extended by:
Abstract
Defined in:
lib/rumbly/model/relationship.rb

Overview

This is an abstract class that represents a (one-way) relationship between two classes within an MVC application. Object mapper-specific implementations should subclass this class and implement the following methods: type, source, target, name, multiplicity, through, and navigable.

According to the UML spec, generalizations don’t really have a name or a multiplicity, so these attributes should should be nil for this Relationship type; navigable should always return true for generalizations, and the subclass should be the source, whereas the superclass should be the target.

Direct Known Subclasses

ActiveRecord::Relationship

Constant Summary collapse

ATTRIBUTES =

Attributes and default values of a Relationship

{
  type: :association, source: nil, target: nil, name: '',
  multiplicity: nil, through: nil, navigable: false
}
RELATIONSHIP_TYPES =

Valid Relationship types

[
  :dependency, :association, :aggregation, :composition, :generalization
]

Instance Method Summary collapse

Methods included from Abstract

stub_required_methods

Instance Method Details

#<=>(other) ⇒ Object

Compares two Relationship objects by first seeing if their sources or targets differ. If those are the same, then use the name, then type, then through.



39
40
41
42
43
# File 'lib/rumbly/model/relationship.rb', line 39

def <=> (other)
  (source <=> other.source).nonzero? || (target <=> other.target).nonzero? ||
  (name <=> other.name).nonzero? || (type <=> other.type).nonzero? ||
  (through <=> other.through)
end

#labelObject

Returns a string that fully describes this Relationship, including its type, name, source, target, through class, and multiplicity.



47
48
49
50
51
52
53
54
# File 'lib/rumbly/model/relationship.rb', line 47

def label
  label  = "#{type.to_s}"
  label += " '#{name}'"
  label += " from #{source.name}"
  label += " to #{target.name}"
  label += " through #{through.name}" unless through.nil?
  label += " #{multiplicity.inspect}"
end

Simple question mark-style wrapper for the Relationship#navigable attribute.

Returns:

  • (Boolean)


33
34
35
# File 'lib/rumbly/model/relationship.rb', line 33

def navigable?
  navigable
end