Module: OQGraph::Edge

Defined in:
lib/oqgraph/edge.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/oqgraph/edge.rb', line 6

def self.included base
  base.instance_eval do  
    def self.node_class_name
      self.name.gsub(/Edge$/,'')
    end
    
    def self.node_class
      node_class_name.constantize 
    end
    
    self.table_name = name.underscore.pluralize
    
    after_create  :add_to_graph
    after_destroy :remove_from_graph
    after_update  :update_graph

    belongs_to :from, :class_name => node_class_name, :foreign_key => :from_id
    belongs_to :to,   :class_name => node_class_name, :foreign_key => :to_id
    
    attr_accessible :from_id, :to_id, :weight
    
    include OQGraph::EdgeInstanceMethods
    extend OQGraph::EdgeClassMethods
  end
end