neo4j 1.0.0.beta.6 → 1.0.0.beta.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/neo4j.rb +2 -2
- data/lib/neo4j/index.rb +6 -1
- data/lib/neo4j/jars/neo4j-lucene-index-0.1-20101002.153213-102.jar +0 -0
- data/lib/neo4j/mapping/class_methods/rule.rb +12 -11
- data/lib/neo4j/rails/model.rb +5 -0
- data/lib/neo4j/rails/validations/uniqueness.rb +29 -0
- data/lib/neo4j/version.rb +1 -1
- metadata +5 -7
- data/lib/neo4j/jars/lucene-core-2.9.2.jar +0 -0
- data/lib/neo4j/jars/neo4j-index-1.1.jar +0 -0
- data/lib/neo4j/jars/neo4j-kernel-1.1.jar +0 -0
- data/lib/neo4j/jars/neo4j-lucene-index-0.1-20100916.085626-67.jar +0 -0
data/lib/neo4j.rb
CHANGED
@@ -6,10 +6,9 @@ require 'time'
|
|
6
6
|
require 'date'
|
7
7
|
|
8
8
|
require 'neo4j/jars/neo4j-kernel-1.1.1.jar'
|
9
|
-
#require 'neo4j/jars/neo4j-kernel-1.2-20100916.085228-39.jar'
|
10
9
|
require 'neo4j/jars/geronimo-jta_1.1_spec-1.1.1.jar'
|
11
10
|
require 'neo4j/jars/lucene-core-3.0.1.jar'
|
12
|
-
require 'neo4j/jars/neo4j-lucene-index-0.1-
|
11
|
+
require 'neo4j/jars/neo4j-lucene-index-0.1-20101002.153213-102.jar'
|
13
12
|
require 'neo4j/to_java'
|
14
13
|
require 'neo4j/version'
|
15
14
|
require 'neo4j/equal'
|
@@ -39,6 +38,7 @@ require 'rails/railtie'
|
|
39
38
|
require 'active_model'
|
40
39
|
require 'neo4j/rails/transaction'
|
41
40
|
require 'neo4j/rails/railtie'
|
41
|
+
require 'neo4j/rails/validations/uniqueness'
|
42
42
|
require 'neo4j/rails/model'
|
43
43
|
require 'neo4j/rails/value'
|
44
44
|
require 'neo4j/rails/lucene_connection_closer'
|
data/lib/neo4j/index.rb
CHANGED
@@ -12,7 +12,7 @@ module Neo4j
|
|
12
12
|
module ClassMethods
|
13
13
|
extend Forwardable
|
14
14
|
|
15
|
-
def_delegators :@indexer, :index, :find, :index?, :index_type?, :clear_index_type, :rm_index_type, :add_index, :rm_index
|
15
|
+
def_delegators :@indexer, :index, :find, :index?, :index_type?, :clear_index_type, :rm_index_type, :add_index, :rm_index, :index_type_for
|
16
16
|
|
17
17
|
# Sets which indexer should be used for the given class.
|
18
18
|
# Returns the old one if there was an old indexer.
|
@@ -103,6 +103,11 @@ module Neo4j
|
|
103
103
|
@field_types.include?(field.to_s)
|
104
104
|
end
|
105
105
|
|
106
|
+
def index_type_for(field)
|
107
|
+
return nil unless index?(field)
|
108
|
+
@field_types[field.to_s]
|
109
|
+
end
|
110
|
+
|
106
111
|
def index_type?(type)
|
107
112
|
@field_types.values.include?(type)
|
108
113
|
end
|
Binary file
|
@@ -5,6 +5,11 @@ module Neo4j::Mapping
|
|
5
5
|
def add(clazz, field, props, &block)
|
6
6
|
clazz = clazz.to_s
|
7
7
|
@rules ||= {}
|
8
|
+
# was there no ruls for this class AND is neo4j running ?
|
9
|
+
if !@rules.include?(clazz) && Neo4j.running?
|
10
|
+
# maybe Neo4j was started first and the rules was added later. Create rule nodes now
|
11
|
+
create_rule_node_for(clazz)
|
12
|
+
end
|
8
13
|
@rules[clazz] ||= {}
|
9
14
|
filter = block.nil? ? Proc.new { |*| true } : block
|
10
15
|
@rules[clazz][field] = filter
|
@@ -38,23 +43,19 @@ module Neo4j::Mapping
|
|
38
43
|
end
|
39
44
|
|
40
45
|
def on_neo4j_started(*)
|
41
|
-
|
46
|
+
@rules.each_key { |clazz| create_rule_node_for(clazz) } if @rules
|
42
47
|
end
|
43
48
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
Neo4j
|
49
|
-
|
50
|
-
Neo4j.ref_node.outgoing(clazz) << node
|
51
|
-
node
|
52
|
-
end
|
49
|
+
def create_rule_node_for(clazz)
|
50
|
+
if !Neo4j.ref_node.rel?(clazz)
|
51
|
+
Neo4j::Transaction.run do
|
52
|
+
node = Neo4j::Node.new
|
53
|
+
Neo4j.ref_node.outgoing(clazz) << node
|
54
|
+
node
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
|
-
|
58
59
|
def trigger?(node)
|
59
60
|
@rules && node.property?(:_classname) && @rules.include?(node[:_classname])
|
60
61
|
end
|
data/lib/neo4j/rails/model.rb
CHANGED
@@ -3,10 +3,15 @@ class Neo4j::Model
|
|
3
3
|
include ActiveModel::Validations
|
4
4
|
include ActiveModel::Dirty
|
5
5
|
include ActiveModel::MassAssignmentSecurity
|
6
|
+
|
6
7
|
extend ActiveModel::Naming
|
7
8
|
extend ActiveModel::Callbacks
|
9
|
+
extend Neo4j::Validations::ClassMethods
|
8
10
|
define_model_callbacks :create, :save, :update, :destroy
|
9
11
|
|
12
|
+
|
13
|
+
UniquenessValidator = Neo4j::Validations::UniquenessValidator
|
14
|
+
|
10
15
|
class RecordInvalidError < RuntimeError
|
11
16
|
attr_reader :record
|
12
17
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Neo4j
|
2
|
+
module Validations
|
3
|
+
class UniquenessValidator < ActiveModel::EachValidator
|
4
|
+
def initialize(options)
|
5
|
+
super(options.reverse_merge(:case_sensitive => true))
|
6
|
+
end
|
7
|
+
|
8
|
+
def validate_each(record, attribute, value)
|
9
|
+
clazz = record.class
|
10
|
+
|
11
|
+
# TODO is it possible to move this to setup instead so that we don't have to do this always ?
|
12
|
+
if clazz.index_type_for(attribute) != :exact
|
13
|
+
raise "Can't validate property #{attribute} on class #{clazz} since there is no :exact lucene index on that property"
|
14
|
+
end
|
15
|
+
|
16
|
+
query = "#{attribute}: #{value}"
|
17
|
+
if !clazz.find(query).empty?
|
18
|
+
record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
def validates_uniqueness_of(*attr_names)
|
25
|
+
validates_with UniquenessValidator, _merge_attributes(attr_names)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/neo4j/version.rb
CHANGED
metadata
CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
|
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- beta
|
10
|
-
-
|
11
|
-
version: 1.0.0.beta.
|
10
|
+
- 7
|
11
|
+
version: 1.0.0.beta.7
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Andreas Ronge
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-10-03 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -178,13 +178,11 @@ files:
|
|
178
178
|
- lib/neo4j/rails/lucene_connection_closer.rb
|
179
179
|
- lib/neo4j/rails/transaction.rb
|
180
180
|
- lib/neo4j/rails/value.rb
|
181
|
-
- lib/neo4j/
|
182
|
-
- lib/neo4j/jars/lucene-core-2.9.2.jar
|
183
|
-
- lib/neo4j/jars/neo4j-kernel-1.1.jar
|
181
|
+
- lib/neo4j/rails/validations/uniqueness.rb
|
184
182
|
- lib/neo4j/jars/lucene-core-3.0.1.jar
|
185
183
|
- lib/neo4j/jars/geronimo-jta_1.1_spec-1.1.1.jar
|
186
184
|
- lib/neo4j/jars/neo4j-kernel-1.1.1.jar
|
187
|
-
- lib/neo4j/jars/neo4j-index-
|
185
|
+
- lib/neo4j/jars/neo4j-lucene-index-0.1-20101002.153213-102.jar
|
188
186
|
- lib/neo4j/mapping/decl_relationship_dsl.rb
|
189
187
|
- lib/neo4j/mapping/node_mixin.rb
|
190
188
|
- lib/neo4j/mapping/has_n.rb
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|