Skip to content

Commit e2b6a84

Browse files
committed
Install rubocop and fix offenses
Using the rules from the main Rails repository.
1 parent bd22a52 commit e2b6a84

17 files changed

+239
-116
lines changed

.codeclimate.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
engines:
2+
rubocop:
3+
enabled: true
4+
5+
ratings:
6+
paths:
7+
- "**.rb"

.rubocop.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
AllCops:
2+
TargetRubyVersion: 2.2
3+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
4+
# to ignore them, so only the ones explicitly set in this file are enabled.
5+
DisabledByDefault: true
6+
7+
# Prefer &&/|| over and/or.
8+
Style/AndOr:
9+
Enabled: true
10+
11+
# Do not use braces for hash literals when they are the last argument of a
12+
# method call.
13+
Style/BracesAroundHashParameters:
14+
Enabled: true
15+
16+
# Align `when` with `case`.
17+
Style/CaseIndentation:
18+
Enabled: true
19+
20+
# Align comments with method definitions.
21+
Style/CommentIndentation:
22+
Enabled: true
23+
24+
# No extra empty lines.
25+
Style/EmptyLines:
26+
Enabled: true
27+
28+
# In a regular class definition, no empty lines around the body.
29+
Style/EmptyLinesAroundClassBody:
30+
Enabled: true
31+
32+
# In a regular module definition, no empty lines around the body.
33+
Style/EmptyLinesAroundModuleBody:
34+
Enabled: true
35+
36+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
37+
Style/HashSyntax:
38+
Enabled: true
39+
40+
# Method definitions after `private` or `protected` isolated calls need one
41+
# extra level of indentation.
42+
Style/IndentationConsistency:
43+
Enabled: true
44+
EnforcedStyle: rails
45+
46+
# Two spaces, no tabs (for indentation).
47+
Style/IndentationWidth:
48+
Enabled: true
49+
50+
Style/SpaceAfterColon:
51+
Enabled: true
52+
53+
Style/SpaceAfterComma:
54+
Enabled: true
55+
56+
Style/SpaceAroundEqualsInParameterDefault:
57+
Enabled: true
58+
59+
Style/SpaceAroundKeyword:
60+
Enabled: true
61+
62+
Style/SpaceAroundOperators:
63+
Enabled: true
64+
65+
Style/SpaceBeforeFirstArg:
66+
Enabled: true
67+
68+
# Defining a method with parameters needs parentheses.
69+
Style/MethodDefParentheses:
70+
Enabled: true
71+
72+
# Use `foo {}` not `foo{}`.
73+
Style/SpaceBeforeBlockBraces:
74+
Enabled: true
75+
76+
# Use `foo { bar }` not `foo {bar}`.
77+
Style/SpaceInsideBlockBraces:
78+
Enabled: true
79+
80+
# Use `{ a: 1 }` not `{a:1}`.
81+
Style/SpaceInsideHashLiteralBraces:
82+
Enabled: true
83+
84+
Style/SpaceInsideParens:
85+
Enabled: true
86+
87+
# Check quotes usage according to lint rule below.
88+
Style/StringLiterals:
89+
Enabled: true
90+
EnforcedStyle: double_quotes
91+
92+
# Detect hard tabs, no hard tabs.
93+
Style/Tab:
94+
Enabled: true
95+
96+
# Blank lines should not have any spaces.
97+
Style/TrailingBlankLines:
98+
Enabled: true
99+
100+
# No trailing whitespace.
101+
Style/TrailingWhitespace:
102+
Enabled: true
103+
104+
# Use quotes for string literals when they are enough.
105+
Style/UnneededPercentQ:
106+
Enabled: true
107+
108+
# Align `end` with the matching keyword or starting expression except for
109+
# assignments, where it should be aligned with the LHS.
110+
Lint/EndAlignment:
111+
Enabled: true
112+
AlignWith: variable
113+
114+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
115+
Lint/RequireParentheses:
116+
Enabled: true

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

33
gemspec
44

5-
gem 'rails'
5+
gem "rails"
66
gem "mime-types", "< 3"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Installation
99
Add this line to your application's Gemfile:
1010

1111
```ruby
12-
gem 'actionpack-page_caching'
12+
gem "actionpack-page_caching"
1313
```
1414

1515
And then execute:
@@ -62,8 +62,8 @@ and friends:
6262
class WeblogController < ActionController::Base
6363
def update
6464
List.update(params[:list][:id], params[:list])
65-
expire_page action: 'show', id: params[:list][:id]
66-
redirect_to action: 'show', id: params[:list][:id]
65+
expire_page action: "show", id: params[:list][:id]
66+
redirect_to action: "show", id: params[:list][:id]
6767
end
6868
end
6969
```

Rakefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env rake
2-
require 'bundler/gem_tasks'
3-
require 'rake/testtask'
2+
require "bundler/gem_tasks"
3+
require "rake/testtask"
44

55
Rake::TestTask.new do |t|
6-
t.libs = ['test']
7-
t.pattern = 'test/**/*_test.rb'
8-
t.ruby_opts = ['-w']
6+
t.libs = ["test"]
7+
t.pattern = "test/**/*_test.rb"
8+
t.ruby_opts = ["-w"]
99
end
1010

1111
task default: :test

actionpack-page_caching.gemspec

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
# -*- encoding: utf-8 -*-
2-
31
Gem::Specification.new do |gem|
4-
gem.name = 'actionpack-page_caching'
5-
gem.version = '1.0.2'
6-
gem.author = 'David Heinemeier Hansson'
7-
gem.email = 'david@loudthinking.com'
8-
gem.description = 'Static page caching for Action Pack (removed from core in Rails 4.0)'
9-
gem.summary = 'Static page caching for Action Pack (removed from core in Rails 4.0)'
10-
gem.homepage = 'https://github.com/rails/actionpack-page_caching'
11-
gem.license = 'MIT'
2+
gem.name = "actionpack-page_caching"
3+
gem.version = "1.0.2"
4+
gem.author = "David Heinemeier Hansson"
5+
gem.email = "david@loudthinking.com"
6+
gem.description = "Static page caching for Action Pack (removed from core in Rails 4.0)"
7+
gem.summary = "Static page caching for Action Pack (removed from core in Rails 4.0)"
8+
gem.homepage = "https://github.com/rails/actionpack-page_caching"
9+
gem.license = "MIT"
1210

1311
gem.files = `git ls-files`.split($/)
14-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
1513
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16-
gem.require_paths = ['lib']
14+
gem.require_paths = ["lib"]
1715

18-
gem.add_dependency 'actionpack', '>= 4.0.0', '< 5'
16+
gem.add_dependency "actionpack", ">= 4.0.0", "< 5"
1917

20-
gem.add_development_dependency 'mocha'
18+
gem.add_development_dependency "mocha"
2119
end

gemfiles/Gemfile-4-0-stable

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

3-
gemspec path: '..'
3+
gemspec path: ".."
44

5-
gem 'rails', github: 'rails/rails', branch: '4-0-stable'
5+
gem "rails", github: "rails/rails", branch: "4-0-stable"
66
gem "mime-types", "< 3"

gemfiles/Gemfile-4-1-stable

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

3-
gemspec path: '..'
3+
gemspec path: ".."
44

5-
gem 'rails', github: 'rails/rails', branch: '4-1-stable'
5+
gem "rails", github: "rails/rails", branch: "4-1-stable"
66
gem "mime-types", "< 3"

gemfiles/Gemfile-4-2-stable

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

3-
gemspec path: '..'
3+
gemspec path: ".."
44

5-
gem 'rails', github: 'rails/rails', branch: '4-2-stable'
5+
gem "rails", github: "rails/rails", branch: "4-2-stable"
66
gem "mime-types", "< 3"

gemfiles/Gemfile-edge

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

3-
gemspec path: '..'
3+
gemspec path: ".."
44

5-
gem 'rails', github: 'rails/rails', branch: 'master'
5+
gem "rails", github: "rails/rails", branch: "master"

lib/action_controller/caching/pages.rb

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
require 'fileutils'
2-
require 'active_support/core_ext/class/attribute_accessors'
1+
require "fileutils"
2+
require "active_support/core_ext/class/attribute_accessors"
33

44
module ActionController
55
module Caching
@@ -32,8 +32,8 @@ module Caching
3232
# class WeblogController < ActionController::Base
3333
# def update
3434
# List.update(params[:list][:id], params[:list])
35-
# expire_page action: 'show', id: params[:list][:id]
36-
# redirect_to action: 'show', id: params[:list][:id]
35+
# expire_page action: "show", id: params[:list][:id]
36+
# redirect_to action: "show", id: params[:list][:id]
3737
# end
3838
# end
3939
#
@@ -51,7 +51,7 @@ module Pages
5151
# likely require configuring your web server to look in the new location for
5252
# cached files.
5353
class_attribute :page_cache_directory
54-
self.page_cache_directory ||= ''
54+
self.page_cache_directory ||= ""
5555

5656
# The compression used for gzip. If +false+ (default), the page is not compressed.
5757
# If can be a symbol showing the ZLib compression method, for example, <tt>:best_compression</tt>
@@ -63,29 +63,29 @@ module Pages
6363
module ClassMethods
6464
# Expires the page that was cached with the +path+ as a key.
6565
#
66-
# expire_page '/lists/show'
66+
# expire_page "/lists/show"
6767
def expire_page(path)
6868
return unless perform_caching
6969
path = page_cache_path(path)
7070

7171
instrument_page_cache :expire_page, path do
7272
File.delete(path) if File.exist?(path)
73-
File.delete(path + '.gz') if File.exist?(path + '.gz')
73+
File.delete(path + ".gz") if File.exist?(path + ".gz")
7474
end
7575
end
7676

7777
# Manually cache the +content+ in the key determined by +path+.
7878
#
79-
# cache_page "I'm the cached content", '/lists/show'
79+
# cache_page "I'm the cached content", "/lists/show"
8080
def cache_page(content, path, extension = nil, gzip = Zlib::BEST_COMPRESSION)
8181
return unless perform_caching
8282
path = page_cache_path(path, extension)
8383

8484
instrument_page_cache :write_page, path do
8585
FileUtils.makedirs(File.dirname(path))
86-
File.open(path, 'wb+') { |f| f.write(content) }
86+
File.open(path, "wb+") { |f| f.write(content) }
8787
if gzip
88-
Zlib::GzipWriter.open(path + '.gz', gzip) { |f| f.write(content) }
88+
Zlib::GzipWriter.open(path + ".gz", gzip) { |f| f.write(content) }
8989
end
9090
end
9191
end
@@ -109,26 +109,27 @@ def caches_page(*actions)
109109
options = actions.extract_options!
110110

111111
gzip_level = options.fetch(:gzip, page_cache_compression)
112-
gzip_level = case gzip_level
113-
when Symbol
114-
Zlib.const_get(gzip_level.upcase)
115-
when Fixnum
116-
gzip_level
117-
when false
118-
nil
119-
else
120-
Zlib::BEST_COMPRESSION
121-
end
112+
gzip_level = \
113+
case gzip_level
114+
when Symbol
115+
Zlib.const_get(gzip_level.upcase)
116+
when Fixnum
117+
gzip_level
118+
when false
119+
nil
120+
else
121+
Zlib::BEST_COMPRESSION
122+
end
122123

123-
after_filter({only: actions}.merge(options)) do |c|
124+
after_filter({ only: actions }.merge(options)) do |c|
124125
c.cache_page(nil, nil, gzip_level)
125126
end
126127
end
127128

128129
private
129130
def page_cache_file(path, extension)
130-
name = (path.empty? || path == '/') ? '/index' : URI.parser.unescape(path.chomp('/'))
131-
unless (name.split('/').last || name).include? '.'
131+
name = (path.empty? || path == "/") ? "/index" : URI.parser.unescape(path.chomp("/"))
132+
unless (name.split("/").last || name).include? "."
132133
name << (extension || self.default_static_extension)
133134
end
134135
return name
@@ -139,13 +140,13 @@ def page_cache_path(path, extension = nil)
139140
end
140141

141142
def instrument_page_cache(name, path)
142-
ActiveSupport::Notifications.instrument("#{name}.action_controller", path: path){ yield }
143+
ActiveSupport::Notifications.instrument("#{name}.action_controller", path: path) { yield }
143144
end
144145
end
145146

146147
# Expires the page that was cached with the +options+ as a key.
147148
#
148-
# expire_page controller: 'lists', action: 'show'
149+
# expire_page controller: "lists", action: "show"
149150
def expire_page(options = {})
150151
return unless self.class.perform_caching
151152

@@ -166,18 +167,19 @@ def expire_page(options = {})
166167
# the contents of response.body is used. If no options are provided, the url of the current
167168
# request being handled is used.
168169
#
169-
# cache_page "I'm the cached content", controller: 'lists', action: 'show'
170+
# cache_page "I'm the cached content", controller: "lists", action: "show"
170171
def cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION)
171172
return unless self.class.perform_caching && caching_allowed?
172173

173-
path = case options
174+
path = \
175+
case options
174176
when Hash
175177
url_for(options.merge(only_path: true, format: params[:format]))
176178
when String
177179
options
178180
else
179181
request.path
180-
end
182+
end
181183

182184
if (type = Mime::LOOKUP[self.content_type]) && (type_symbol = type.symbol).present?
183185
extension = ".#{type_symbol}"

lib/action_controller/page_caching.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'action_controller/caching/pages'
1+
require "action_controller/caching/pages"
22

33
module ActionController
44
module Caching

lib/actionpack/page_caching.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
require 'actionpack/page_caching/railtie'
1+
require "actionpack/page_caching/railtie"

0 commit comments

Comments
 (0)