neoid 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ ## v0.0.2
2
+
3
+ * create node immediately after active record create
4
+ * logging
5
+ * bug fixes
6
+
1
7
  ## v0.0.1
2
8
 
3
9
  * initial release
data/README.md CHANGED
@@ -1,5 +1,3 @@
1
- # DRAFT ONLY - GEM IS NOT HOSTED YET.
2
-
3
1
  # Neoid
4
2
 
5
3
  Make your ActiveRecords stored and searchable on Neo4j graph database, in order to make fast graph queries that MySQL would crawl while doing them.
@@ -261,11 +259,11 @@ Please create a [new issue](https://github.com/elado/neoid/issues) if you run in
261
259
 
262
260
  ## To Do
263
261
 
264
- * Auto create node when creating an AR, instead of lazily-creating it
265
262
  * `after_update` to update a node/relationship.
266
263
  * Allow to disable sub reference nodes through options
267
264
  * Execute queries/scripts from model and not Neography (e.g. `Movie.neo_gremlin(gremlin_query)` with query that outputs IDs, returns a list of `Movie`s)
265
+ * Rake task to index all nodes and relatiohsips in Neo4j
268
266
 
269
267
  ---
270
268
 
271
- developed by [@elado](http://twitter.com/elado) | named by [@ekampf](http://twitter.com/ekampf)
269
+ Developed by [@elado](http://twitter.com/elado)
@@ -3,18 +3,22 @@ require "neoid/model_config"
3
3
  require "neoid/model_additions"
4
4
  require "neoid/node"
5
5
  require "neoid/relationship"
6
- require "neoid/railtie" if defined? Rails
7
6
 
8
7
  module Neoid
9
8
  class << self
10
9
  attr_accessor :db
10
+ attr_accessor :logger
11
11
  attr_accessor :ref_node
12
12
 
13
13
  def db
14
- raise "Neoid.db wasn't supplied" unless @db
14
+ raise "Must set Neoid.db with a Neography::Rest instance" unless @db
15
15
  @db
16
16
  end
17
17
 
18
+ def logger
19
+ @logger ||= Logger.new(ENV['NEOID_LOG'] ? $stdout : '/dev/null')
20
+ end
21
+
18
22
  def ref_node
19
23
  @ref_node ||= Neography::Node.load(Neoid.db.get_root['self'])
20
24
  end
@@ -10,21 +10,21 @@ module Neoid
10
10
  def neoidable_options
11
11
  @neoidable_options
12
12
  end
13
+
14
+ def neo_index_name
15
+ @index_name ||= "#{self.name.tableize}_index"
16
+ end
13
17
  end
14
18
 
15
19
  module InstanceMethods
16
20
  def to_neo
17
21
  {}
18
22
  end
19
-
20
- def neo_index_name
21
- @index_name ||= "#{self.class.name.tableize}_index"
22
- end
23
23
 
24
24
  protected
25
25
  def neo_properties_to_hash(*property_list)
26
26
  property_list.flatten.inject({}) { |all, property|
27
- all[property] = self.send(property)
27
+ all[property] = self.attributes[property]
28
28
  all
29
29
  }
30
30
  end
@@ -10,6 +10,8 @@ module Neoid
10
10
 
11
11
  def neo_subref_node
12
12
  @_neo_subref_node ||= begin
13
+ Neoid::logger.info "Node#neo_subref_node #{neo_subref_rel_type}"
14
+
13
15
  subref_node_query = Neoid.ref_node.outgoing(neo_subref_rel_type)
14
16
 
15
17
  if subref_node_query.to_a.blank?
@@ -30,7 +32,8 @@ module Neoid
30
32
 
31
33
  module InstanceMethods
32
34
  def neo_find_by_id
33
- Neoid.db.get_node_index(neo_index_name, :ar_id, self.id)
35
+ Neoid::logger.info "Node#neo_find_by_id #{self.class.neo_index_name} #{self.id}"
36
+ Neoid.db.get_node_index(self.class.neo_index_name, :ar_id, self.id)
34
37
  end
35
38
 
36
39
  def neo_create
@@ -39,18 +42,16 @@ module Neoid
39
42
 
40
43
  node = Neography::Node.create(data)
41
44
 
42
- begin
43
- Neography::Relationship.create(
44
- self.class.neo_subref_node_rel_type,
45
- self.class.neo_subref_node,
46
- node
47
- )
48
- rescue Exception => e
49
- puts [$!.message] + $!.backtrace
50
- raise e
51
- end
45
+ Neography::Relationship.create(
46
+ self.class.neo_subref_node_rel_type,
47
+ self.class.neo_subref_node,
48
+ node
49
+ )
52
50
 
53
- Neoid.db.add_node_to_index(neo_index_name, :ar_id, self.id, node)
51
+ Neoid.db.add_node_to_index(self.class.neo_index_name, :ar_id, self.id, node)
52
+
53
+ Neoid::logger.info "Node#neo_create #{self.class.name} #{self.id}, index = #{self.class.neo_index_name}"
54
+
54
55
  node
55
56
  end
56
57
 
@@ -64,14 +65,12 @@ module Neoid
64
65
 
65
66
  def neo_destroy
66
67
  return unless neo_node
67
- Neoid.db.remove_node_from_index(neo_index_name, neo_node)
68
+ Neoid.db.remove_node_from_index(self.class.neo_index_name, neo_node)
68
69
  neo_node.del
69
70
  end
70
71
  end
71
72
 
72
73
  def self.included(receiver)
73
- Neoid.db.create_node_index(receiver.name.tableize)
74
-
75
74
  receiver.extend Neoid::ModelAdditions::ClassMethods
76
75
  receiver.send :include, Neoid::ModelAdditions::InstanceMethods
77
76
  receiver.extend ClassMethods
@@ -79,6 +78,7 @@ module Neoid
79
78
 
80
79
  receiver.neo_subref_node # ensure
81
80
 
81
+ receiver.after_create :neo_create
82
82
  receiver.after_destroy :neo_destroy
83
83
  end
84
84
  end
@@ -2,7 +2,7 @@ module Neoid
2
2
  module Relationship
3
3
  module InstanceMethods
4
4
  def neo_find_by_id
5
- Neoid.db.get_relationship_index(neo_index_name, :ar_id, self.id)
5
+ Neoid.db.get_relationship_index(self.class.neo_index_name, :ar_id, self.id)
6
6
  end
7
7
 
8
8
  def neo_create
@@ -19,7 +19,9 @@ module Neoid
19
19
  end_node.neo_node
20
20
  )
21
21
 
22
- Neoid.db.add_relationship_to_index(neo_index_name, :ar_id, self.id, relationship)
22
+ Neoid.db.add_relationship_to_index(self.class.neo_index_name, :ar_id, self.id, relationship)
23
+
24
+ Neoid::logger.info "Relationship#neo_create #{self.class.name} #{self.id}, index = #{self.class.neo_index_name}"
23
25
 
24
26
  relationship
25
27
  end
@@ -30,8 +32,8 @@ module Neoid
30
32
 
31
33
  def neo_destroy
32
34
  return unless neo_relationship
33
- Neoid.db.remove_relationship_from_index(neo_index_name, neo_relationship)
34
- puts neo_relationship.del
35
+ Neoid.db.remove_relationship_from_index(self.class.neo_index_name, neo_relationship)
36
+ neo_relationship.del
35
37
  end
36
38
 
37
39
  def neo_relationship
@@ -40,8 +42,6 @@ module Neoid
40
42
  end
41
43
 
42
44
  def self.included(receiver)
43
- Neoid.db.create_relationship_index(receiver.name.tableize)
44
-
45
45
  receiver.extend Neoid::ModelAdditions::ClassMethods
46
46
  receiver.send :include, Neoid::ModelAdditions::InstanceMethods
47
47
  receiver.send :include, InstanceMethods
@@ -1,3 +1,3 @@
1
1
  module Neoid
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -18,8 +18,9 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
+ s.add_development_dependency "rake"
21
22
  s.add_development_dependency "rspec"
22
23
  s.add_development_dependency "rest-client"
24
+ s.add_development_dependency "supermodel"
23
25
  s.add_runtime_dependency "neography"
24
- s.add_runtime_dependency "supermodel"
25
26
  end
@@ -77,12 +77,9 @@ describe Neoid::ModelAdditions do
77
77
  context "nodes" do
78
78
  context "create graph nodes" do
79
79
  it "should call neo_create on a neo_node for user" do
80
- user = User.create(name: "Elad Ossadon")
81
-
82
- user.neo_find_by_id.should be_nil
83
-
84
- user.should_receive(:neo_create)
85
- user.neo_node
80
+ User.any_instance.should_receive(:neo_create)
81
+
82
+ User.create(name: "Elad Ossadon")
86
83
  end
87
84
 
88
85
  it "should create a neo_node for user" do
@@ -110,7 +107,6 @@ describe Neoid::ModelAdditions do
110
107
  it "should find a neo_node for user" do
111
108
  user = User.create(name: "Elad Ossadon", slug: "elado")
112
109
 
113
- user.neo_find_by_id.should be_nil
114
110
  user.neo_node.should_not be_nil
115
111
  user.neo_find_by_id.should_not be_nil
116
112
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-18 00:00:00.000000000 Z
12
+ date: 2012-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70163085349120 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70163085349120
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rspec
16
- requirement: &70350248004300 !ruby/object:Gem::Requirement
27
+ requirement: &70163085342100 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,10 +32,10 @@ dependencies:
21
32
  version: '0'
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *70350248004300
35
+ version_requirements: *70163085342100
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rest-client
27
- requirement: &70350248003700 !ruby/object:Gem::Requirement
38
+ requirement: &70163085341480 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,21 +43,21 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70350248003700
46
+ version_requirements: *70163085341480
36
47
  - !ruby/object:Gem::Dependency
37
- name: neography
38
- requirement: &70350248003040 !ruby/object:Gem::Requirement
48
+ name: supermodel
49
+ requirement: &70163085341000 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
42
53
  - !ruby/object:Gem::Version
43
54
  version: '0'
44
- type: :runtime
55
+ type: :development
45
56
  prerelease: false
46
- version_requirements: *70350248003040
57
+ version_requirements: *70163085341000
47
58
  - !ruby/object:Gem::Dependency
48
- name: supermodel
49
- requirement: &70350248002080 !ruby/object:Gem::Requirement
59
+ name: neography
60
+ requirement: &70163085340500 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: '0'
55
66
  type: :runtime
56
67
  prerelease: false
57
- version_requirements: *70350248002080
68
+ version_requirements: *70163085340500
58
69
  description: Extend Ruby on Rails ActiveRecord with Neo4j nodes. Keep RDBMS and utilize
59
70
  the power of Neo4j queries
60
71
  email:
@@ -94,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
105
  version: '0'
95
106
  segments:
96
107
  - 0
97
- hash: -1013384318664591928
108
+ hash: -1739317772889618819
98
109
  required_rubygems_version: !ruby/object:Gem::Requirement
99
110
  none: false
100
111
  requirements:
@@ -103,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
114
  version: '0'
104
115
  segments:
105
116
  - 0
106
- hash: -1013384318664591928
117
+ hash: -1739317772889618819
107
118
  requirements: []
108
119
  rubyforge_project: neoid
109
120
  rubygems_version: 1.8.10