acts_as_oqgraph 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/acts_as_oqgraph.gemspec +1 -1
- data/lib/acts_as_oqgraph.rb +4 -1
- data/lib/graph_edge.rb +0 -1
- data/test/models/custom_test_model.rb +1 -1
- data/test/test_acts_as_oqgraph.rb +6 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/acts_as_oqgraph.gemspec
CHANGED
data/lib/acts_as_oqgraph.rb
CHANGED
@@ -75,7 +75,7 @@ module OQGraph
|
|
75
75
|
oqgraph_table_name = options[:oqgraph_table_name] || "#{self.name}Oqgraph".underscore
|
76
76
|
from_key = options[:from_key] || 'from_id'
|
77
77
|
to_key = options[:to_key] || 'to_id'
|
78
|
-
|
78
|
+
weight_column = options[:weight_column] || 'weight'
|
79
79
|
# Create the Edge Model
|
80
80
|
eval <<-EOS
|
81
81
|
class ::#{class_name} < ::GraphEdge
|
@@ -84,10 +84,13 @@ module OQGraph
|
|
84
84
|
belongs_to :from, :class_name => '#{self.name}', :foreign_key => '#{from_key}'
|
85
85
|
belongs_to :to, :class_name => '#{self.name}', :foreign_key => '#{to_key}'
|
86
86
|
|
87
|
+
cattr_accessor :node_class, :oqgraph_table_name, :to_key, :from_key, :weight_column
|
88
|
+
|
87
89
|
@@oqgraph_table_name = '#{oqgraph_table_name}'
|
88
90
|
@@from_key = '#{from_key}'
|
89
91
|
@@to_key = '#{to_key}'
|
90
92
|
@@node_class = #{self}
|
93
|
+
@@weight_column = '#{weight_column}'
|
91
94
|
|
92
95
|
create_graph_table
|
93
96
|
end
|
data/lib/graph_edge.rb
CHANGED
@@ -6,7 +6,6 @@ class GraphEdge < ActiveRecord::Base
|
|
6
6
|
after_destroy :remove_from_graph
|
7
7
|
after_update :update_graph
|
8
8
|
|
9
|
-
cattr_accessor :node_class, :oqgraph_table_name, :to_key, :from_key
|
10
9
|
|
11
10
|
# Creates the OQgraph table if it does not exist.
|
12
11
|
# Deletes all entries if it does exist and then repopulates with
|
@@ -66,6 +66,12 @@ class TestActsAsOqgraph < ActiveSupport::TestCase
|
|
66
66
|
assert_equal CustomEdge, CustomTestModel.edge_class
|
67
67
|
end
|
68
68
|
|
69
|
+
def test_custom_keys
|
70
|
+
assert_equal 'dest_id', CustomEdge.to_key
|
71
|
+
assert_equal 'orig_id', CustomEdge.from_key
|
72
|
+
assert_equal 'length', CustomEdge.weight_column
|
73
|
+
end
|
74
|
+
|
69
75
|
def test_test_model_edge_creation
|
70
76
|
@test_1.create_edge_to(@test_2)
|
71
77
|
assert_not_nil edge = TestModelEdge.find(:first, :conditions => {:from_id => @test_1.id, :to_id => @test_2.id, :weight => 1.0})
|