Class: Dag::Polymorphic::EndPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/dag/polymorphic.rb

Overview

Contains nested classes in the link model for polymorphic DAGs Encapsulates the necessary information about a graph node

Direct Known Subclasses

Sink, Source

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type) ⇒ EndPoint

Initializes the EndPoint instance with an id and type



29
30
31
32
# File 'lib/dag/polymorphic.rb', line 29

def initialize(id, type)
  @id = id
  @type = type
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



34
35
36
# File 'lib/dag/polymorphic.rb', line 34

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



34
35
36
# File 'lib/dag/polymorphic.rb', line 34

def type
  @type
end

Class Method Details

.from(obj) ⇒ Object

Factory Construction method that creates an EndPoint instance from a model if necessary



23
24
25
26
# File 'lib/dag/polymorphic.rb', line 23

def self.from(obj)
  return obj if obj.kind_of?(EndPoint)
  self.from_resource(obj)
end

.from_resource(resource) ⇒ Object

Factory Construction method that creates an EndPoint instance from a model



18
19
20
# File 'lib/dag/polymorphic.rb', line 18

def self.from_resource(resource)
  self.new(resource.id, resource.class.to_s)
end

Instance Method Details

#matches?(other) ⇒ Boolean

Does the endpoint match a model or another endpoint

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/dag/polymorphic.rb', line 12

def matches?(other)
  return (self.id == other.id) && (self.type == other.type) if other.is_a?(EndPoint)
  (self.id == other.id) && (self.type == other.class.to_s)
end