acts_as_oqgraph 0.1.7 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+ source "http://gems.github.com"
3
+
4
+ gem 'mysql2'
5
+ gem 'activerecord'
6
+ gem 'jeweler'
@@ -77,11 +77,11 @@ This gem requires the use of MySQL or MariaDB with the OQGraph engine plugin.
77
77
  For details of this see: http://openquery.com/products/graph-engine
78
78
 
79
79
  You will need a table for the edges with the following schema:
80
- create_table foo_edges do |t|
81
- t.integer from_id
82
- t.integer to_id
83
- t.double weight
84
- end
80
+ create_table :foo_edges do |t|
81
+ t.integer :from_id
82
+ t.integer :to_id
83
+ t.float :weight, :limit => 25
84
+ end
85
85
  The field names and table name can be changed via the options listed above.
86
86
  You should be able also to extend the edge model as you wish.
87
87
  The gem will automatically create the oqgraph table and the associations to it from your node model.
@@ -97,7 +97,7 @@ The associations are:
97
97
  = Examples of Use
98
98
 
99
99
  === Creating edges:
100
- foo.create_edge_to(bar)
100
+ foo.create_edge_to(bar)
101
101
  foo.create_edge_to_and_from(bar)
102
102
 
103
103
  Edge creation using ActiveRecord associations:
@@ -174,6 +174,13 @@ Here's an example request:
174
174
 
175
175
  Of course YMMV.
176
176
 
177
+ == Compatability
178
+
179
+ Versions < 1.0.0 use the mysql gem.
180
+
181
+ For compatability with Rails 3:
182
+ Versions >= 1.0.0 use the mysql2 gem.
183
+
177
184
  == Hairy bits, bugs and gotchas
178
185
 
179
186
  To keep the oqgraph table up to date the edge model copies all of it records in when first instantiated.
@@ -188,6 +195,4 @@ I'm working on a way to tell if the oqgraph table is stale other than by the cur
188
195
 
189
196
  There is a method 'in_edges' in the edge model class. This does not currently work. 'out_edges' does.
190
197
 
191
- This gem is very new, the API is liable to change until it stabilises.
192
-
193
198
  Copyright (c) 2010 Stuart Coyle, released under the MIT license
data/Rakefile CHANGED
@@ -37,7 +37,7 @@ rescue LoadError
37
37
  end
38
38
  end
39
39
 
40
- task :test => :check_dependencies
40
+ task :test
41
41
 
42
42
  task :default => :test
43
43
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 1.0.1
@@ -1,56 +1,57 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_oqgraph}
8
- s.version = "0.1.7"
8
+ s.version = "1.0.1"
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"]
12
- s.date = %q{2011-06-06}
12
+ s.date = %q{2011-09-13}
13
13
  s.description = %q{Acts As OQGraph allows ActiveRecord models to use the fast and powerful OQGraph engine for MYSQL.}
14
14
  s.email = %q{stuart.coyle@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "acts_as_oqgraph.gemspec",
27
- "lib/acts_as_oqgraph.rb",
28
- "lib/graph_edge.rb",
29
- "test/helper.rb",
30
- "test/models/custom_test_model.rb",
31
- "test/models/test_model.rb",
32
- "test/test_acts_as_oqgraph.rb"
21
+ "Gemfile",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "acts_as_oqgraph.gemspec",
27
+ "lib/acts_as_oqgraph.rb",
28
+ "lib/graph_edge.rb",
29
+ "test/helper.rb",
30
+ "test/models/custom_test_model.rb",
31
+ "test/models/test_model.rb",
32
+ "test/test_acts_as_oqgraph.rb"
33
33
  ]
34
34
  s.homepage = %q{http://github.com/stuart/acts_as_oqgraph}
35
- s.rdoc_options = ["--charset=UTF-8"]
36
35
  s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.3.7}
36
+ s.rubygems_version = %q{1.6.2}
38
37
  s.summary = %q{Use the Open Query Graph engine with Active Record}
39
- s.test_files = [
40
- "test/helper.rb",
41
- "test/models/custom_test_model.rb",
42
- "test/models/test_model.rb",
43
- "test/test_acts_as_oqgraph.rb"
44
- ]
45
38
 
46
39
  if s.respond_to? :specification_version then
47
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
40
  s.specification_version = 3
49
41
 
50
42
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<mysql2>, [">= 0"])
44
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
45
+ s.add_runtime_dependency(%q<jeweler>, [">= 0"])
51
46
  else
47
+ s.add_dependency(%q<mysql2>, [">= 0"])
48
+ s.add_dependency(%q<activerecord>, [">= 0"])
49
+ s.add_dependency(%q<jeweler>, [">= 0"])
52
50
  end
53
51
  else
52
+ s.add_dependency(%q<mysql2>, [">= 0"])
53
+ s.add_dependency(%q<activerecord>, [">= 0"])
54
+ s.add_dependency(%q<jeweler>, [">= 0"])
54
55
  end
55
56
  end
56
57
 
@@ -1,6 +1,5 @@
1
1
  require 'active_record'
2
2
  require File.join(File.dirname(__FILE__),'graph_edge')
3
- require 'mysql'
4
3
 
5
4
  module OQGraph
6
5
  def self.included(base)
@@ -133,10 +132,8 @@ module OQGraph
133
132
  edge_class.create_graph_table
134
133
  end
135
134
  EOF
136
- end
137
-
135
+ end
138
136
 
139
-
140
137
  private
141
138
 
142
139
  # Check that we have the OQGraph engine plugin installed in MySQL
@@ -144,8 +141,8 @@ module OQGraph
144
141
  begin
145
142
  result = false
146
143
  engines = self.connection.execute("SHOW ENGINES")
147
- engines.each_hash do |engine|
148
- result = true if (engine["Engine"]=="OQGRAPH" and engine["Support"]=="YES")
144
+ engines.each do |engine|
145
+ result = true if (engine[0]=="OQGRAPH" and engine[1]=="YES")
149
146
  end
150
147
  return result
151
148
  rescue ActiveRecord::StatementInvalid => e
@@ -3,7 +3,7 @@ require 'helper'
3
3
  class TestActsAsOqgraph < ActiveSupport::TestCase
4
4
  def setup
5
5
  ActiveRecord::Base.establish_connection(
6
- :adapter => "mysql",
6
+ :adapter => "mysql2",
7
7
  :host => "localhost",
8
8
  :username => "root",
9
9
  :password => "",
@@ -103,7 +103,7 @@ class TestActsAsOqgraph < ActiveSupport::TestCase
103
103
  def test_edge_model_creation_creates_oqgraph_edge
104
104
  @test_1.create_edge_to(@test_2, 2.5)
105
105
  oqedge = ActiveRecord::Base.connection.execute("SELECT * FROM test_model_oqgraph WHERE origid=#{@test_1.id} AND destid=#{@test_2.id};")
106
- assert_equal [nil,"1","2","2.5",nil,nil], oqedge.fetch_row
106
+ assert_equal [nil,1,2,2.5,nil,nil], oqedge.first
107
107
  end
108
108
 
109
109
  def test_edge_model_removal_deletes_oqgraph_edge
@@ -111,17 +111,17 @@ class TestActsAsOqgraph < ActiveSupport::TestCase
111
111
  edge = @test_1.outgoing_edges.find(:first, :conditions => {:to_id => @test_2.id})
112
112
  edge.destroy
113
113
  oqedge = ActiveRecord::Base.connection.execute("SELECT * FROM test_model_oqgraph WHERE origid=#{@test_1.id} AND destid=#{@test_2.id};")
114
- assert_equal nil, oqedge.fetch_row
114
+ assert_equal nil, oqedge.first
115
115
  end
116
116
 
117
117
  def test_edge_model_update
118
118
  edge = @test_1.create_edge_to(@test_2, 2.5)
119
119
  edge.update_attributes(:weight => 3.0)
120
120
  oqedge = ActiveRecord::Base.connection.execute("SELECT * FROM test_model_oqgraph WHERE origid=#{@test_1.id} AND destid=#{@test_2.id};")
121
- assert_equal [nil,"1","2","3",nil,nil], oqedge.fetch_row
121
+ assert_equal [nil,1,2,3,nil,nil], oqedge.first
122
122
  edge.update_attributes(:to_id => 3)
123
123
  oqedge = ActiveRecord::Base.connection.execute("SELECT * FROM test_model_oqgraph WHERE origid=#{@test_1.id} AND destid=3;")
124
- assert_equal [nil,"1","3","3",nil,nil], oqedge.fetch_row
124
+ assert_equal [nil,1,3,3,nil,nil], oqedge.first
125
125
  end
126
126
 
127
127
  def test_gettting_the_shortest_path
@@ -152,7 +152,7 @@ class TestActsAsOqgraph < ActiveSupport::TestCase
152
152
  @test_1.create_edge_to @test_2, 2.0
153
153
  @test_2.create_edge_to @test_3, 1.5
154
154
  @test_3.create_edge_to @test_4, 1.2
155
- assert_equal [nil,"2","1.5","1.2"], @test_1.shortest_path_to(@test_4).map(&:weight)
155
+ assert_equal [nil, 2.0 ,1.5, 1.2], @test_1.shortest_path_to(@test_4).map(&:weight)
156
156
  end
157
157
 
158
158
  def test_path_weight
@@ -241,7 +241,6 @@ class TestActsAsOqgraph < ActiveSupport::TestCase
241
241
 
242
242
  assert_equal [@test_1, @test_2, @test_3, @test_4], @test_1.shortest_path_to(@test_4)
243
243
  assert_equal ['a','b','c','d'], @test_1.shortest_path_to(@test_4).map(&:name)
244
-
245
244
  end
246
245
 
247
246
 
metadata CHANGED
@@ -1,35 +1,61 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: acts_as_oqgraph
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 7
9
- version: 0.1.7
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Stuart Coyle
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-06-06 00:00:00 +10:00
12
+ date: 2011-09-13 00:00:00.000000000 +10:00
18
13
  default_executable:
19
- dependencies: []
20
-
21
- description: Acts As OQGraph allows ActiveRecord models to use the fast and powerful OQGraph engine for MYSQL.
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mysql2
17
+ requirement: &2158235020 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2158235020
26
+ - !ruby/object:Gem::Dependency
27
+ name: activerecord
28
+ requirement: &2158233940 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2158233940
37
+ - !ruby/object:Gem::Dependency
38
+ name: jeweler
39
+ requirement: &2158233180 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2158233180
48
+ description: Acts As OQGraph allows ActiveRecord models to use the fast and powerful
49
+ OQGraph engine for MYSQL.
22
50
  email: stuart.coyle@gmail.com
23
51
  executables: []
24
-
25
52
  extensions: []
26
-
27
- extra_rdoc_files:
53
+ extra_rdoc_files:
28
54
  - LICENSE
29
55
  - README.rdoc
30
- files:
56
+ files:
31
57
  - .document
32
- - .gitignore
58
+ - Gemfile
33
59
  - LICENSE
34
60
  - README.rdoc
35
61
  - Rakefile
@@ -44,37 +70,26 @@ files:
44
70
  has_rdoc: true
45
71
  homepage: http://github.com/stuart/acts_as_oqgraph
46
72
  licenses: []
47
-
48
73
  post_install_message:
49
- rdoc_options:
50
- - --charset=UTF-8
51
- require_paths:
74
+ rdoc_options: []
75
+ require_paths:
52
76
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
77
+ required_ruby_version: !ruby/object:Gem::Requirement
54
78
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- segments:
59
- - 0
60
- version: "0"
61
- required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
84
  none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- segments:
67
- - 0
68
- version: "0"
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
69
89
  requirements: []
70
-
71
90
  rubyforge_project:
72
- rubygems_version: 1.3.7
91
+ rubygems_version: 1.6.2
73
92
  signing_key:
74
93
  specification_version: 3
75
94
  summary: Use the Open Query Graph engine with Active Record
76
- test_files:
77
- - test/helper.rb
78
- - test/models/custom_test_model.rb
79
- - test/models/test_model.rb
80
- - test/test_acts_as_oqgraph.rb
95
+ test_files: []
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC