rubocop-postgresql_cursor 0.0.2

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: d0f03dcc56486d825b1b6456f2b036ab36c0ba55
4
+ data.tar.gz: 34e8cc5c3ecf32effd0c09c408811631746f3be7
5
+ SHA512:
6
+ metadata.gz: 0c69acf7e46f610ce31b198727aae092d6299c0cf09050340c87a7b06a22663988910ae9e4586ee497c545319836fb92c98c96926ec052c87e2341cc83fc2b18
7
+ data.tar.gz: 1a944149b512087c54eb78eef5b2ac18d5c5135f479d5a09068323944a78342aef9db92b066f6711711af4183e5a8bc2acb5269753ae3e28b92e5fd1b77dcf72
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubocop_postgres_cursor.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Tijmen Brommet
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Rubocop - Enforce PostgreSQL Cursor usage
2
+
3
+ Enforces the use of `each_instance` over `find_each`, so that all batching is done with [the postgresql_cursor gem](https://github.com/afair/postgresql_cursor).
4
+
5
+ Supports auto-correct!
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rubocop-postgresql_cursor'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Add the following line to `rubocop.yml`:
20
+
21
+ ```
22
+ require:
23
+ - rubocop-postgresql_cursor
24
+ ```
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( https://github.com/tijmenb/rubocop-postgres_cursor/fork )
29
+ 2. Create your feature branch (`git checkout -b feature/my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin feature/my-new-feature`)
32
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,22 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Rails
4
+ class PostgresqlCursor < Cop
5
+ MSG = 'Prefer `each_instance` over `find_each`.'
6
+
7
+ def on_send(node)
8
+ _receiver, method_name, *_args = *node
9
+ return unless :find_each == method_name
10
+
11
+ add_offense(node, :selector, MSG)
12
+ end
13
+
14
+ def autocorrect(node)
15
+ @corrections << lambda do |corrector|
16
+ corrector.replace(node.loc.selector, 'each_instance')
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module RubocopPostgresqlCursor
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubocop-postgresql_cursor/version'
2
+
3
+ require 'rubocop/cop/rails/postgresql_cursor'
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubocop-postgresql_cursor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubocop-postgresql_cursor"
8
+ spec.version = RubocopPostgresqlCursor::VERSION
9
+ spec.authors = ["tijmen"]
10
+ spec.email = ["tijmen@gmail.com"]
11
+ spec.summary = %q{Enforce usage of each_instance over find_each.}
12
+ spec.description = %q{Enforce usage of the postgresql_cursor gem in Rails
13
+ projects. }
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rubocop', '~> 0.24'
24
+ spec.add_development_dependency 'rake', '~> 10.1'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe RuboCop::Cop::Rails::PostgresqlCursor do
4
+ subject(:cop) { described_class.new }
5
+
6
+ it "registers an offense for find_each" do
7
+ inspect_source_file(cop, "User.find_each { |x| x }")
8
+ expect(cop.offenses.size).to eq(1)
9
+ end
10
+
11
+ it 'auto-corrects to each_instance' do
12
+ new_source = autocorrect_source_file(cop, 'User.find_each')
13
+ expect(new_source).to eq('User.each_instance')
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ # As much as possible, we try to reuse RuboCop's spec environment.
4
+ require File.join(
5
+ Gem::Specification.find_by_name('rubocop').gem_dir, 'spec', 'spec_helper.rb'
6
+ )
7
+
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ require 'rubocop-postgres_cursor'
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-postgresql_cursor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - tijmen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.24'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.24'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: "Enforce usage of the postgresql_cursor gem in Rails\n projects. "
70
+ email:
71
+ - tijmen@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/rubocop-postgresql_cursor.rb
82
+ - lib/rubocop-postgresql_cursor/version.rb
83
+ - lib/rubocop/cop/rails/postgresql_cursor.rb
84
+ - rubocop_postgresql_cursor.gemspec
85
+ - spec/lib/rubocop_postgresql_cursor_spec.rb
86
+ - spec/spec_helper.rb
87
+ homepage: ''
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Enforce usage of each_instance over find_each.
111
+ test_files:
112
+ - spec/lib/rubocop_postgresql_cursor_spec.rb
113
+ - spec/spec_helper.rb
114
+ has_rdoc: