neo4j-will_paginate_redux 0.3.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d6a1bf407df21848542b063515f569356025079
4
+ data.tar.gz: 94cc9a3400af5ca7f1a5cb5f170d811cb1881b37
5
+ SHA512:
6
+ metadata.gz: 1a5db13acee30b2bf14a2a6e59cf6c1cefefe2ee1b6283ae1cc219007b4d0003fb4ffdacebc3519b886e67d19c8bbd8934c033b9b5a8932a84bd58b0c1c2da02
7
+ data.tar.gz: 7f2cfecf532739f066b59ffc9c333d4197066158349215748f135bb6d7ee70ef44342656e5c787d67ac0b7efed1b668b7bc41deec6f86d28519f6f672069dba7
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ *.swp
3
+ db/
4
+ bin/
5
+ .bundle
6
+ Gemfile.lock
7
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - jruby
3
+ env:
4
+ - JRUBY_OPTS=--1.8
5
+ - JRUBY_OPTS=--1.9
data/CHANGELOG ADDED
@@ -0,0 +1,14 @@
1
+ == 0.3.2 / 2014-11-03
2
+ * Adds `order` option.
3
+ * Moving to the neo4j-will_paginate_redux gem officially because listing repo in Gemfile is annoying.
4
+
5
+ == 0.3.1 / July 2014
6
+ * WE'RE BACK, BABY! Updated with support for Neo4jrb 3.0.
7
+
8
+ == 0.2.1 / 2013-06-22
9
+
10
+ * Make per_page optional like the doc says (#5)
11
+
12
+ == 0.2.0 / 2012-10-02
13
+
14
+ * Upgrade to use neo4j-cypher 1.0.0 gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in neo4j-will_paginate.gemspec
4
+ gemspec
5
+
6
+ # gem 'neo4j', path: '../neo4j'
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ Integration for Neo4j.rb and will_paginate
2
+ ============================================
3
+
4
+ This gem is just a simple integration of will_paginate and neo4j.
5
+
6
+ Which version do I use?
7
+ ==================
8
+
9
+ Neo4j.rb 2.x: 0.2.1<br />
10
+ Neo4j.rb 3.0 < alpha 8: 0.2.2<br />
11
+ Neo4j.rb 3.0 > alpha 7: Latest
12
+
13
+ Installation
14
+ ==================
15
+
16
+ 1. Add `neo4j-will_paginate` to your `Gemfile`.
17
+ 2. `require 'neo4j-will_paginate'` somewhere from your code.
18
+
19
+ Using
20
+ ==================
21
+
22
+ Please see the [will_paginate](https://github.com/mislav/will_paginate)
23
+ and [neo4j.rb](https://github.com/andreasronge/neo4j) for details.
24
+
25
+ But here is simple example:
26
+
27
+
28
+ ```ruby
29
+ # Probably in the Rails controller:
30
+
31
+ def index
32
+ # :per_page is optional
33
+ # :return is also optional. To return multiple objects, use an array of symbols
34
+ # :order is -- you guessed it -- optional, too. It accepts the same arguments as Neo4j::ActiveNode::QueryProxy's `order` method
35
+ @people = Person.(as: :p).where(age: 30).paginate(:page => 2, :per_page => 20, return: :p, order: :name)
36
+ end
37
+
38
+ # Then in the view:
39
+ paginate @people
40
+
41
+ ```
42
+
43
+ License
44
+ =====================
45
+
46
+ MIT by Dmytrii Nagirniak, Andreas Ronge, and Chris Grigg
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ srand # JRuby bug
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new("spec")
6
+
7
+ task :default => 'spec'
@@ -0,0 +1,59 @@
1
+ require "neo4j-will_paginate_redux/version"
2
+ require 'will_paginate/collection'
3
+ require 'will_paginate/per_page'
4
+ require 'neo4j'
5
+
6
+
7
+ module Neo4j::ActiveNode::Query
8
+ class QueryProxy
9
+
10
+ # The module provides the common interface for the pagination on any Enumerable class.
11
+ # By including the module, {Neo4j::WillPaginate::Pagination#paginate} method will be available.
12
+ include ::WillPaginate::CollectionMethods
13
+
14
+ # Paginates the {Enumerable} and returns {::WillPaginate::Collection} instance.
15
+ #
16
+ # @param [Hash] options a hash of options for the pagination.
17
+ # @option options [Symbol] :page current page for the pagination (defualts to 1).
18
+ # @option options [Symbol] :per_page numer of items per page (defaults to {::WillPaginate.per_page}).
19
+ # Aliases are `:per`, `:limit`.
20
+ # @option options [String,Array] :return an optional string or array of identifiers used earlier in the query
21
+ # requested for return.
22
+ # @option options [String,Symbol] :order an optional QueryProxy `order` clause to sort your results
23
+ #
24
+ # @example Paginate on a relationship:
25
+ # person.friends.paginate(:page => 5, :per_page => 10)
26
+ #
27
+ # @example Paginate the search results:
28
+ # Person.all(:conditions => "name: Dmytrii*").paginate(:page => 5, :per_page => 10)
29
+ def paginate(options={})
30
+ @page = (options[:page] || 1).to_i
31
+ @per_page = (options[:per] || options[:per_page] || options[:limit] || ::WillPaginate.per_page).to_i
32
+ @result_order = options[:order]
33
+ @returns = to_return(options[:return])
34
+ ::WillPaginate::Collection.create(page, per_page) { |pager| pager_return(pager) }
35
+ end
36
+
37
+ attr_reader :page, :per_page, :result_order, :returns
38
+
39
+ private
40
+
41
+ def pager_return(pager)
42
+ res = ::Neo4j::Paginated.create_from(self, page, per_page, result_order)
43
+ return_method = returns.nil? ? Proc.new { res.to_a } : Proc.new { res.pluck(*returns) }
44
+ pager.replace return_method.call
45
+ pager.total_entries = res.total unless pager.total_entries
46
+ end
47
+
48
+ def to_return(returns)
49
+ case returns
50
+ when Array
51
+ returns
52
+ when Symbol
53
+ [returns]
54
+ else
55
+ nil
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ module Neo4j
2
+ module WillPaginateRedux
3
+ VERSION = "0.3.2"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "neo4j-will_paginate_redux/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "neo4j-will_paginate_redux"
7
+ s.version = Neo4j::WillPaginateRedux::VERSION
8
+ s.authors = ["Dmytrii Nagirniak", "Andreas Ronge", "Chris Grigg"]
9
+ s.email = ["dnagir@gmail.com", "andreas.ronge@gmail.com", "chris@subvertallmedia.com"]
10
+ s.homepage = "https://github.com/neo4jrb/neo4j-will_paginate_redux"
11
+ s.summary = %q{Integration between Neo4jrb 3.0 and will_paginate.}
12
+ s.description = s.summary
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_development_dependency "rspec"
20
+ s.add_development_dependency 'rspec-its'
21
+ s.add_runtime_dependency "activesupport", "~> 4.0"
22
+ s.add_runtime_dependency "will_paginate", "~> 3.0"
23
+ s.add_runtime_dependency "neo4j", '>= 3.0.3', '< 3.1.0'
24
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+ require 'rspec/its'
3
+
4
+ describe 'pagination' do
5
+ class Lesson; end
6
+
7
+ class Person
8
+ include Neo4j::ActiveNode
9
+ property :name, :default => 'x'
10
+ has_many :both, :friends, model_class: 'Person'
11
+ has_many :out, :lessons
12
+ end
13
+
14
+ class Lesson
15
+ include Neo4j::ActiveNode
16
+ property :subject
17
+ has_many :in, :people, model_class: Person, origin: :lessons
18
+ end
19
+
20
+ describe 'will_paginate' do
21
+ before(:all) do
22
+ Person.destroy_all
23
+ 10.times { Person.create(name: 'x') }
24
+ end
25
+
26
+ subject { source.paginate(:page => 2, :per_page => 3) }
27
+
28
+ def self.should_be_paginated
29
+ its(:size) { is_expected.to eq 3 }
30
+ its(:current_page) { is_expected.to eq 2 }
31
+ its(:per_page) { is_expected.to eq 3 }
32
+ its(:total_entries) { is_expected.to eq 10 }
33
+ its(:offset) { is_expected.to eq 3 }
34
+ end
35
+
36
+ describe 'called on QueryProxy chain' do
37
+ let(:source) { Person.where(name: 'x') }
38
+ should_be_paginated
39
+ end
40
+
41
+ describe 'specifying return' do
42
+ context 'with a symbol' do
43
+ let(:subject) { source.paginate(page: 2, per_page: 3, return: :p) }
44
+ let(:source) { Person.as(:p).where(name: 'x') }
45
+ should_be_paginated
46
+ end
47
+
48
+ context 'with an array' do
49
+ let(:source) { Person.lessons(:l, :r) }
50
+ let(:subject) { source.paginate(page: 2, per_page: 3, return: [:l, :r]) }
51
+ before do
52
+ Lesson.create
53
+ Person.all.each { |p| p.lessons << Lesson.first}
54
+ end
55
+
56
+ it 'should contain arrays of both lessons and rels' do
57
+ expect(subject.first).to be_an(Array)
58
+ expect(subject.first[0]).to be_a(Lesson)
59
+ expect(subject.first[1]).to be_a(Neo4j::Server::CypherRelationship)
60
+ end
61
+ end
62
+ end
63
+
64
+ it 'should default to WillPaginate.per_page' do
65
+ pager = Person.where.paginate
66
+ expect(pager.per_page).to eq ::WillPaginate.per_page
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,66 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+ end
11
+
12
+
13
+ require 'neo4j-will_paginate_redux'
14
+ # neo4j Specs clean-up
15
+ require 'fileutils'
16
+
17
+ EMBEDDED_DB_PATH = File.join(Dir.tmpdir, "neo4j-core-java")
18
+
19
+ I18n.enforce_available_locales = false
20
+
21
+ def create_session
22
+ if RUBY_PLATFORM != 'java'
23
+ create_server_session
24
+ else
25
+ require "neo4j-embedded/embedded_impermanent_session"
26
+ create_embedded_session
27
+ end
28
+ end
29
+
30
+ def create_embedded_session
31
+ session = Neo4j::Session.open(:impermanent_db, EMBEDDED_DB_PATH, auto_commit: true)
32
+ session.start
33
+ end
34
+
35
+ def create_server_session
36
+ Neo4j::Session.open(:server_db, "http://localhost:7474")
37
+ delete_db
38
+ end
39
+
40
+ FileUtils.rm_rf(EMBEDDED_DB_PATH)
41
+
42
+ def delete_db
43
+ Neo4j::Session.current._query('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r')
44
+ end
45
+
46
+ RSpec.configure do |c|
47
+
48
+ c.before(:suite) do
49
+ Neo4j::Session.current.close if Neo4j::Session.current
50
+ create_session
51
+ end
52
+
53
+ c.before(:each) do
54
+ Neo4j::Session._listeners.clear
55
+ curr_session = Neo4j::Session.current
56
+ curr_session || create_session
57
+ end
58
+
59
+ c.after(:each) do
60
+ if Neo4j::Transaction.current
61
+ puts "WARNING forgot to close transaction"
62
+ Neo4j::Transaction.current.close
63
+ end
64
+ end
65
+
66
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neo4j-will_paginate_redux
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ platform: ruby
6
+ authors:
7
+ - Dmytrii Nagirniak
8
+ - Andreas Ronge
9
+ - Chris Grigg
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-11-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rspec-its
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: activesupport
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '4.0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '4.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: will_paginate
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.0'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: neo4j
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 3.0.3
78
+ - - "<"
79
+ - !ruby/object:Gem::Version
80
+ version: 3.1.0
81
+ type: :runtime
82
+ prerelease: false
83
+ version_requirements: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 3.0.3
88
+ - - "<"
89
+ - !ruby/object:Gem::Version
90
+ version: 3.1.0
91
+ description: Integration between Neo4jrb 3.0 and will_paginate.
92
+ email:
93
+ - dnagir@gmail.com
94
+ - andreas.ronge@gmail.com
95
+ - chris@subvertallmedia.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - ".gitignore"
101
+ - ".rspec"
102
+ - ".travis.yml"
103
+ - CHANGELOG
104
+ - Gemfile
105
+ - README.md
106
+ - Rakefile
107
+ - lib/neo4j-will_paginate_redux.rb
108
+ - lib/neo4j-will_paginate_redux/version.rb
109
+ - neo4j-will_paginate_redux.gemspec
110
+ - spec/neo4j-will_paginate_redux_spec.rb
111
+ - spec/spec_helper.rb
112
+ homepage: https://github.com/neo4jrb/neo4j-will_paginate_redux
113
+ licenses: []
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.2
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Integration between Neo4jrb 3.0 and will_paginate.
135
+ test_files:
136
+ - spec/neo4j-will_paginate_redux_spec.rb
137
+ - spec/spec_helper.rb