neo4j 1.0.0.beta.7 → 1.0.0.beta.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,6 +24,7 @@ require 'neo4j/relationship'
24
24
  require 'neo4j/node'
25
25
  require 'neo4j/config'
26
26
  require 'neo4j/neo4j'
27
+ require 'neo4j/mapping/class_methods/root'
27
28
  require 'neo4j/mapping/class_methods/property'
28
29
  require 'neo4j/mapping/class_methods/index'
29
30
  require 'neo4j/mapping/class_methods/relationship'
@@ -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, :index_type_for
15
+ def_delegators :@indexer, :index, :find, :index?, :index_type?, :clear_index_type, :rm_index_type, :add_index, :rm_index, :index_type_for, :index_name
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.
@@ -12,10 +12,6 @@ module Neo4j::Mapping
12
12
  def rm_index(field, config = {})
13
13
  Neo4j::Node.rm_index(field, config, index_name)
14
14
  end
15
-
16
- def index_name
17
- root_class
18
- end
19
15
  end
20
16
  end
21
17
  end
@@ -2,25 +2,6 @@ module Neo4j::Mapping
2
2
  module ClassMethods
3
3
  module Property
4
4
 
5
- #
6
- # Access to class constants.
7
- # These properties are shared by the class and its siblings.
8
- # For example that means that we can specify properties for a parent
9
- # class and the child classes will 'inherit' those properties.
10
- #
11
-
12
- def root_class # :nodoc:
13
- self::ROOT_CLASS
14
- end
15
-
16
- def properties_info # :nodoc:
17
- self::PROPERTIES_INFO
18
- end
19
-
20
-
21
- # ------------------------------------------------------------------------
22
-
23
-
24
5
  # Generates accessor method and sets configuration for Neo4j node properties.
25
6
  # The generated accessor is a simple wrapper around the #[] and
26
7
  # #[]= operators.
@@ -43,16 +24,16 @@ module Neo4j::Mapping
43
24
  if props.size == 2 and props[1].kind_of?(Hash)
44
25
  props[1].each_pair do |key, value|
45
26
  pname = props[0].to_sym
46
- properties_info[pname] ||= {}
47
- properties_info[pname][key] = value
27
+ _decl_props[pname] ||= {}
28
+ _decl_props[pname][key] = value
48
29
  end
49
30
  props = props[0..0]
50
31
  end
51
32
 
52
33
  props.each do |prop|
53
34
  pname = prop.to_sym
54
- properties_info[pname] ||= {}
55
- properties_info[pname][:defined] = true
35
+ _decl_props[pname] ||= {}
36
+ _decl_props[pname][:defined] = true
56
37
 
57
38
  define_method(pname) do
58
39
  self[pname]
@@ -76,8 +57,8 @@ module Neo4j::Mapping
76
57
  # true or false
77
58
  #
78
59
  def property?(prop_name)
79
- return false if properties_info[prop_name.to_sym].nil?
80
- properties_info[prop_name.to_sym][:defined] == true
60
+ return false if _decl_props[prop_name.to_sym].nil?
61
+ _decl_props[prop_name.to_sym][:defined] == true
81
62
  end
82
63
 
83
64
 
@@ -89,7 +70,8 @@ module Neo4j::Mapping
89
70
  end
90
71
 
91
72
  def load_wrapper(node, db = Neo4j.started_db)
92
- wrapped_node = self.orig_new # avoid creating a new node, only a Ruby Object
73
+ wrapped_node = self.orig_new # avo
74
+ #id creating a new node, only a Ruby Object
93
75
  wrapped_node.init_on_load(node)
94
76
  wrapped_node
95
77
  end
@@ -2,9 +2,6 @@ module Neo4j::Mapping
2
2
  module ClassMethods
3
3
 
4
4
  module Relationship
5
- def decl_relationships # :nodoc:
6
- self::DECL_RELATIONSHIPS
7
- end
8
5
 
9
6
  # Specifies a relationship between two node classes.
10
7
  # Generates assignment and accessor methods for the given relationship.
@@ -28,17 +25,17 @@ module Neo4j::Mapping
28
25
  clazz = self
29
26
  module_eval(%Q{
30
27
  def #{rel_type}(&block)
31
- dsl = #{clazz}.decl_relationships[:'#{rel_type.to_s}']
28
+ dsl = #{clazz}._decl_rels[:'#{rel_type.to_s}']
32
29
  Neo4j::Mapping::HasN.new(self, dsl, &block)
33
30
  end}, __FILE__, __LINE__)
34
31
 
35
32
  module_eval(%Q{
36
33
  def #{rel_type}_rels
37
- dsl = #{clazz}.decl_relationships[:'#{rel_type.to_s}']
34
+ dsl = #{clazz}._decl_rels[:'#{rel_type.to_s}']
38
35
  Neo4j::Mapping::HasN.new(self, dsl).rels
39
36
  end}, __FILE__, __LINE__)
40
37
 
41
- decl_relationships[rel_type.to_sym] = Neo4j::Mapping::DeclRelationshipDsl.new(rel_type, params)
38
+ _decl_rels[rel_type.to_sym] = Neo4j::Mapping::DeclRelationshipDsl.new(rel_type, params)
42
39
  end
43
40
 
44
41
 
@@ -67,7 +64,7 @@ module Neo4j::Mapping
67
64
 
68
65
 
69
66
  module_eval(%Q{def #{rel_type}=(value)
70
- dsl = #{clazz}.decl_relationships[:'#{rel_type.to_s}']
67
+ dsl = #{clazz}._decl_rels[:'#{rel_type.to_s}']
71
68
  r = Neo4j::Mapping::HasN.new(self, dsl)
72
69
  r.rels.each {|n| n.del} # delete previous relationships, only one can exist
73
70
  r << value
@@ -75,19 +72,19 @@ module Neo4j::Mapping
75
72
  end}, __FILE__, __LINE__)
76
73
 
77
74
  module_eval(%Q{def #{rel_type}
78
- dsl = #{clazz}.decl_relationships[:'#{rel_type.to_s}']
75
+ dsl = #{clazz}._decl_rels[:'#{rel_type.to_s}']
79
76
  r = Neo4j::Mapping::HasN.new(self, dsl)
80
77
  [*r][0]
81
78
  end}, __FILE__, __LINE__)
82
79
 
83
80
  module_eval(%Q{
84
81
  def #{rel_type}_rel
85
- dsl = #{clazz}.decl_relationships[:'#{rel_type.to_s}']
82
+ dsl = #{clazz}._decl_rels[:'#{rel_type.to_s}']
86
83
  r = Neo4j::Mapping::HasN.new(self, dsl).rels
87
84
  [*r][0]
88
85
  end}, __FILE__, __LINE__)
89
86
 
90
- decl_relationships[rel_type.to_sym] = Neo4j::Mapping::DeclRelationshipDsl.new(rel_type, params)
87
+ _decl_rels[rel_type.to_sym] = Neo4j::Mapping::DeclRelationshipDsl.new(rel_type, params)
91
88
  end
92
89
 
93
90
  end
@@ -0,0 +1,28 @@
1
+ module Neo4j::Mapping
2
+ module ClassMethods
3
+ module Root
4
+ #attr_reader :_decl_rels, :_decl_props
5
+
6
+ def root_class(clazz)
7
+ @@_all_decl_rels ||= {}
8
+ @@_all_decl_props ||= {}
9
+ @@_all_decl_rels[clazz] ||= {}
10
+ @@_all_decl_props[clazz] ||= {}
11
+ @_decl_rels = @@_all_decl_rels[clazz]
12
+ @_decl_props = @@_all_decl_props[clazz]
13
+ end
14
+
15
+
16
+ def _decl_rels
17
+ @@_all_decl_rels[self] ||= {}
18
+ @_decl_props = @@_all_decl_rels[self]
19
+ end
20
+
21
+ def _decl_props
22
+ @@_all_decl_props[self] ||= {}
23
+ @_decl_props = @@_all_decl_props[self]
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -16,7 +16,7 @@ module Neo4j
16
16
  else
17
17
  # which class specifies the incoming DSL ?
18
18
  clazz = dsl.to_class || node.class
19
- @dsl = clazz.decl_relationships[dsl.to_type]
19
+ @dsl = clazz._decl_rels[dsl.to_type]
20
20
  raise "Unspecified outgoing relationship '#{dsl.to_type}' for incoming relationship '#{dsl.rel_id}' on class #{clazz}" if @dsl.nil?
21
21
  end
22
22
 
@@ -42,28 +42,22 @@ module Neo4j::Mapping
42
42
 
43
43
  def self.included(c) # :nodoc:
44
44
  c.instance_eval do
45
- # these constants are used in the Neo4j::RelClassMethods and Neo4j::PropertyClassMethods
46
- # they are defined here since they should only be defined once -
47
- # all subclasses share the same index and declared properties
48
- unless c.const_defined?(:DECL_RELATIONSHIPS)
49
- const_set(:ROOT_CLASS, self)
50
- const_set(:DECL_RELATIONSHIPS, {})
51
- const_set(:PROPERTIES_INFO, {})
52
- end
53
-
54
45
  class << self
55
46
  alias_method :orig_new, :new
56
47
  end
57
48
  end
49
+ c.extend ClassMethods::Root
58
50
  c.extend ClassMethods::Property
59
51
  c.extend ClassMethods::Relationship
60
52
  c.extend ClassMethods::Rule
61
53
  c.extend Neo4j::Index::ClassMethods
62
54
  def c.inherited(subclass)
63
55
  subclass.indexer subclass
56
+ subclass.root_class subclass
64
57
  super
65
58
  end
66
59
  c.indexer c
60
+ c.root_class c
67
61
  end
68
62
  end
69
63
  end
@@ -56,7 +56,7 @@ class Neo4j::Model
56
56
  # enables ActiveModel::Dirty and Validation
57
57
  def method_missing(method_id, *args, &block)
58
58
  if !self.class.attribute_methods_generated?
59
- self.class.define_attribute_methods(self.class.properties_info.keys)
59
+ self.class.define_attribute_methods(self.class._decl_props.keys)
60
60
  # try again
61
61
  send(method_id, *args, &block)
62
62
  end
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = "1.0.0.beta.7"
2
+ VERSION = "1.0.0.beta.8"
3
3
  end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 7
11
- version: 1.0.0.beta.7
10
+ - 8
11
+ version: 1.0.0.beta.8
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-10-03 00:00:00 +02:00
19
+ date: 2010-10-04 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -189,6 +189,7 @@ files:
189
189
  - lib/neo4j/mapping/class_methods/rule.rb
190
190
  - lib/neo4j/mapping/class_methods/property.rb
191
191
  - lib/neo4j/mapping/class_methods/index.rb
192
+ - lib/neo4j/mapping/class_methods/root.rb
192
193
  - lib/neo4j/mapping/class_methods/relationship.rb
193
194
  - README.rdoc
194
195
  - CHANGELOG