mongoid-graph 0.0.3

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/.gitignore ADDED
@@ -0,0 +1,26 @@
1
+ *.gem
2
+ *.rbc
3
+
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+
20
+ # Ignore idea stuff
21
+
22
+ .idea/
23
+ *.iml
24
+ *.swp
25
+
26
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+ # Capybara request specs
17
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
18
+ end
19
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Venelin Valkov <venelin@bapplz.com>, bapplz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Mongoid graph
2
+
3
+ Undirected graph implementation for Mongoid
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mongoid-graph'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mongoid-graph
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ first_node = Node.new(node_index: 1)
23
+ second_node = Node.new(node_index: 2)
24
+ first_node.connect_to second_node
25
+ first_node.save!
26
+ second_node.save!
27
+ Node.neighbours_of(first_node).size.should == 1
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ require "mongoid-graph/version"
2
+ require "mongoid/graph"
3
+
4
+ # Represents a Undirected general graph stored via Mongo
5
+ #
6
+ # Example
7
+ # first_node = Node.new(node_index: 1)
8
+ # second_node = Node.new(node_index: 2)
9
+ # first_node.connect_to second_node
10
+ # first_node.save!
11
+ # second_node.save!
12
+ # Node.neighbours_of(first_node).size.should == 1
13
+ module MongoidGraph
14
+ end
@@ -0,0 +1,3 @@
1
+ module MongoidGraph
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,33 @@
1
+ module Mongoid
2
+ module Graph
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ field :node_index, type: Integer
7
+ field :_neighbours, type: Array
8
+
9
+ after_initialize :generate_mongoid_neighbours
10
+ end
11
+
12
+ def connect_to(node)
13
+ unless self._neighbours.include?(node.node_index)
14
+ self._neighbours << node.node_index
15
+ node._neighbours << self.node_index
16
+ end
17
+ end
18
+
19
+ module ClassMethods
20
+
21
+ def neighbours_of(node)
22
+ any_in(node_index: node._neighbours.to_a)
23
+ end
24
+
25
+ end
26
+
27
+ protected
28
+
29
+ def generate_mongoid_neighbours
30
+ self._neighbours = []
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/mongoid-graph/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Venelin Valkov"]
6
+ gem.email = %w(venelin@bapplz.com)
7
+ gem.description = %q{Undirected graph implementation for Mongoid}
8
+ gem.summary = %q{Check who is connected to who, all withing the Mongoid context}
9
+ gem.homepage = "http://github.com/bapplz/mongoid-graph"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "mongoid-graph"
15
+ gem.require_paths = %w(lib)
16
+ gem.version = MongoidGraph::VERSION
17
+
18
+ gem.add_development_dependency "rspec", "~>2.10.0"
19
+ gem.add_development_dependency "mongoid-rspec", "~> 1.4.4"
20
+ gem.add_development_dependency "gem-release", "~>0.3.1"
21
+ gem.add_development_dependency "yard", "~>0.8.1"
22
+ gem.add_development_dependency "spork", "~> 0.9.1"
23
+ gem.add_development_dependency "guard", "~> 1.0.2"
24
+ gem.add_development_dependency "guard-spork", "~> 0.7.1"
25
+ gem.add_development_dependency "guard-rspec", "~> 0.7.0"
26
+
27
+ gem.add_runtime_dependency "activesupport", "~> 3.2.3"
28
+ gem.add_runtime_dependency "mongoid", "~> 2.4.9"
29
+ gem.add_runtime_dependency "bson_ext", "~> 1.6.2"
30
+ end
@@ -0,0 +1,25 @@
1
+ require "rspec"
2
+ require "spork"
3
+ require "mongoid"
4
+ require "mongoid-graph"
5
+ require "support/node"
6
+
7
+ Spork.prefork do
8
+
9
+ Mongoid.configure do |config|
10
+ name = "mongoid-graph"
11
+ config.master = Mongo::Connection.new.db(name)
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ config.mock_with :rspec
16
+
17
+ config.after :each do
18
+ Mongoid.purge!
19
+ end
20
+ end
21
+ end
22
+
23
+ Spork.each_run do
24
+ Mongoid.purge!
25
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ describe Node do
4
+
5
+ before :each do
6
+ @first_node = Node.new(node_index: 1)
7
+ @second_node = Node.new(node_index: 2)
8
+ end
9
+
10
+ it "should have 1 neighbour" do
11
+ @first_node.connect_to @second_node
12
+ @first_node.save!
13
+ @second_node.save!
14
+ Node.neighbours_of(@first_node).size.should == 1
15
+ end
16
+
17
+ it "should have neighbour with index 2" do
18
+ @first_node.connect_to @second_node
19
+ @first_node.save!
20
+ @second_node.save!
21
+ Node.neighbours_of(@first_node).first.node_index.should == 2
22
+ end
23
+
24
+ it "should connect a neighbour only once" do
25
+ @first_node.connect_to @second_node
26
+ @first_node.connect_to @second_node
27
+ @first_node.save!
28
+ @second_node.save!
29
+ Node.neighbours_of(@first_node).size.should == 1
30
+ end
31
+
32
+ it "should have neighbours which he is connected to" do
33
+ @third_node = Node.new(node_index: 3)
34
+ @first_node.connect_to @second_node
35
+ @first_node.save!
36
+ @second_node.save!
37
+ @third_node.save!
38
+ Node.neighbours_of(@first_node).size.should == 1
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ class Node
2
+
3
+ include Mongoid::Document
4
+ include Mongoid::Graph
5
+ end
metadata ADDED
@@ -0,0 +1,238 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-graph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Venelin Valkov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.10.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.10.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: mongoid-rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.4.4
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.4.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: gem-release
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.3.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.8.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.8.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: spork
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.9.1
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.9.1
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.0.2
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.0.2
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-spork
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.7.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 0.7.1
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 0.7.0
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 0.7.0
142
+ - !ruby/object:Gem::Dependency
143
+ name: activesupport
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 3.2.3
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 3.2.3
158
+ - !ruby/object:Gem::Dependency
159
+ name: mongoid
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ~>
164
+ - !ruby/object:Gem::Version
165
+ version: 2.4.9
166
+ type: :runtime
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: 2.4.9
174
+ - !ruby/object:Gem::Dependency
175
+ name: bson_ext
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ~>
180
+ - !ruby/object:Gem::Version
181
+ version: 1.6.2
182
+ type: :runtime
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ~>
188
+ - !ruby/object:Gem::Version
189
+ version: 1.6.2
190
+ description: Undirected graph implementation for Mongoid
191
+ email:
192
+ - venelin@bapplz.com
193
+ executables: []
194
+ extensions: []
195
+ extra_rdoc_files: []
196
+ files:
197
+ - .gitignore
198
+ - Gemfile
199
+ - Guardfile
200
+ - LICENSE
201
+ - README.md
202
+ - Rakefile
203
+ - lib/mongoid-graph.rb
204
+ - lib/mongoid-graph/version.rb
205
+ - lib/mongoid/graph.rb
206
+ - mongoid-graph.gemspec
207
+ - spec/spec_helper.rb
208
+ - spec/specs/mongoid-graph_spec.rb
209
+ - spec/support/node.rb
210
+ homepage: http://github.com/bapplz/mongoid-graph
211
+ licenses: []
212
+ post_install_message:
213
+ rdoc_options: []
214
+ require_paths:
215
+ - lib
216
+ required_ruby_version: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ required_rubygems_version: !ruby/object:Gem::Requirement
223
+ none: false
224
+ requirements:
225
+ - - ! '>='
226
+ - !ruby/object:Gem::Version
227
+ version: '0'
228
+ requirements: []
229
+ rubyforge_project:
230
+ rubygems_version: 1.8.24
231
+ signing_key:
232
+ specification_version: 3
233
+ summary: Check who is connected to who, all withing the Mongoid context
234
+ test_files:
235
+ - spec/spec_helper.rb
236
+ - spec/specs/mongoid-graph_spec.rb
237
+ - spec/support/node.rb
238
+ has_rdoc: