neo4j-will_paginate 0.1.0

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.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in neo4j-will_paginate.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ Integration for Neo4j.rb and will_paginate
2
+ ============================================
3
+
4
+ This gem is just a simple integration of will_paginate and neo4j.
5
+ [![Build Status](https://secure.travis-ci.org/neo4j-will_paginate/its.png)](http://travis-ci.org/dnagir/neo4j-will_paginate)
6
+
7
+ Installation
8
+ ==================
9
+
10
+ 1. Add `neo4j-will_paginate` to your `Gemfile`.
11
+ 2. `require 'neo4j-will_paginate` somewhere from your code.
12
+
13
+
14
+
15
+ Using
16
+ ==================
17
+
18
+ Please see the [will_paginate](https://github.com/mislav/will_paginate)
19
+ and [neo4j.rb](https://github.com/andreasronge/neo4j) for details.
20
+
21
+ But here is simple example:
22
+
23
+
24
+ ```ruby
25
+ # Probably in the Rails controller:
26
+
27
+ def index
28
+ @people = Person.all.paginate(:page => 2, :per_page => 20) # :per_page is optional
29
+ end
30
+
31
+ # Then in the view:
32
+ paginate @people
33
+
34
+ ```
35
+
36
+ License
37
+ =====================
38
+
39
+ MIT by Dmytrii Nagirniak and Andreas Ronge
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ srand # Workaround for a JRuby 1.6.5 bug
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,52 @@
1
+ require "neo4j-will_paginate/version"
2
+ require 'will_paginate/collection'
3
+ require 'neo4j'
4
+
5
+
6
+ module Neo4j
7
+ module WillPaginate
8
+
9
+ # The module provides the common interface for the pagination on any Enumerable class.
10
+ # By including the module, {Neo4j::WillPaginate::Pagination#paginate} method will be available.
11
+ module Pagination
12
+ include ::WillPaginate::CollectionMethods
13
+
14
+
15
+ # Paginates the {Enumerable} and returns {::WillPaginate::Collection} instance.
16
+ #
17
+ # @param [Hash] options a hash of options for the pagination.
18
+ # @option options [Symbol] :page current page for the pagination (defualts to 1).
19
+ # @option options [Symbol] :per_page numer of items per page (defaults to {::WillPaginate.per_page}).
20
+ # Aliases are `:per`, `:limit`.
21
+ #
22
+ # @example Paginate on a relationship:
23
+ # person.friends.paginate(:page => 5, :per_page => 10)
24
+ #
25
+ # @example Paginate the search results:
26
+ # Person.all(:conditions => "name: Dmytrii*").paginate(:page => 5, :per_page => 10)
27
+ def paginate(options={})
28
+ page = (options[:page] || 1).to_i
29
+ per_page = (options[:per] || options[:per_page] || options[:limit] || WillPaginate.per_page).to_i
30
+ ::WillPaginate::Collection.create(page, per_page) do |pager|
31
+ res = ::Neo4j::Paginated.create_from(self, page, per_page)
32
+ pager.replace res.to_a
33
+ pager.total_entries = res.total unless pager.total_entries
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ [
44
+ Neo4j::Traversal::Traverser,
45
+ Neo4j::Index::LuceneQuery,
46
+ Neo4j::HasN::Mapping,
47
+ Neo4j::Rails::Relationships::NodesDSL,
48
+ Neo4j::HasList::Mapping,
49
+ Neo4j::Rails::Relationships::RelsDSL
50
+ ].each do |m|
51
+ m.send :include, Neo4j::WillPaginate::Pagination
52
+ end
@@ -0,0 +1,5 @@
1
+ module Neo4j
2
+ module WillPaginate
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "neo4j-will_paginate/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "neo4j-will_paginate"
7
+ s.version = Neo4j::WillPaginate::VERSION
8
+ s.authors = ["Dmytrii Nagirniak", "Andreas Ronge"]
9
+ s.email = ["dnagir@gmail.com", "andreas.ronge@gmail.com"]
10
+ s.homepage = "https://github.com/dnagir/neo4j-will_paginate"
11
+ s.summary = %q{Integration between neo4j.rb and will_paginate.}
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = "neo4j-will_paginate"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec"
22
+ s.add_runtime_dependency "activesupport", "~> 3.0"
23
+ s.add_runtime_dependency "will_paginate", "~> 3.0"
24
+ s.add_runtime_dependency "neo4j", ">= 2.0.0.alpha.2"
25
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ module Specs
4
+
5
+ class Person < ::Neo4j::Model
6
+ property :name, :default => 'x'
7
+ index :name
8
+ has_n :friends
9
+ has_list :seen_before
10
+ end
11
+
12
+ describe Neo4j::WillPaginate::Pagination do
13
+ subject { source.paginate(:page => 2, :per_page => 3) }
14
+
15
+ def self.should_be_paginated
16
+ its(:size) { should == 3 }
17
+ its(:current_page) { should == 2 }
18
+ its(:per_page) { should == 3 }
19
+ its(:total_entries) { should == 10 }
20
+ its(:offset) { should == 3 }
21
+ end
22
+
23
+ context ::Neo4j::Traversal::Traverser do
24
+ let(:source) { Person.all }
25
+ before { 10.times { Person.create } }
26
+ should_be_paginated
27
+ end
28
+
29
+ context ::Neo4j::Index::LuceneQuery do
30
+ let(:source) { Person.all(:conditions => 'name: *') }
31
+ before { 10.times { Person.create(:name => 'x') } }
32
+ should_be_paginated
33
+ end
34
+
35
+ describe "models & rels" do
36
+ let(:source) { he.friends }
37
+ let(:he) { Person.create }
38
+ before { 10.times { he.friends << Person.create }; he.save! }
39
+
40
+ context ::Neo4j::Rails::Relationships::NodesDSL do
41
+ should_be_paginated
42
+ end
43
+
44
+ context ::Neo4j::Rails::Relationships::RelsDSL do
45
+ subject { source.paginate(:page => "2", :per => "3") } # Just a bit different set of options
46
+ let(:source) { he.rels(:friends, :outgoing) }
47
+ should_be_paginated
48
+ end
49
+ end
50
+
51
+ context ::Neo4j::HasList::Mapping do
52
+ let(:he) { Person.create }
53
+ let(:source) { he.seen_before }
54
+ before do
55
+ Neo4j::Transaction.run do
56
+ 10.times { he.seen_before << Person.create }
57
+ he.save!
58
+ end
59
+ end
60
+
61
+ should_be_paginated
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,42 @@
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.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ end
12
+
13
+
14
+ require 'neo4j-will_paginate'
15
+
16
+
17
+ # neo4j Specs clean-up
18
+ require 'fileutils'
19
+
20
+ def rm_db_storage!
21
+ FileUtils.rm_rf Neo4j::Config[:storage_path]
22
+ raise "Can't delete db" if File.exist?(Neo4j::Config[:storage_path])
23
+ end
24
+
25
+ RSpec.configure do |config|
26
+ $spec_counter = 0
27
+
28
+ config.before(:all) do
29
+ rm_db_storage! unless Neo4j.running?
30
+ end
31
+
32
+ config.after(:each) do
33
+ Neo4j::Rails::Model.close_lucene_connections
34
+ Neo4j::Transaction.run do
35
+ Neo4j::Index::IndexerRegistry.delete_all_indexes
36
+ end
37
+ Neo4j::Transaction.run do
38
+ Neo4j.threadlocal_ref_node = Neo4j::Node.new :name => "ref_#{$spec_counter}"
39
+ $spec_counter += 1
40
+ end
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neo4j-will_paginate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dmytrii Nagirniak
9
+ - Andreas Ronge
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-01-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &70217690688240 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70217690688240
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ requirement: &70217690687180 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70217690687180
37
+ - !ruby/object:Gem::Dependency
38
+ name: will_paginate
39
+ requirement: &70217690686000 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: '3.0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *70217690686000
48
+ - !ruby/object:Gem::Dependency
49
+ name: neo4j
50
+ requirement: &70217690684720 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 2.0.0.alpha.2
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *70217690684720
59
+ description: Integration between neo4j.rb and will_paginate.
60
+ email:
61
+ - dnagir@gmail.com
62
+ - andreas.ronge@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - .rspec
69
+ - .travis.yml
70
+ - Gemfile
71
+ - README.md
72
+ - Rakefile
73
+ - lib/neo4j-will_paginate.rb
74
+ - lib/neo4j-will_paginate/version.rb
75
+ - neo4j-will_paginate.gemspec
76
+ - spec/neo4j-will_paginate_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/dnagir/neo4j-will_paginate
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project: neo4j-will_paginate
98
+ rubygems_version: 1.8.10
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Integration between neo4j.rb and will_paginate.
102
+ test_files:
103
+ - spec/neo4j-will_paginate_spec.rb
104
+ - spec/spec_helper.rb
105
+ has_rdoc: