nazrin 0.1.1 → 0.2.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 +4 -4
- data/README.md +5 -4
- data/lib/generators/nazrin/templates/nazrin_config.rb +2 -2
- data/lib/nazrin.rb +1 -0
- data/lib/nazrin/active_record/data_accessor.rb +1 -1
- data/lib/nazrin/paginated_array.rb +2 -23
- data/lib/nazrin/pagination_generator.rb +20 -0
- data/lib/nazrin/pagination_generator/kaminari_generator.rb +17 -0
- data/lib/nazrin/pagination_generator/nazrin_generator.rb +13 -0
- data/lib/nazrin/pagination_generator/will_paginate_generator.rb +17 -0
- data/lib/nazrin/version.rb +1 -1
- data/nazrin.gemspec +1 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ee0cd5215a23ea2f245801bf4802248c2ebca11
|
4
|
+
data.tar.gz: bac5d1685ff2d1590cfc18780faecd869c382e58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9348020250c407fc833f22a39446bef81965cf3cbe26de457b18fd5e1d07ff73fcbeada5120b0c6e120e1bc369debb2c5e31475e03708ca98b47585d8a76db1f
|
7
|
+
data.tar.gz: 92c0a290d2e5631eb24dc1b7cd74ed52ba43dd7f5456174648552c584420a2f626f94300adc27155cf120d4b9d3f492b66bee76e4feda08acdd55d8f3e776f06
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ Or install it yourself as:
|
|
31
31
|
```ruby
|
32
32
|
$ bundle exec rails g nazrin:config
|
33
33
|
|
34
|
-
Nazrin.
|
34
|
+
Nazrin.configure do |config|
|
35
35
|
config.debug_mode = false
|
36
36
|
config.search_endpoint = ''
|
37
37
|
config.document_endpoint = ''
|
@@ -44,7 +44,7 @@ end
|
|
44
44
|
```
|
45
45
|
|
46
46
|
```ruby
|
47
|
-
class Post
|
47
|
+
class Post < ActiveRecord::Base
|
48
48
|
include Nazrin::ActiveRecord::Searchable
|
49
49
|
|
50
50
|
searchable do
|
@@ -52,13 +52,14 @@ class Post
|
|
52
52
|
field(:created_at) { created_at.utc.iso8601 }
|
53
53
|
end
|
54
54
|
|
55
|
-
after_create :
|
55
|
+
after_create :add_to_index
|
56
|
+
after_update :update_in_index
|
56
57
|
after_destroy :delete_from_index
|
57
58
|
end
|
58
59
|
```
|
59
60
|
|
60
61
|
```ruby
|
61
|
-
Post.search.size(1).start(0).query("(and 'content')").query_parser('structured').execute
|
62
|
+
Post.search(where: :foo, includes: :bar).size(1).start(0).query("(and 'content')").query_parser('structured').execute
|
62
63
|
=> [#<Post id: 1, content: "content">]
|
63
64
|
```
|
64
65
|
|
@@ -5,6 +5,6 @@ Nazrin.configure do |config|
|
|
5
5
|
config.region = ''
|
6
6
|
config.access_key_id = ''
|
7
7
|
config.secret_access_key = ''
|
8
|
-
# currently support kaminari
|
9
|
-
|
8
|
+
# currently support 'kaminari', 'will_paginate' or 'nazrin'
|
9
|
+
config.pagination = 'kaminari'
|
10
10
|
end
|
data/lib/nazrin.rb
CHANGED
@@ -2,11 +2,11 @@ module Nazrin
|
|
2
2
|
class PaginatedArray < Array
|
3
3
|
attr_reader :current_page, :per_page, :total_count
|
4
4
|
|
5
|
-
def initialize(
|
5
|
+
def initialize(collection, page, per_page, total_count)
|
6
6
|
@current_page = page
|
7
7
|
@per_page = per_page
|
8
8
|
@total_count = total_count
|
9
|
-
replace
|
9
|
+
replace collection
|
10
10
|
end
|
11
11
|
|
12
12
|
# first page of the collections?
|
@@ -39,25 +39,4 @@ module Nazrin
|
|
39
39
|
current_page > total_pages
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
43
|
-
# create paginated collection
|
44
|
-
def self.paginated_array(collections, options = {})
|
45
|
-
if Nazrin.config.pagination == 'kaminari'
|
46
|
-
begin
|
47
|
-
require 'kaminari'
|
48
|
-
rescue LoadError
|
49
|
-
abort "Missing dependency 'kaminari' for pagination"
|
50
|
-
end
|
51
|
-
Kaminari.config.max_pages = options[:last_page]
|
52
|
-
Kaminari.paginate_array(collections, total_count: options[:total_count])
|
53
|
-
.page(options[:current_page])
|
54
|
-
.per(options[:per_page])
|
55
|
-
else
|
56
|
-
Nazrin::PaginatedArray.new(
|
57
|
-
collections,
|
58
|
-
options[:current_page],
|
59
|
-
options[:per_page],
|
60
|
-
options[:total_count])
|
61
|
-
end
|
62
|
-
end
|
63
42
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Nazrin
|
2
|
+
module PaginationGenerator
|
3
|
+
SUPPORTED_PAGINATION_GEMS = %w(nazrin kaminari will_paginate)
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def generate(collection, options = {})
|
7
|
+
abort "#{Nazrin.config.pagination} is not supported gem of pagination" unless SUPPORTED_PAGINATION_GEMS.include?(Nazrin.config.pagination.to_s)
|
8
|
+
|
9
|
+
retreive_generator_module.call(collection, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def retreive_generator_module
|
15
|
+
require "nazrin/pagination_generator/#{Nazrin.config.pagination}_generator"
|
16
|
+
Nazrin::PaginationGenerator.const_get("#{Nazrin.config.pagination.to_s.camelize}Generator")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Nazrin
|
2
|
+
module PaginationGenerator
|
3
|
+
module KaminariGenerator
|
4
|
+
def self.call(collection, options)
|
5
|
+
begin
|
6
|
+
require 'kaminari'
|
7
|
+
rescue LoadError
|
8
|
+
abort "Missing dependency 'kaminari' for pagination"
|
9
|
+
end
|
10
|
+
Kaminari.config.max_pages = options[:last_page]
|
11
|
+
Kaminari.paginate_array(collection, total_count: options[:total_count])
|
12
|
+
.page(options[:current_page])
|
13
|
+
.per(options[:per_page])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Nazrin
|
2
|
+
module PaginationGenerator
|
3
|
+
module WillPaginateGenerator
|
4
|
+
def self.call(collection, options)
|
5
|
+
begin
|
6
|
+
require 'will_paginate/collection'
|
7
|
+
rescue LoadError
|
8
|
+
abort "Missing dependency 'will_paginate' for pagination"
|
9
|
+
end
|
10
|
+
|
11
|
+
WillPaginate::Collection.create(options[:current_page], options[:per_page], options[:total_count]) do |pager|
|
12
|
+
pager.replace collection[pager.offset, pager.per_page].to_a
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/nazrin/version.rb
CHANGED
data/nazrin.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
24
|
spec.add_development_dependency 'rubocop'
|
25
25
|
spec.add_development_dependency 'kaminari'
|
26
|
+
spec.add_development_dependency 'will_paginate'
|
26
27
|
spec.add_development_dependency 'rspec'
|
27
28
|
spec.add_development_dependency 'coveralls'
|
28
29
|
spec.add_development_dependency 'sqlite3'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nazrin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomohiro Suwa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: will_paginate
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rspec
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,6 +188,10 @@ files:
|
|
174
188
|
- lib/nazrin/config.rb
|
175
189
|
- lib/nazrin/document_client.rb
|
176
190
|
- lib/nazrin/paginated_array.rb
|
191
|
+
- lib/nazrin/pagination_generator.rb
|
192
|
+
- lib/nazrin/pagination_generator/kaminari_generator.rb
|
193
|
+
- lib/nazrin/pagination_generator/nazrin_generator.rb
|
194
|
+
- lib/nazrin/pagination_generator/will_paginate_generator.rb
|
177
195
|
- lib/nazrin/search_client.rb
|
178
196
|
- lib/nazrin/version.rb
|
179
197
|
- nazrin.gemspec
|