Class: Dbwatcher::Services::DiagramData::RelationshipParams

Inherits:
Object
  • Object
show all
Defined in:
lib/dbwatcher/services/diagram_data/relationship_params.rb

Overview

Parameter object for relationship creation

This class encapsulates parameters used for creating relationships to avoid long parameter lists.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ RelationshipParams

Initialize relationship parameters

Parameters:

  • params (Hash) (defaults to: {})

    hash containing all parameters

Options Hash (params):

  • :source_id (String)

    ID of the source entity

  • :target_id (String)

    ID of the target entity

  • :type (String)

    relationship type

  • :label (String)

    optional display label

  • :cardinality (String)

    optional cardinality type

  • :metadata (Hash)

    additional information



22
23
24
25
26
27
28
29
# File 'lib/dbwatcher/services/diagram_data/relationship_params.rb', line 22

def initialize(params = {})
  @source_id = params[:source_id]
  @target_id = params[:target_id]
  @type = params[:type]
  @label = params[:label]
  @cardinality = params[:cardinality]
  @metadata = params[:metadata] || {}
end

Instance Attribute Details

#cardinalityObject

Returns the value of attribute cardinality.



11
12
13
# File 'lib/dbwatcher/services/diagram_data/relationship_params.rb', line 11

def cardinality
  @cardinality
end

#labelObject

Returns the value of attribute label.



11
12
13
# File 'lib/dbwatcher/services/diagram_data/relationship_params.rb', line 11

def label
  @label
end

#metadataObject

Returns the value of attribute metadata.



11
12
13
# File 'lib/dbwatcher/services/diagram_data/relationship_params.rb', line 11

def 
  @metadata
end

#source_idObject

Returns the value of attribute source_id.



11
12
13
# File 'lib/dbwatcher/services/diagram_data/relationship_params.rb', line 11

def source_id
  @source_id
end

#target_idObject

Returns the value of attribute target_id.



11
12
13
# File 'lib/dbwatcher/services/diagram_data/relationship_params.rb', line 11

def target_id
  @target_id
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/dbwatcher/services/diagram_data/relationship_params.rb', line 11

def type
  @type
end

Class Method Details

.create(params) ⇒ RelationshipParams

Create from individual parameters

Parameters:

  • params (Hash)

    parameters hash

Returns:



35
36
37
# File 'lib/dbwatcher/services/diagram_data/relationship_params.rb', line 35

def self.create(params)
  new(params)
end

Instance Method Details

#to_hHash

Convert to hash

Returns:

  • (Hash)

    hash representation of parameters



42
43
44
45
46
47
48
49
50
51
# File 'lib/dbwatcher/services/diagram_data/relationship_params.rb', line 42

def to_h
  {
    source_id: source_id,
    target_id: target_id,
    type: type,
    label: label,
    cardinality: cardinality,
    metadata: 
  }
end