active_hash-kaminari 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6792b1dedba2c63017ec967ce24f3c0a1ca8ead
4
+ data.tar.gz: d7e39441dca1612c29d8bdb2025e75bf44c34213
5
+ SHA512:
6
+ metadata.gz: eb91f05e0e242f6021d76e00cb66c84c2a70741062211702c6342a3ceb54799b14346fd4f21c940315deaeb2499a72521e8dbfefaaa4a5754d28adfa5b6df5d5
7
+ data.tar.gz: 845ae4cf21c0bb4c3c09136a393d721c48051f3698fd5e633032d625256b1553eacca4026d703ea7e7823231291e5e89df21a963fbf175b131e5f4f3c8aa0518
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_hash-kaminari.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 monochromegane
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,57 @@
1
+ # ActiveHash::Kaminari [![Build Status](https://travis-ci.org/monochromegane/active_hash-kaminari.svg?branch=master)](https://travis-ci.org/monochromegane/active_hash-kaminari)
2
+
3
+ ActiveHash::Kaminari provides [Kaminari](https://github.com/amatsuda/kaminari) paginator to [ActiveHash](https://github.com/zilkey/active_hash).
4
+
5
+ ## Usage
6
+
7
+ Just prepend `ActiveHash::Paginatable` module.
8
+
9
+ ```rb
10
+ class Country < ActiveHash::Base
11
+ prepend ActiveHash::Paginatable
12
+ ...
13
+ end
14
+ ```
15
+
16
+ So, ActiveHash class returns `Kaminari::PaginatableArray` instance that provides pagination methods (e.g. `page`, `per` and more page scope methods).
17
+
18
+ ```rb
19
+ Country.all.page(1).per(10)
20
+ ```
21
+
22
+ Of course, you can use this at view.
23
+
24
+ ```rb
25
+ <%= paginate @counties %>
26
+ ```
27
+
28
+ ## Installation
29
+
30
+ Add this line to your application's Gemfile:
31
+
32
+ ```ruby
33
+ gem 'active_hash-kaminari'
34
+ ```
35
+
36
+ And then execute:
37
+
38
+ $ bundle
39
+
40
+ Or install it yourself as:
41
+
42
+ $ gem install active_hash-kaminari
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/monochromegane/active_hash-kaminari.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
57
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -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 'active_hash/kaminari/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_hash-kaminari"
8
+ spec.version = ActiveHash::Kaminari::VERSION
9
+ spec.authors = ["monochromegane"]
10
+ spec.email = ["dev.kuro.obi@gmail.com"]
11
+
12
+ spec.summary = %q{Use kaminari paginator with ActiveHash.}
13
+ spec.description = %q{Use kaminari paginator with ActiveHash.}
14
+ spec.homepage = "https://github.com/monochromegane/active_hash-kaminari"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "active_hash"
23
+ spec.add_dependency "kaminari"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ spec.add_development_dependency "pry"
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_hash/kaminari"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require "active_hash/kaminari/version"
2
+ require "active_hash/paginatable"
3
+
4
+ module ActiveHash
5
+ module Kaminari
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveHash
2
+ module Kaminari
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ module ActiveHash
2
+ module Paginatable
3
+ def self.prepended(base)
4
+ class << base
5
+ self.prepend(ClassMethods)
6
+ end
7
+ end
8
+
9
+ module ClassMethods
10
+ [:find, :all, :where, :method_missing].each do |method|
11
+ define_method(method) do |*args|
12
+ paginatize(super(*args))
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def define_custom_find_all_method(field_name)
19
+ super(field_name)
20
+
21
+ method_name = :"find_all_by_#{field_name}"
22
+ orignal_method_name = :"#{method_name}_org"
23
+
24
+ return if has_singleton_method?(orignal_method_name)
25
+
26
+ the_meta_class.instance_eval do
27
+ alias_method orignal_method_name, method_name
28
+
29
+ define_method(method_name) do |*args|
30
+ paginatize(send(orignal_method_name, *args))
31
+ end
32
+ end
33
+ end
34
+
35
+ def paginatize(ary)
36
+ return ary unless ary.is_a?(Array)
37
+
38
+ ::Kaminari.paginate_array(ary, {
39
+ total_count: ary.count,
40
+ offset: 0,
41
+ limit: ary.count
42
+ })
43
+ end
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_hash-kaminari
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - monochromegane
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: active_hash
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: kaminari
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
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'
97
+ description: Use kaminari paginator with ActiveHash.
98
+ email:
99
+ - dev.kuro.obi@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - active_hash-kaminari.gemspec
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/active_hash/kaminari.rb
114
+ - lib/active_hash/kaminari/version.rb
115
+ - lib/active_hash/paginatable.rb
116
+ homepage: https://github.com/monochromegane/active_hash-kaminari
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.5.1
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Use kaminari paginator with ActiveHash.
140
+ test_files: []