neo4j 3.0.2 → 3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75e9394211348d0302d6f68dac0f87653eb95f28
4
- data.tar.gz: 289355ac0ac9c885ae57eb12395046a1b612b5ae
3
+ metadata.gz: 4d902cb2867667c62e30b5a4c0ca2aa5341b06cc
4
+ data.tar.gz: 95ce7ebf16a229a510ab76aeb1e40b69275e1dc3
5
5
  SHA512:
6
- metadata.gz: 6d85f48c40cb8d3af253ae0eae9ed40d10b351eb0dc993d962987426d54f395495b7a1940f970c8c25b4847693d658fa22a5e6c003ea85cdb36fc04da51b2e04
7
- data.tar.gz: 8cd671cfc2c868f184388c4b37df8490b7d07b7dcc0421e3bce21ea1ee0caee1626e0b3800128e736f8002497a0868996e2517880b69f076d63d5664d9487096
6
+ metadata.gz: 265e6724e37c3a89d7af59dcc2484915cd0d39b60e1cf642bd22ed1f0a6d997aa09163186148e78803f7cec552be2c07f0ce9eb503f572208c116313da6db764
7
+ data.tar.gz: c84429373e502d634d4b29c6a0ab864af15e4def869260693bfba8789c4a610c2406f2dd611d6d84317ca2a55199c267d642342f1610966d5a210a351ae873eb
data/CHANGELOG CHANGED
@@ -1,8 +1,17 @@
1
+ == 3.0.3
2
+ * Gemspec has been updated to require neo4j-core 3.0.5
3
+ * Added `find_in_batches`
4
+ * Pagination has been updated to allow better ordering. Relaunch of neo4j-will_paginate as neo4j-will_paginate_redux is imminent!
5
+ * Everything is better: `create`'s handling of blocks, better behavior from `count`, better ActiveRel from_class/to_class checks, better handling of rel_class strings, and more
6
+ * Added a new find_or_create_by class method
7
+
8
+ Big thanks to new contributors Miha Rekar and Michael Perez! Also check out or Github issues, where we're discussing changes for 3.1.0. https://github.com/neo4jrb/neo4j/issues
9
+
1
10
  == 3.0.2
2
11
  * "Model#all" now evaluates lazily, models no longer include Enumerable
3
12
  * Faster, more efficient uniqueness validations
4
13
  * Adjusted many common queries to use params, will improve performance
5
- * ActiveRel fixes: create uses Core Query instead of Core's `rels` method, `{ classname: #{_classname} }` no longer inserted into every query, find related node IDs without loading the nodes
14
+ * ActiveRel fixes: create uses Core Query instead of Core's `rels` method, `{ classname: #{_classname} }` no longer inserted into every query, find related node IDs without loading the nodes
6
15
  * Allow inheritance when checking model class on a relation (Andrew Jones)
7
16
  * Provided migrations will use Rake.original_dir instead of Rails.env to provide better compatibility with frameworks other than Rails
8
17
  * rel_class option in ActiveNode models will now accept string of a model name
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- #gem 'neo4j-core', path: '../neo4j-core'
5
+ gem 'neo4j-core', github: 'neo4jrb/neo4j-core' if ENV["TRAVIS"]
6
6
  #gem 'neo4j-core', git: 'https://github.com/neo4jrb/neo4j-core'
7
7
  #gem 'orm_adapter', :path => '../orm_adapter'
8
8
 
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
- # Welcome to Neo4j.rb [![Build Status](https://secure.travis-ci.org/neo4jrb/neo4j.png?branch=master)](http://travis-ci.org/neo4jrb/neo4j) [![Coverage Status](https://coveralls.io/repos/neo4jrb/neo4j/badge.png?branch=master)](https://coveralls.io/r/neo4jrb/neo4j?branch=master) [![Code Climate](https://codeclimate.com/github/neo4jrb/neo4j.png)](https://codeclimate.com/github/andreasronge/neo4j)
1
+ # Welcome to Neo4j.rb
2
+ [![Build Status](https://secure.travis-ci.org/neo4jrb/neo4j.png?branch=master)](http://travis-ci.org/neo4jrb/neo4j) [![Coverage Status](https://coveralls.io/repos/neo4jrb/neo4j/badge.png?branch=master)](https://coveralls.io/r/neo4jrb/neo4j?branch=master) [![Code Climate](https://codeclimate.com/github/neo4jrb/neo4j.png)](https://codeclimate.com/github/andreasronge/neo4j)
2
3
 
3
4
  Neo4j.rb is an Active Model compliant Ruby/JRuby wrapper for [the Neo4j graph database](http://www.neo4j.org/). It uses the [neo4j-core](https://github.com/neo4jrb/neo4j-core) and [active_attr](https://github.com/cgriego/active_attr) gems.
4
5
 
6
+ Winner of a 2014 Graphie for "Best Community Contribution" at Neo4j's [Graph Connect](http://graphconnect.com) conference!
7
+ ![2014 Graphie](http://i.imgur.com/CkOoTTYm.jpg)
8
+
5
9
  ## Modern (3.X) Documentation
6
10
 
7
11
  * [Wiki](https://github.com/neo4jrb/neo4j/wiki/Neo4j.rb-v3-Introduction)
@@ -27,7 +27,7 @@ module Neo4j
27
27
  relationship_name_cypher = ":`#{relationship_type}`" if relationship_type
28
28
  properties_string = get_properties_string(properties)
29
29
  relationship_cypher = get_relationship_cypher(var, relationship_name_cypher, properties_string)
30
- get_direction(relationship_cypher, create)
30
+ get_direction(relationship_cypher, create)
31
31
  end
32
32
 
33
33
  def target_class_name
@@ -73,8 +73,12 @@ module Neo4j
73
73
  @relationship_class._type
74
74
  end
75
75
 
76
+ def relationship_class_name
77
+ @relationship_class_name ||= @relationship_class.respond_to?(:constantize) ? @relationship_class : @relationship_class.name
78
+ end
79
+
76
80
  def inject_classname(properties)
77
- properties[Neo4j::Config.class_name_property] = @relationship_class.name if @relationship_class
81
+ properties[Neo4j::Config.class_name_property] = relationship_class_name if @relationship_class
78
82
  properties
79
83
  end
80
84
 
@@ -117,7 +121,7 @@ module Neo4j
117
121
  @relationship_class = options[:rel_class]
118
122
  @relationship_type = options[:type] && options[:type].to_sym
119
123
  end
120
-
124
+
121
125
  # Return basic details about association as declared in the model
122
126
  # @example
123
127
  # has_many :in, :bands
@@ -68,12 +68,13 @@ module Neo4j::ActiveNode
68
68
  end
69
69
 
70
70
  module ClassMethods
71
- # Creates a saves a new node
71
+ # Creates and saves a new node
72
72
  # @param [Hash] props the properties the new node should have
73
- def create(props = {})
73
+ def create(props = {}, &block)
74
74
  association_props = extract_association_attributes!(props)
75
75
 
76
76
  new(props).tap do |obj|
77
+ yield obj if block_given?
77
78
  obj.save
78
79
  association_props.each do |prop, value|
79
80
  obj.send("#{prop}=", value)
@@ -82,7 +83,7 @@ module Neo4j::ActiveNode
82
83
  end
83
84
 
84
85
  # Same as #create, but raises an error if there is a problem during save.
85
- def create!(*args)
86
+ def create!(*args, &block)
86
87
  props = args[0] || {}
87
88
  association_props = extract_association_attributes!(props)
88
89
 
@@ -95,6 +96,16 @@ module Neo4j::ActiveNode
95
96
  end
96
97
  end
97
98
 
99
+ # Finds the first node with the given attributes, or calls create if none found
100
+ def find_or_create_by(attributes, &block)
101
+ find_by(attributes) || create(attributes, &block)
102
+ end
103
+
104
+ # Same as #find_or_create_by, but calls #create! so it raises an error if there is a problem during save.
105
+ def find_or_create_by!(attributes, &block)
106
+ find_by(attributes) || create!(attributes, &block)
107
+ end
108
+
98
109
  def load_entity(id)
99
110
  Neo4j::Node.load(id)
100
111
  end
@@ -174,12 +174,11 @@ module Neo4j
174
174
  end
175
175
 
176
176
  attr_reader :context
177
+ attr_reader :node_var
177
178
 
178
179
  protected
179
180
  # Methods are underscored to prevent conflict with user class methods
180
181
 
181
- attr_reader :node_var
182
-
183
182
  def _add_params(params)
184
183
  @params = @params.merge(params)
185
184
  end
@@ -21,7 +21,7 @@ module Neo4j
21
21
  raise(InvalidParameterError, ':count accepts `distinct` or nil as a parameter') unless distinct.nil? || distinct == :distinct
22
22
  query_with_target(target) do |target|
23
23
  q = distinct.nil? ? target : "DISTINCT #{target}"
24
- self.query.return("count(#{q}) AS count").first.count
24
+ self.query.pluck("count(#{q}) AS #{target}").first
25
25
  end
26
26
  end
27
27
 
@@ -36,6 +36,23 @@ module Neo4j
36
36
 
37
37
  alias_method :blank?, :empty?
38
38
 
39
+ def include?(other)
40
+ raise(InvalidParameterError, ':include? only accepts nodes') unless other.respond_to?(:neo_id)
41
+ self.query_as(:n).where(n: {primary_key => other.id}).return("count(n) AS count").first.count > 0
42
+ end
43
+
44
+ def find_in_batches(options = {})
45
+ self.query_as(:n).return(:n).find_in_batches(:n, primary_key, options) do |batch|
46
+ yield batch.map(&:n)
47
+ end
48
+ end
49
+
50
+ def find_each(options = {})
51
+ self.query_as(:n).return(:n).find_each(:n, primary_key, options) do |batch|
52
+ yield batch.n
53
+ end
54
+ end
55
+
39
56
  private
40
57
 
41
58
  def exists_query_start(node_condition)
@@ -54,7 +54,7 @@ module Neo4j::ActiveRel
54
54
  [from_node, to_node].each do |node|
55
55
  type = from_node == node ? :_from_class : :_to_class
56
56
  next if allows_any_class?(type)
57
- raise ModelClassInvalidError, "Node class was #{node.class}, expected #{self.class.send(type)}" unless class_as_constant(type) == node.class
57
+ raise ModelClassInvalidError, "Node class was #{node.class}, expected #{self.class.send(type)}" unless class_as_constant(type) == node.class || node.class.ancestors.include?(class_as_constant(type))
58
58
  end
59
59
  end
60
60
 
@@ -23,7 +23,11 @@ module Neo4j::ActiveRel
23
23
  # @example Match with a string
24
24
  # MyRelClass.where('r1.grade > r1')
25
25
  def where(args={})
26
- Neo4j::Session.query.match("#{cypher_string(:outbound)}-[r1:`#{self._type}`]->#{cypher_string(:inbound)}").where(where_string(args)).pluck(:r1)
26
+ where_query.where(where_string(args)).pluck(:r1)
27
+ end
28
+
29
+ def array_load(ids_array)
30
+ where_query.where("ID(r1) IN {ids_array}").params(ids_array: ids_array).pluck(:r1)
27
31
  end
28
32
 
29
33
  # Performs a basic match on the relationship, returning all results.
@@ -42,6 +46,10 @@ module Neo4j::ActiveRel
42
46
 
43
47
  private
44
48
 
49
+ def where_query
50
+ Neo4j::Session.query.match("#{cypher_string(:outbound)}-[r1:`#{self._type}`]->#{cypher_string(:inbound)}")
51
+ end
52
+
45
53
  def all_query
46
54
  Neo4j::Session.query.match("#{cypher_string}-[r1:`#{self._type}`]->#{cypher_string(:inbound)}")
47
55
  end
@@ -7,10 +7,16 @@ module Neo4j
7
7
  @items, @total, @current_page = items, total, current_page
8
8
  end
9
9
 
10
- def self.create_from(source, page, per_page)
10
+ def self.create_from(source, page, per_page, order = nil)
11
11
  #partial = source.drop((page-1) * per_page).first(per_page)
12
+ target = source.node_var
12
13
  partial = source.skip(page-1).limit(per_page)
13
- Paginated.new(partial, source.count, page)
14
+ ordered_partial, ordered_source = if order
15
+ [partial.order_by(order), source.query.with("#{target} as #{target}").pluck("COUNT(#{target})").first]
16
+ else
17
+ [partial, source.count]
18
+ end
19
+ Paginated.new(ordered_partial, ordered_source, page)
14
20
  end
15
21
 
16
22
  delegate :each, :to => :items
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = "3.0.2"
2
+ VERSION = "3.0.3"
3
3
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
 
12
12
  s.authors = "Andreas Ronge"
13
13
  s.email = 'andreas.ronge@gmail.com'
14
- s.homepage = "https://github.com/andreasronge/neo4j/"
14
+ s.homepage = "https://github.com/neo4jrb/neo4j/"
15
15
  s.rubyforge_project = 'neo4j'
16
16
  s.summary = "A graph database for Ruby"
17
17
  s.license = 'MIT'
@@ -31,7 +31,7 @@ A Neo4j OGM (Object-Graph-Mapper) for use in Ruby on Rails and Rack frameworks,
31
31
  s.add_dependency("activesupport", "~> 4")
32
32
  s.add_dependency("railties", "~> 4")
33
33
  s.add_dependency('active_attr', "~> 0.8")
34
- s.add_dependency("neo4j-core", "~> 3.0.2")
34
+ s.add_dependency("neo4j-core", "~> 3.0.5")
35
35
 
36
36
  if RUBY_PLATFORM =~ /java/
37
37
  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.2
4
+ version: 3.0.3
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-10-23 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orm_adapter
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 3.0.2
89
+ version: 3.0.5
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 3.0.2
96
+ version: 3.0.5
97
97
  description: |
98
98
  A Neo4j OGM (Object-Graph-Mapper) for use in Ruby on Rails and Rack frameworks, intended as a complete replacement for ActiveRecord.
99
99
  email: andreas.ronge@gmail.com
@@ -160,7 +160,7 @@ files:
160
160
  - lib/rails/generators/neo4j/model/templates/model.erb
161
161
  - lib/rails/generators/neo4j_generator.rb
162
162
  - neo4j.gemspec
163
- homepage: https://github.com/andreasronge/neo4j/
163
+ homepage: https://github.com/neo4jrb/neo4j/
164
164
  licenses:
165
165
  - MIT
166
166
  metadata: {}
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  version: '0'
188
188
  requirements: []
189
189
  rubyforge_project: neo4j
190
- rubygems_version: 2.2.2
190
+ rubygems_version: 2.4.2
191
191
  signing_key:
192
192
  specification_version: 4
193
193
  summary: A graph database for Ruby