neo4j 3.0.0.alpha.8 → 3.0.0.alpha.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ module Neo4j::ActiveNode
2
+ module SerializedProperties
3
+ extend ActiveSupport::Concern
4
+
5
+ def serialized_properties
6
+ self.class.serialized_properties
7
+ end
8
+
9
+ module ClassMethods
10
+
11
+ def serialized_properties
12
+ @serialize || {}
13
+ end
14
+
15
+ def serialize(name, coder = JSON)
16
+ @serialize ||= {}
17
+ @serialize[name] = coder
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,119 @@
1
+ module Neo4j
2
+
3
+
4
+ # == Keeps configuration for neo4j
5
+ #
6
+ # == Configurations keys
7
+ #
8
+ class Config
9
+
10
+ DEFAULT_FILE = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config", "neo4j", "config.yml"))
11
+
12
+ class << self
13
+
14
+ # @return [Fixnum] The location of the default configuration file.
15
+ def default_file
16
+ @default_file ||= DEFAULT_FILE
17
+ end
18
+
19
+ # Sets the location of the configuration YAML file and old deletes configurations.
20
+ #
21
+ # @param [String] file_path represent the path to the file.
22
+ def default_file=(file_path)
23
+ delete_all
24
+ @defaults = nil
25
+ @default_file = File.expand_path(file_path)
26
+ end
27
+
28
+ # @return [Hash] the default file loaded by yaml
29
+ def defaults
30
+ require 'yaml'
31
+ @defaults ||= ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file(default_file))
32
+ end
33
+
34
+ # Reads from the default_file if configuration is not set already
35
+ # @return [Hash] the configuration
36
+ def get_or_setup_configuration
37
+ @configuration ||= setup
38
+ end
39
+
40
+ # @return [Hash] the configuration
41
+ def configuration
42
+ @configuration || {}
43
+ end
44
+
45
+ # Yields the configuration
46
+ #
47
+ # @example
48
+ # Neo4j::Config.use do |config|
49
+ # config[:storage_path] = '/var/neo4j'
50
+ # end
51
+ #
52
+ # @return nil
53
+ # @yield config
54
+ # @yieldparam [Neo4j::Config] config - this configuration class
55
+ def use
56
+ @configuration ||= ActiveSupport::HashWithIndifferentAccess.new
57
+ yield @configuration
58
+ nil
59
+ end
60
+
61
+
62
+ # Sets the value of a config entry.
63
+ #
64
+ # @param [Symbol] key the key to set the parameter for
65
+ # @param val the value of the parameter.
66
+ def []=(key, val)
67
+ get_or_setup_configuration[key.to_s] = val
68
+ end
69
+
70
+
71
+ # @param [Symbol] key The key of the config entry value we want
72
+ # @return the the value of a config entry
73
+ def [](key)
74
+ get_or_setup_configuration[key.to_s]
75
+ end
76
+
77
+
78
+ # Remove the value of a config entry.
79
+ #
80
+ # @param [Symbol] key the key of the configuration entry to delete
81
+ # @return The value of the removed entry.
82
+ def delete(key)
83
+ get_or_setup_configuration.delete(key)
84
+ end
85
+
86
+
87
+ # Remove all configuration. This can be useful for testing purpose.
88
+ #
89
+ # @return nil
90
+ def delete_all
91
+ @configuration = nil
92
+ end
93
+
94
+
95
+ # @return [Hash] The config as a hash.
96
+ def to_hash
97
+ get_or_setup_configuration.to_hash
98
+ end
99
+
100
+ # @return [String] The config as a YAML
101
+ def to_yaml
102
+ get_or_setup_configuration.to_yaml
103
+ end
104
+
105
+ # @return The a new configuration using default values as a hash.
106
+ def setup
107
+ @configuration = ActiveSupport::HashWithIndifferentAccess.new
108
+ @configuration.merge!(defaults)
109
+ @configuration
110
+ end
111
+
112
+ def class_name_property
113
+ Neo4j::Config[:class_name_property] || :_classname
114
+ end
115
+
116
+ end
117
+ end
118
+
119
+ end
@@ -0,0 +1,19 @@
1
+ module Neo4j
2
+ class Paginated
3
+ include Enumerable
4
+ attr_reader :items, :total, :current_page
5
+
6
+ def initialize(items, total, current_page)
7
+ @items, @total, @current_page = items, total, current_page
8
+ end
9
+
10
+ def self.create_from(source, page, per_page)
11
+ #partial = source.drop((page-1) * per_page).first(per_page)
12
+ partial = source.skip(page-1).limit(per_page)
13
+ Paginated.new(partial, source.count, page)
14
+ end
15
+
16
+ delegate :each, :to => :items
17
+ delegate :size, :[], :to => :items
18
+ end
19
+ end
data/lib/neo4j/railtie.rb CHANGED
@@ -65,6 +65,7 @@ module Neo4j
65
65
  cfg.sessions.each do |session_opts|
66
66
  Neo4j::Railtie.open_neo4j_session(session_opts)
67
67
  end
68
+ Neo4j::Config.setup.merge!(cfg.to_hash)
68
69
  end
69
70
  end
70
71
  end
@@ -2,7 +2,6 @@ module Neo4j
2
2
 
3
3
  module TypeConverters
4
4
 
5
-
6
5
  # Converts Date objects to Java long types. Must be timezone UTC.
7
6
  class DateConverter
8
7
  class << self
@@ -79,13 +78,60 @@ module Neo4j
79
78
  end
80
79
  end
81
80
 
81
+ # Converts hash to/from YAML
82
+ class YAMLConverter
83
+ class << self
84
+
85
+ def convert_type
86
+ Hash
87
+ end
88
+
89
+ def to_db(value)
90
+ return nil if value.nil?
91
+ Psych.dump(value)
92
+ end
93
+
94
+ def to_ruby(value)
95
+ return nil if value.nil?
96
+ Psych.load(value)
97
+ end
98
+ end
99
+ end
100
+
101
+ # Converts hash to/from JSON
102
+ class JSONConverter
103
+ class << self
104
+
105
+ def convert_type
106
+ JSON
107
+ end
108
+
109
+ def to_db(value)
110
+ return nil if value.nil?
111
+ value.to_json
112
+ end
113
+
114
+ def to_ruby(value)
115
+ return nil if value.nil?
116
+ JSON.parse(value, quirks_mode: true)
117
+ end
118
+ end
119
+ end
120
+
121
+
122
+
82
123
  def convert_properties_to(medium, properties)
83
124
  # Perform type conversion
125
+ serialize = self.respond_to?(:serialized_properties) ? self.serialized_properties : {}
84
126
  properties = properties.inject({}) do |new_attributes, key_value_pair|
85
127
  attr, value = key_value_pair
86
- type = self.class._attribute_type(attr)
128
+
129
+ # skip "secret" undeclared attributes such as uuid
130
+ next new_attributes unless self.class.attributes[attr]
131
+
132
+ type = serialize.has_key?(attr.to_sym) ? serialize[attr.to_sym] : self.class._attribute_type(attr)
87
133
  new_attributes[attr] = if TypeConverters.converters[type].nil?
88
- value
134
+ value
89
135
  else
90
136
  TypeConverters.send "to_#{medium}", value, type
91
137
  end
data/lib/neo4j/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = "3.0.0.alpha.8"
2
+ VERSION = "3.0.0.alpha.9"
3
3
  end
data/lib/neo4j/wrapper.rb CHANGED
@@ -4,16 +4,10 @@ class Neo4j::Node
4
4
 
5
5
  # this is a plugin in the neo4j-core so that the Ruby wrapper will be wrapped around the Neo4j::Node objects
6
6
  def wrapper
7
- wrappers = _class_wrappers
8
- if wrappers.empty?
9
- self
10
- else
11
- wrapper_classes = wrappers.map{|w| Neo4j::ActiveNode::Labels._wrapped_labels[w]}
12
- most_concrete_class = wrapper_classes.sort.first
13
- wrapped_node = most_concrete_class.new
14
- wrapped_node.init_on_load(self, self.props)
15
- wrapped_node
16
- end
7
+ most_concrete_class = sorted_wrapper_classes
8
+ wrapped_node = most_concrete_class.new
9
+ wrapped_node.init_on_load(self, self.props)
10
+ wrapped_node
17
11
  end
18
12
 
19
13
  def checked_labels_set
@@ -28,6 +22,17 @@ class Neo4j::Node
28
22
  end
29
23
  end
30
24
 
25
+ def sorted_wrapper_classes
26
+ if self.props.is_a?(Hash) && self.props.has_key?(Neo4j::Config.class_name_property)
27
+ self.props[Neo4j::Config.class_name_property].constantize
28
+ else
29
+ wrappers = _class_wrappers
30
+ return self if wrappers.nil?
31
+ wrapper_classes = wrappers.map{|w| Neo4j::ActiveNode::Labels._wrapped_labels[w]}
32
+ wrapper_classes.sort.first
33
+ end
34
+ end
35
+
31
36
  def load_class_from_label(label_name)
32
37
  begin
33
38
  label_name.to_s.split("::").inject(Kernel) {|container, name| container.const_get(name.to_s) }
data/lib/person.rb~ ADDED
@@ -0,0 +1,9 @@
1
+ require 'neo4j'
2
+
3
+ Neo4j::Session.open
4
+
5
+ class Person
6
+ include Neo4j::ActiveNode
7
+ property :name
8
+
9
+ end
@@ -62,7 +62,7 @@ module Rails
62
62
  when 'text' then
63
63
  'String'
64
64
  when 'integer', 'number', 'fixnum' then
65
- 'Fixnum'
65
+ 'Integer'
66
66
  when 'float' then
67
67
  'Float'
68
68
  else
data/lib/test.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'neo4j'
2
+ s = Neo4j::Session.open
3
+ class Person
4
+ include Neo4j::ActiveNode
5
+ property :name
6
+ has_many :out, :friends, type: :friends, model_class: self
7
+ end
8
+
9
+ t = Neo4j::Transaction.new
10
+
11
+ p = Person.new
12
+ p.save
13
+ p.friends << Person.create(name: 'a') << Person.create(name: 'b')
14
+ id = p.id
15
+ puts "ID #{id}"
16
+ puts "FRIENDS #{p.friends.to_a.first.name}"
17
+ t.fail
18
+ t.close
19
+ puts "DONE"
20
+
21
+ puts "LOAD #{Neo4j::Node.load(id)}"
data/lib/test.rb~ ADDED
@@ -0,0 +1,21 @@
1
+ require 'neo4j'
2
+ s = Neo4j::Session.open
3
+ class Person
4
+ include Neo4j::ActiveNode
5
+ property :name
6
+ has_many :out, :friends
7
+ end
8
+
9
+ t = Neo4j::Transaction.new
10
+
11
+ p = Person.new
12
+ p.save
13
+ p.friends << Person.create << Person.create
14
+ id = p.id
15
+ puts "ID #{id}"
16
+ puts "FRIENDS #{p.friends.to_a.count}"
17
+ t.fail
18
+ t.close
19
+ puts "DONE"
20
+
21
+ puts "LOAD #{Neo4j::Node.load(id)}"
data/neo4j.gemspec CHANGED
@@ -31,9 +31,10 @@ It comes included with the Apache Lucene document database.
31
31
 
32
32
  s.add_dependency('orm_adapter', "~> 0.5.0")
33
33
  s.add_dependency("activemodel", "~> 4")
34
+ s.add_dependency("activesupport", "~> 4")
34
35
  s.add_dependency("railties", "~> 4")
35
36
  s.add_dependency('active_attr', "~> 0.8")
36
- s.add_dependency("neo4j-core", "= 3.0.0.alpha.17")
37
+ s.add_dependency("neo4j-core", "= 3.0.0.alpha.19")
37
38
 
38
39
  if RUBY_PLATFORM =~ /java/
39
40
  s.add_dependency("neo4j-community", '~> 2.0')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.alpha.8
4
+ version: 3.0.0.alpha.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Ronge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-12 00:00:00.000000000 Z
11
+ date: 2014-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orm_adapter
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: railties
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +86,14 @@ dependencies:
72
86
  requirements:
73
87
  - - '='
74
88
  - !ruby/object:Gem::Version
75
- version: 3.0.0.alpha.17
89
+ version: 3.0.0.alpha.19
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - '='
81
95
  - !ruby/object:Gem::Version
82
- version: 3.0.0.alpha.17
96
+ version: 3.0.0.alpha.19
83
97
  description: "You can think of Neo4j as a high-performance graph engine with all the
84
98
  features of a mature and robust database.\nThe programmer works with an object-oriented,
85
99
  flexible network structure rather than with strict and static tables \nyet enjoys
@@ -100,11 +114,13 @@ files:
100
114
  - config/locales/en.yml
101
115
  - config/neo4j/config.yml
102
116
  - lib/neo4j.rb
117
+ - lib/neo4j.rb~
103
118
  - lib/neo4j/active_node.rb
104
119
  - lib/neo4j/active_node/callbacks.rb
105
120
  - lib/neo4j/active_node/has_n.rb
106
- - lib/neo4j/active_node/has_n/decl_rel.rb
121
+ - lib/neo4j/active_node/has_n/association.rb
107
122
  - lib/neo4j/active_node/has_n/nodes.rb
123
+ - lib/neo4j/active_node/id_property.rb
108
124
  - lib/neo4j/active_node/identity.rb
109
125
  - lib/neo4j/active_node/initialize.rb
110
126
  - lib/neo4j/active_node/labels.rb
@@ -115,14 +131,20 @@ files:
115
131
  - lib/neo4j/active_node/query/query_proxy.rb
116
132
  - lib/neo4j/active_node/quick_query.rb
117
133
  - lib/neo4j/active_node/rels.rb
134
+ - lib/neo4j/active_node/serialized_properties.rb
118
135
  - lib/neo4j/active_node/validations.rb
136
+ - lib/neo4j/config.rb
137
+ - lib/neo4j/paginated.rb
119
138
  - lib/neo4j/railtie.rb
120
139
  - lib/neo4j/type_converters.rb
121
140
  - lib/neo4j/version.rb
122
141
  - lib/neo4j/wrapper.rb
142
+ - lib/person.rb~
123
143
  - lib/rails/generators/neo4j/model/model_generator.rb
124
144
  - lib/rails/generators/neo4j/model/templates/model.erb
125
145
  - lib/rails/generators/neo4j_generator.rb
146
+ - lib/test.rb
147
+ - lib/test.rb~
126
148
  - neo4j.gemspec
127
149
  homepage: http://github.com/andreasronge/neo4j/tree
128
150
  licenses: