Module: Dag::Edges::EdgeInstanceMethods
- Defined in:
- lib/dag/edges.rb
Overview
Instance methods included into the link model for polymorphic and non-polymorphic DAGs
Instance Attribute Summary collapse
-
#do_not_perpetuate ⇒ Object
Returns the value of attribute do_not_perpetuate.
Instance Method Summary collapse
-
#ancestor_id ⇒ Object
Id of the ancestor.
-
#count ⇒ Object
Count of the edge, ie the edge exists in X ways.
-
#descendant_id ⇒ Object
Id of the descendant.
-
#destroyable! ⇒ Object
Raises an exception if the edge is not destroyable.
-
#destroyable? ⇒ Boolean
Whether the edge can be destroyed.
-
#direct? ⇒ Boolean
Whether the link is direct, ie manually created.
-
#edge? ⇒ Boolean
Whether the link is an edge?.
-
#fill_defaults ⇒ Object
Fill default direct and count values if necessary.
-
#internal_count=(val) ⇒ Object
Changes the count of the edge.
-
#links_from_sink ⇒ Object
all links that start from the sink.
-
#links_to_source ⇒ Object
All links that end at the source.
-
#make_direct ⇒ Object
Makes the link direct, ie an edge.
-
#make_indirect ⇒ Object
Makes an edge indirect, ie a link.
-
#perpetuate ⇒ Object
Analyzes the changes in a model instance and rewires as necessary.
-
#sink ⇒ Object
Sink (destination) of the edge, creates if necessary.
-
#source ⇒ Object
Source of the edge, creates if necessary.
Instance Attribute Details
#do_not_perpetuate ⇒ Object
Returns the value of attribute do_not_perpetuate.
123 124 125 |
# File 'lib/dag/edges.rb', line 123 def do_not_perpetuate @do_not_perpetuate end |
Instance Method Details
#ancestor_id ⇒ Object
Id of the ancestor
163 164 165 |
# File 'lib/dag/edges.rb', line 163 def ancestor_id self[ancestor_id_column_name] end |
#count ⇒ Object
Count of the edge, ie the edge exists in X ways
173 174 175 |
# File 'lib/dag/edges.rb', line 173 def count self[count_column_name] end |
#descendant_id ⇒ Object
Id of the descendant
168 169 170 |
# File 'lib/dag/edges.rb', line 168 def descendant_id self[descendant_id_column_name] end |
#destroyable! ⇒ Object
Raises an exception if the edge is not destroyable. Otherwise makes the edge indirect before destruction to cleanup graph.
137 138 139 140 141 142 143 144 |
# File 'lib/dag/edges.rb', line 137 def destroyable! raise ActiveRecord::ActiveRecordError, 'ERROR: cannot destroy this edge' unless destroyable? #this triggers rewiring on destruction via perpetuate if self.direct? self[direct_column_name] = false end true end |
#destroyable? ⇒ Boolean
Whether the edge can be destroyed
132 133 134 |
# File 'lib/dag/edges.rb', line 132 def destroyable? (self.count == 0) || (self.direct? && self.count == 1) end |
#direct? ⇒ Boolean
Whether the link is direct, ie manually created
183 184 185 |
# File 'lib/dag/edges.rb', line 183 def direct? self[direct_column_name] end |
#edge? ⇒ Boolean
Whether the link is an edge?
188 189 190 |
# File 'lib/dag/edges.rb', line 188 def edge? self[direct_column_name] end |
#fill_defaults ⇒ Object
Fill default direct and count values if necessary. In place of after_initialize method
126 127 128 129 |
# File 'lib/dag/edges.rb', line 126 def fill_defaults self[direct_column_name] = true if self[direct_column_name].nil? self[count_column_name] = 0 if self[count_column_name].nil? end |
#internal_count=(val) ⇒ Object
Changes the count of the edge. DO NOT CALL THIS OUTSIDE THE PLUGIN
178 179 180 |
# File 'lib/dag/edges.rb', line 178 def internal_count=(val) self[count_column_name] = val end |
#links_from_sink ⇒ Object
all links that start from the sink
220 221 222 |
# File 'lib/dag/edges.rb', line 220 def links_from_sink self.class.with_ancestor_point(self.sink) end |
#links_to_source ⇒ Object
All links that end at the source
215 216 217 |
# File 'lib/dag/edges.rb', line 215 def links_to_source self.class.with_descendant_point(self.source) end |
#make_direct ⇒ Object
Makes the link direct, ie an edge
193 194 195 |
# File 'lib/dag/edges.rb', line 193 def make_direct self[direct_column_name] = true end |
#make_indirect ⇒ Object
Makes an edge indirect, ie a link.
198 199 200 |
# File 'lib/dag/edges.rb', line 198 def make_indirect self[direct_column_name] = false end |
#perpetuate ⇒ Object
Analyzes the changes in a model instance and rewires as necessary.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/dag/edges.rb', line 147 def perpetuate #flag set by links that were modified in association return true if self.do_not_perpetuate #if edge changed this was manually altered if direct_changed? if self.direct? self[count_column_name] += 1 else self[count_column_name] -= 1 end self.wiring end end |
#sink ⇒ Object
Sink (destination) of the edge, creates if necessary
209 210 211 212 |
# File 'lib/dag/edges.rb', line 209 def sink @sink = self.class::Sink.from_edge(self) if @sink.nil? @sink end |
#source ⇒ Object
Source of the edge, creates if necessary
203 204 205 206 |
# File 'lib/dag/edges.rb', line 203 def source @source = self.class::Source.from_edge(self) if @source.nil? @source end |