kaminari-activegraph 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +75 -0
- data/Rakefile +9 -0
- data/kaminari-activegraph.gemspec +29 -0
- data/lib/kaminari/active_graph/criteria_methods.rb +30 -0
- data/lib/kaminari/active_graph/extension.rb +29 -0
- data/lib/kaminari/active_graph/hooks.rb +13 -0
- data/lib/kaminari/active_graph/paginated.rb +55 -0
- data/lib/kaminari/active_graph/version.rb +5 -0
- data/lib/kaminari/active_graph.rb +11 -0
- data/lib/kaminari-activegraph.rb +1 -0
- metadata +145 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: df9615574a0da75f63000a7b5bd917c0f61b146363ff08cd8b8019dd0822ada9
|
|
4
|
+
data.tar.gz: ab0a6432e8364fd534d571317f0e6beeec0fea626c789d470f2ce77adc3467ac
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 35b11ef3836e1106f23c9916d1ee2c6f04fb3fa678a4845beb53ec165a3c8c56c7db9d772dd4e795dc1a07e92defdc5b5cba14114f2b6604a3bb697114d6d22e
|
|
7
|
+
data.tar.gz: 70e0d54019b619e38f000eb2675ed3008bef969f0c9596896a7c7d2955614ea5b6f263ab2d4dbb5c7314b21b26deb48516129464617133defc61d63a637e6465
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shuai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Kaminari::ActiveGraph
|
|
2
|
+
|
|
3
|
+
Adds [ActiveGraph](https://github.com/neo4jrb/activegraph) (Neo4j.rb) **11+**
|
|
4
|
+
support to [kaminari](https://github.com/kaminari/kaminari).
|
|
5
|
+
|
|
6
|
+
This gem is a port of
|
|
7
|
+
[kaminari-neo4j](https://github.com/megorei/kaminari-neo4j) updated for the
|
|
8
|
+
modern `activegraph` gem (the `neo4j` gem was renamed to `activegraph` starting
|
|
9
|
+
with 10.x, and the top-level constant moved from `Neo4j` to `ActiveGraph`).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add this line to your application's Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'kaminari-activegraph'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
$ bundle
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or install it yourself as:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
$ gem install kaminari-activegraph
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
Once required, every `ActiveGraph::Node` model and `QueryProxy` chain gains the
|
|
34
|
+
standard kaminari `#page` / `#per` methods:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
class User
|
|
38
|
+
include ActiveGraph::Node
|
|
39
|
+
property :name
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
User.page(2).per(20)
|
|
43
|
+
User.where(active: true).page(1).per(50)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The returned object is a `Kaminari::ActiveGraph::Paginated` collection that
|
|
47
|
+
exposes `current_page`, `total_count`, `total_pages`, `limit_value`,
|
|
48
|
+
`offset_value`, `entry_name`, etc., and is compatible with kaminari view
|
|
49
|
+
helpers such as `paginate @users`.
|
|
50
|
+
|
|
51
|
+
## Compatibility
|
|
52
|
+
|
|
53
|
+
| Dependency | Version |
|
|
54
|
+
| ------------- | ---------- |
|
|
55
|
+
| activegraph | `>= 11.0` |
|
|
56
|
+
| kaminari | `>= 1.2.1` |
|
|
57
|
+
| activesupport | `>= 6.0` |
|
|
58
|
+
| ruby | `>= 2.7` |
|
|
59
|
+
|
|
60
|
+
For older `neo4j` (≤ 9.x) projects use the original
|
|
61
|
+
[kaminari-neo4j](https://github.com/megorei/kaminari-neo4j) gem instead.
|
|
62
|
+
|
|
63
|
+
## Contributing
|
|
64
|
+
|
|
65
|
+
1. Fork it
|
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
67
|
+
3. Run the test suite (`bundle exec rspec`)
|
|
68
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
|
69
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
|
70
|
+
6. Create a new Pull Request
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
The gem is available as open source under the terms of the
|
|
75
|
+
[MIT License](LICENSE.txt).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'kaminari/active_graph/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'kaminari-activegraph'
|
|
8
|
+
spec.version = Kaminari::ActiveGraph::VERSION
|
|
9
|
+
spec.authors = %w(waynels)
|
|
10
|
+
spec.email = ["clover_0304@163.com"]
|
|
11
|
+
spec.summary = 'ActiveGraph support for kaminari'
|
|
12
|
+
spec.description = 'Adds ActiveGraph (Neo4j.rb 11+) support to kaminari'
|
|
13
|
+
spec.homepage = 'https://github.com/waynels/kaminari-activegraph'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.required_ruby_version = '>= 2.7'
|
|
17
|
+
|
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ['lib']
|
|
21
|
+
|
|
22
|
+
spec.add_dependency 'activesupport', ['>= 6.0', '< 7.1']
|
|
23
|
+
spec.add_dependency 'activegraph', '>= 11.0'
|
|
24
|
+
spec.add_dependency 'kaminari', '>= 1.2.1'
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency 'bundler', '>= 2.0'
|
|
27
|
+
spec.add_development_dependency 'rake', '>= 13.0'
|
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
29
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Kaminari
|
|
2
|
+
module ActiveGraph
|
|
3
|
+
module CriteriaMethods
|
|
4
|
+
include Kaminari::PageScopeMethods
|
|
5
|
+
|
|
6
|
+
delegate :model, to: :source
|
|
7
|
+
delegate :default_per_page, :max_per_page, :max_pages, to: :model
|
|
8
|
+
|
|
9
|
+
def entry_name(options = {})
|
|
10
|
+
if model.model_name.respond_to?(:human)
|
|
11
|
+
model.model_name.human(options.merge(default: model.name)).downcase
|
|
12
|
+
else
|
|
13
|
+
model.name.downcase
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def limit_value
|
|
18
|
+
per_page
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def offset_value
|
|
22
|
+
(current_page - 1) * per_page
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def total_count
|
|
26
|
+
total
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Kaminari
|
|
2
|
+
module ActiveGraph
|
|
3
|
+
module Extension
|
|
4
|
+
module QueryMethods
|
|
5
|
+
eval <<-RUBY, binding, __FILE__, __LINE__ + 1
|
|
6
|
+
def #{Kaminari.config.page_method_name}(num = nil)
|
|
7
|
+
Kaminari::ActiveGraph::Paginated.new(self, num)
|
|
8
|
+
end
|
|
9
|
+
RUBY
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module InstanceMethods
|
|
13
|
+
extend ActiveSupport::Concern
|
|
14
|
+
|
|
15
|
+
included do
|
|
16
|
+
include QueryMethods
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module ClassMethods
|
|
21
|
+
extend ActiveSupport::Concern
|
|
22
|
+
|
|
23
|
+
included do
|
|
24
|
+
extend QueryMethods
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Kaminari
|
|
2
|
+
module ActiveGraph
|
|
3
|
+
class Hooks
|
|
4
|
+
def self.init
|
|
5
|
+
::ActiveSupport.on_load(:node) do
|
|
6
|
+
::ActiveGraph::Core::Query.send :include, Kaminari::ActiveGraph::Extension::InstanceMethods
|
|
7
|
+
::ActiveGraph::Node::Query::QueryProxy.send :include, Kaminari::ActiveGraph::Extension::InstanceMethods
|
|
8
|
+
::ActiveGraph::Node.send :include, Kaminari::ActiveGraph::Extension::ClassMethods
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module Kaminari
|
|
2
|
+
module ActiveGraph
|
|
3
|
+
class Paginated
|
|
4
|
+
include Enumerable
|
|
5
|
+
include Kaminari::ActiveGraph::CriteriaMethods
|
|
6
|
+
include Kaminari::ConfigurationMethods::ClassMethods
|
|
7
|
+
|
|
8
|
+
attr_accessor :source, :current_page, :per_page
|
|
9
|
+
|
|
10
|
+
delegate :each, to: :items
|
|
11
|
+
delegate :[], to: :items
|
|
12
|
+
delegate :size, to: :to_a
|
|
13
|
+
|
|
14
|
+
def initialize(source, current_page, per_page = nil)
|
|
15
|
+
self.source = source
|
|
16
|
+
self.current_page = (current_page || 1).to_i
|
|
17
|
+
self.current_page = 1 if self.current_page < 1
|
|
18
|
+
self.per_page = (per_page || default_per_page).to_i
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def total
|
|
22
|
+
source.count
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def items
|
|
26
|
+
@items ||= source.skip((current_page - 1) * per_page).limit(per_page)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def method_missing(name, *args, &block)
|
|
30
|
+
items.respond_to?(name) ? items.send(name, *args, &block) : super
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def respond_to_missing?(name, include_private = false)
|
|
34
|
+
items.respond_to?(name, include_private) || super
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.create_from(source, page, per_page = nil)
|
|
38
|
+
new(source, page, per_page)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def per(num)
|
|
42
|
+
self.class.create_from(source, current_page, num)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def pluck(*args)
|
|
46
|
+
@items = source.pluck(*args)
|
|
47
|
+
self
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def to_ary
|
|
51
|
+
items.to_a
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'kaminari/active_graph/version'
|
|
2
|
+
require 'active_support'
|
|
3
|
+
require 'active_graph'
|
|
4
|
+
require 'kaminari'
|
|
5
|
+
require 'kaminari/models/configuration_methods'
|
|
6
|
+
require 'kaminari/active_graph/criteria_methods'
|
|
7
|
+
require 'kaminari/active_graph/paginated'
|
|
8
|
+
require 'kaminari/active_graph/extension'
|
|
9
|
+
require 'kaminari/active_graph/hooks'
|
|
10
|
+
|
|
11
|
+
Kaminari::ActiveGraph::Hooks.init
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'kaminari/active_graph'
|
metadata
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kaminari-activegraph
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- waynels
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: activesupport
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '6.0'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '7.1'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '6.0'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '7.1'
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: activegraph
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '11.0'
|
|
39
|
+
type: :runtime
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '11.0'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: kaminari
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: 1.2.1
|
|
53
|
+
type: :runtime
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: 1.2.1
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: bundler
|
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '2.0'
|
|
67
|
+
type: :development
|
|
68
|
+
prerelease: false
|
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '2.0'
|
|
74
|
+
- !ruby/object:Gem::Dependency
|
|
75
|
+
name: rake
|
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '13.0'
|
|
81
|
+
type: :development
|
|
82
|
+
prerelease: false
|
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '13.0'
|
|
88
|
+
- !ruby/object:Gem::Dependency
|
|
89
|
+
name: rspec
|
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - "~>"
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '3.0'
|
|
95
|
+
type: :development
|
|
96
|
+
prerelease: false
|
|
97
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - "~>"
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '3.0'
|
|
102
|
+
description: Adds ActiveGraph (Neo4j.rb 11+) support to kaminari
|
|
103
|
+
email:
|
|
104
|
+
- clover_0304@163.com
|
|
105
|
+
executables: []
|
|
106
|
+
extensions: []
|
|
107
|
+
extra_rdoc_files: []
|
|
108
|
+
files:
|
|
109
|
+
- ".gitignore"
|
|
110
|
+
- ".rspec"
|
|
111
|
+
- CHANGELOG.md
|
|
112
|
+
- Gemfile
|
|
113
|
+
- LICENSE.txt
|
|
114
|
+
- README.md
|
|
115
|
+
- Rakefile
|
|
116
|
+
- kaminari-activegraph.gemspec
|
|
117
|
+
- lib/kaminari-activegraph.rb
|
|
118
|
+
- lib/kaminari/active_graph.rb
|
|
119
|
+
- lib/kaminari/active_graph/criteria_methods.rb
|
|
120
|
+
- lib/kaminari/active_graph/extension.rb
|
|
121
|
+
- lib/kaminari/active_graph/hooks.rb
|
|
122
|
+
- lib/kaminari/active_graph/paginated.rb
|
|
123
|
+
- lib/kaminari/active_graph/version.rb
|
|
124
|
+
homepage: https://github.com/waynels/kaminari-activegraph
|
|
125
|
+
licenses:
|
|
126
|
+
- MIT
|
|
127
|
+
metadata: {}
|
|
128
|
+
rdoc_options: []
|
|
129
|
+
require_paths:
|
|
130
|
+
- lib
|
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
|
+
requirements:
|
|
133
|
+
- - ">="
|
|
134
|
+
- !ruby/object:Gem::Version
|
|
135
|
+
version: '2.7'
|
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
|
+
requirements:
|
|
138
|
+
- - ">="
|
|
139
|
+
- !ruby/object:Gem::Version
|
|
140
|
+
version: '0'
|
|
141
|
+
requirements: []
|
|
142
|
+
rubygems_version: 3.7.2
|
|
143
|
+
specification_version: 4
|
|
144
|
+
summary: ActiveGraph support for kaminari
|
|
145
|
+
test_files: []
|