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 CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_oqgraph}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Stuart Coyle"]
@@ -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
@@ -1,3 +1,3 @@
1
1
  class CustomTestModel < ActiveRecord::Base
2
- acts_as_oqgraph :class_name => 'CustomEdge', :from_key => 'orig_id', :to_key => 'dest_id'
2
+ acts_as_oqgraph :class_name => 'CustomEdge', :from_key => 'orig_id', :to_key => 'dest_id', :weight_column => 'length'
3
3
  end
@@ -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})
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Stuart Coyle