kaminari-mandatory_ordering 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: 08f862a65011bcd30349ee2d7cf90df4c1805d2e
4
+ data.tar.gz: 70c3466b658d90215de5a5537e1d1af12382642b
5
+ SHA512:
6
+ metadata.gz: cd18bc69cc6844f7c56452ec180a2e04d453312e58ad1179eea67dae42193c1705879d743f47d44ba0b33972db4d9475266c955d311113be9ce8a2bdaaaa4da4
7
+ data.tar.gz: 24be08e162d660a28a264967011a6d1a7ba3184a0a72d26a52457cc4970c534da633633d9c9d42ec54217ccb3d9f6b288b6acac67759ceafe3a5ca3954d67ef9
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
+ /.vscode/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.0
3
+
4
+ Metrics/LineLength:
5
+ Max: 145
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ Style/GuardClause:
11
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kaminari-mandatory_ordering.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Kaminari::MandatoryOrdering
2
+
3
+ Makes sure ActiveRecord collections paged over by `kaminari` are ordered.
4
+
5
+ Forgetting to set order clause when loading records from database in pages can lead to duplicate or missing entries. This gem forces you not to make that mistake.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kaminari-mandatory_ordering'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kaminari-mandatory_ordering
22
+
23
+ ## Usage
24
+
25
+ Look for `Kaminari::MandatoryOrdering::Error` exceptions, add order clauses to queries causing them.
26
+
27
+ Disable (for example, in production environment) by setting `disable_mandatory_ordering = true` value in `kaminari` configuration block.
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tmikoss/kaminari-mandatory_ordering.
38
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'kaminari/mandatory_ordering'
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,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/mandatory_ordering/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kaminari-mandatory_ordering'
8
+ spec.version = Kaminari::MandatoryOrdering::VERSION
9
+ spec.authors = ['Toms Mikoss']
10
+ spec.email = ['toms.mikoss@gmail.com']
11
+
12
+ spec.summary = 'Makes sure ActiveRecord collections paged over by kaminari are ordered'
13
+ spec.homepage = 'https://github.com/tmikoss/kaminari-mandatory_ordering'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = 'exe'
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'kaminari', '>= 1.0'
21
+ spec.add_dependency 'activerecord', '>= 4.0'
22
+ spec.add_dependency 'activesupport', '>= 4.0'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.12'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'rubocop'
28
+ spec.add_development_dependency 'sqlite3', '>= 1.3'
29
+ end
@@ -0,0 +1,22 @@
1
+ require 'kaminari/mandatory_ordering/active_record_model_extension'
2
+
3
+ module Kaminari
4
+ module MandatoryOrdering
5
+ module ActiveRecordExtension
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ descendants.each do |klass|
10
+ klass.send(:prepend, Kaminari::MandatoryOrdering::ActiveRecordModelExtension)
11
+ end
12
+ end
13
+
14
+ module ClassMethods
15
+ def inherited(klass)
16
+ super
17
+ klass.send(:prepend, Kaminari::MandatoryOrdering::ActiveRecordModelExtension)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module Kaminari
2
+ module MandatoryOrdering
3
+ module ActiveRecordModelExtension
4
+ extend ActiveSupport::Concern
5
+
6
+ def self.prepended(klass)
7
+ return if Kaminari.config.disable_mandatory_ordering
8
+
9
+ original = klass.method(Kaminari.config.page_method_name)
10
+
11
+ klass.define_singleton_method(Kaminari.config.page_method_name) do |number|
12
+ if all.values.fetch(:order, []).none?
13
+ raise Kaminari::MandatoryOrdering::Error
14
+ else
15
+ original.call(number)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ module Kaminari
2
+ module MandatoryOrdering
3
+ class Error < RuntimeError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Kaminari
2
+ module MandatoryOrdering
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'kaminari'
2
+ require 'active_support/lazy_load_hooks'
3
+ require 'kaminari/mandatory_ordering/version'
4
+ require 'kaminari/mandatory_ordering/error'
5
+ require 'kaminari/mandatory_ordering/active_record_extension'
6
+
7
+ module Kaminari
8
+ module MandatoryOrdering
9
+ ::ActiveRecord::Base.send :include, Kaminari::MandatoryOrdering::ActiveRecordExtension
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kaminari-mandatory_ordering
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Toms Mikoss
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kaminari
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '1.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '1.3'
125
+ description:
126
+ email:
127
+ - toms.mikoss@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - kaminari-mandatory_ordering.gemspec
142
+ - lib/kaminari/mandatory_ordering.rb
143
+ - lib/kaminari/mandatory_ordering/active_record_extension.rb
144
+ - lib/kaminari/mandatory_ordering/active_record_model_extension.rb
145
+ - lib/kaminari/mandatory_ordering/error.rb
146
+ - lib/kaminari/mandatory_ordering/version.rb
147
+ homepage: https://github.com/tmikoss/kaminari-mandatory_ordering
148
+ licenses: []
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.5.1
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Makes sure ActiveRecord collections paged over by kaminari are ordered
170
+ test_files: []