Class: Dag::Polymorphic::EndPoint
- Inherits:
-
Object
- Object
- Dag::Polymorphic::EndPoint
- 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
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.from(obj) ⇒ Object
Factory Construction method that creates an EndPoint instance from a model if necessary.
-
.from_resource(resource) ⇒ Object
Factory Construction method that creates an EndPoint instance from a model.
Instance Method Summary collapse
-
#initialize(id, type) ⇒ EndPoint
constructor
Initializes the EndPoint instance with an id and type.
-
#matches?(other) ⇒ Boolean
Does the endpoint match a model or another endpoint.
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
34 35 36 |
# File 'lib/dag/polymorphic.rb', line 34 def id @id end |
#type ⇒ Object (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
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 |