Class: MermaidRailsErd::Relationship
- Inherits:
-
Object
- Object
- MermaidRailsErd::Relationship
- Defined in:
- lib/mermaid_rails_erd/relationship.rb
Instance Attribute Summary collapse
-
#extra_label ⇒ Object
readonly
Returns the value of attribute extra_label.
-
#fk_column ⇒ Object
readonly
Returns the value of attribute fk_column.
-
#fk_table ⇒ Object
readonly
Returns the value of attribute fk_table.
-
#foreign_key ⇒ Object
readonly
Returns the value of attribute foreign_key.
-
#from_table ⇒ Object
(also: #from)
readonly
Returns the value of attribute from_table.
-
#is_polymorphic ⇒ Object
readonly
Returns the value of attribute is_polymorphic.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#pk_column ⇒ Object
readonly
Returns the value of attribute pk_column.
-
#pk_table ⇒ Object
readonly
Returns the value of attribute pk_table.
-
#relationship_type ⇒ Object
(also: #symbol)
readonly
Returns the value of attribute relationship_type.
-
#to_table ⇒ Object
(also: #to)
readonly
Returns the value of attribute to_table.
Instance Method Summary collapse
- #generate_label ⇒ Object
-
#initialize(from, to, foreign_key, relationship_type, label = nil, fk_table = nil, fk_column = nil, pk_table = nil, pk_column = nil, is_polymorphic = false, extra_label = nil) ⇒ Relationship
constructor
A new instance of Relationship.
- #key ⇒ Object
Constructor Details
#initialize(from, to, foreign_key, relationship_type, label = nil, fk_table = nil, fk_column = nil, pk_table = nil, pk_column = nil, is_polymorphic = false, extra_label = nil) ⇒ Relationship
Returns a new instance of Relationship.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 12 def initialize(from, to, foreign_key, relationship_type, label = nil, fk_table = nil, fk_column = nil, pk_table = nil, pk_column = nil, is_polymorphic = false, extra_label = nil) @from_table = from @to_table = to @foreign_key = foreign_key @relationship_type = relationship_type @is_polymorphic = is_polymorphic @extra_label = extra_label # Store FK/PK information @fk_table = fk_table || from @fk_column = fk_column || foreign_key @pk_table = pk_table || to @pk_column = pk_column || "id" # Generate label if not provided @label = label || generate_label end |
Instance Attribute Details
#extra_label ⇒ Object (readonly)
Returns the value of attribute extra_label.
5 6 7 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 5 def extra_label @extra_label end |
#fk_column ⇒ Object (readonly)
Returns the value of attribute fk_column.
5 6 7 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 5 def fk_column @fk_column end |
#fk_table ⇒ Object (readonly)
Returns the value of attribute fk_table.
5 6 7 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 5 def fk_table @fk_table end |
#foreign_key ⇒ Object (readonly)
Returns the value of attribute foreign_key.
5 6 7 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 5 def foreign_key @foreign_key end |
#from_table ⇒ Object (readonly) Also known as: from
Returns the value of attribute from_table.
5 6 7 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 5 def from_table @from_table end |
#is_polymorphic ⇒ Object (readonly)
Returns the value of attribute is_polymorphic.
5 6 7 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 5 def is_polymorphic @is_polymorphic end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
5 6 7 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 5 def label @label end |
#pk_column ⇒ Object (readonly)
Returns the value of attribute pk_column.
5 6 7 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 5 def pk_column @pk_column end |
#pk_table ⇒ Object (readonly)
Returns the value of attribute pk_table.
5 6 7 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 5 def pk_table @pk_table end |
#relationship_type ⇒ Object (readonly) Also known as: symbol
Returns the value of attribute relationship_type.
5 6 7 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 5 def relationship_type @relationship_type end |
#to_table ⇒ Object (readonly) Also known as: to
Returns the value of attribute to_table.
5 6 7 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 5 def to_table @to_table end |
Instance Method Details
#generate_label ⇒ Object
36 37 38 39 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 36 def generate_label base_label = "#{@fk_table}.#{@fk_column} FK → #{@pk_table}.#{@pk_column} PK" @is_polymorphic ? "#{base_label} (#{@extra_label})" : base_label end |
#key ⇒ Object
32 33 34 |
# File 'lib/mermaid_rails_erd/relationship.rb', line 32 def key [from_table, to_table, foreign_key].sort.join("::") end |