Skip to content

Commit 0096495

Browse files
added rubocop and some code optimization
1 parent c9183b9 commit 0096495

File tree

14 files changed

+91
-55
lines changed

14 files changed

+91
-55
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@
2929
# Ignore master key for decrypting credentials and more.
3030
/config/master.key
3131
/config/database.yml
32+
.scannerwork
33+
.rubocop.yml
34+
.vscode

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ group :development do
5151
gem 'spring-watcher-listen', '~> 2.0.0'
5252
gem "rename"
5353
gem "letter_opener"
54+
gem 'rubocop'
55+
gem 'rubocop-performance'
5456
end
5557

5658
group :test do
@@ -75,4 +77,4 @@ gem 'jquery-rails'
7577
gem 'bootstrap', '~> 4.1.0'
7678
gem 'active_model_serializers'
7779
gem 'grape-active_model_serializers'
78-
gem "font-awesome-rails"
80+
gem "font-awesome-rails"

Gemfile.lock

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ GEM
5252
archive-zip (0.11.0)
5353
io-like (~> 0.3.0)
5454
arel (9.0.0)
55+
ast (2.4.0)
5556
autoprefixer-rails (8.3.0)
5657
execjs
5758
axiom-types (0.1.1)
@@ -152,6 +153,7 @@ GEM
152153
concurrent-ruby (~> 1.0)
153154
ice_nine (0.11.2)
154155
io-like (0.3.0)
156+
jaro_winkler (1.5.2)
155157
jbuilder (2.7.0)
156158
activesupport (>= 4.2.0)
157159
multi_json (>= 1.2)
@@ -190,6 +192,9 @@ GEM
190192
nokogiri (1.8.2)
191193
mini_portile2 (~> 2.3.0)
192194
orm_adapter (0.5.0)
195+
parallel (1.17.0)
196+
parser (2.6.3.0)
197+
ast (~> 2.4.0)
193198
pg (1.0.0)
194199
popper_js (1.12.9)
195200
pry (0.11.3)
@@ -226,6 +231,7 @@ GEM
226231
method_source
227232
rake (>= 0.8.7)
228233
thor (>= 0.18.1, < 2.0)
234+
rainbow (3.0.0)
229235
rake (12.3.1)
230236
rb-fsevent (0.10.3)
231237
rb-inotify (0.9.10)
@@ -237,6 +243,16 @@ GEM
237243
responders (2.4.0)
238244
actionpack (>= 4.2.0, < 5.3)
239245
railties (>= 4.2.0, < 5.3)
246+
rubocop (0.68.1)
247+
jaro_winkler (~> 1.5.1)
248+
parallel (~> 1.10)
249+
parser (>= 2.5, != 2.5.1.1)
250+
rainbow (>= 2.2.2, < 4.0)
251+
ruby-progressbar (~> 1.7)
252+
unicode-display_width (>= 1.4.0, < 1.6)
253+
rubocop-performance (1.1.0)
254+
rubocop (>= 0.67.0)
255+
ruby-progressbar (1.10.0)
240256
ruby_dep (1.5.0)
241257
ruby_parser (3.11.0)
242258
sexp_processor (~> 4.9)
@@ -282,6 +298,7 @@ GEM
282298
thread_safe (~> 0.1)
283299
uglifier (4.1.10)
284300
execjs (>= 0.3.0, < 3)
301+
unicode-display_width (1.5.0)
285302
virtus (1.0.5)
286303
axiom-types (~> 0.1)
287304
coercible (~> 1.0)
@@ -330,6 +347,8 @@ DEPENDENCIES
330347
puma (~> 3.11)
331348
rails (~> 5.2.0)
332349
rename
350+
rubocop
351+
rubocop-performance
333352
sass-rails (~> 5.0)
334353
selenium-webdriver
335354
spring
@@ -343,4 +362,4 @@ RUBY VERSION
343362
ruby 2.5.1p57
344363

345364
BUNDLED WITH
346-
1.16.2
365+
1.16.6

app/controllers/admin/admins_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
class Admin::AdminsController < Admin::BaseController
2-
32
before_action :set_admin
43

5-
def change_password
6-
end
4+
def change_password; end
75

86
def update_password
97
if @admin.update_with_password(admin_params)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Admin::DashboardController < Admin::BaseController
22
before_action :authenticate_admin!
33

4-
def index
4+
def index
55
@users = User.all
66
end
77
end

app/controllers/api/v1/defaults.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Defaults
99
helpers do
1010
def authenticate!
1111
begin
12-
decoded_token = JWT.decode params[:user][:access_token], Rails.application.credentials.development[:api_hmac_secret], true, { :algorithm => 'HS256' }
12+
JWT.decode params[:user][:access_token], Rails.application.credentials.development[:api_hmac_secret], true, { :algorithm => 'HS256' }
1313
@access_token = AccessToken.where(token: params[:user][:access_token]).first
1414
if @access_token.present?
1515
@current_user = @access_token.user

app/controllers/api/v1/users.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module V1
33
class Users < API::V1::Base
44
include API::V1::Defaults
55

6+
AUTH_DESCRIPTION = "Authorization key".freeze
7+
68
helpers do
79
def generate_access_token_for_user(user_id)
810
@access_token = AccessToken.create(user_id: user_id)
@@ -18,7 +20,7 @@ def logout_from_existing_session(user_id)
1820
desc "Login for user.", {
1921
headers: {
2022
"Authorization" => {
21-
description: "Authorization key",
23+
description: AUTH_DESCRIPTION,
2224
required: true
2325
}
2426
}
@@ -42,7 +44,7 @@ def logout_from_existing_session(user_id)
4244
desc "Signup user", {
4345
headers: {
4446
"Authorization" => {
45-
description: "Authorization key",
47+
description: AUTH_DESCRIPTION,
4648
required: true
4749
}
4850
}
@@ -64,7 +66,7 @@ def logout_from_existing_session(user_id)
6466
desc "Logout user", {
6567
headers: {
6668
"Authorization" => {
67-
description: "Authorization key",
69+
description: AUTH_DESCRIPTION,
6870
required: true
6971
}
7072
}

app/controllers/home_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
class HomeController < ApplicationController
2-
def index
3-
end
2+
def index; end
43
end

app/controllers/users_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class UsersController < ApplicationController
22
before_action :authenticate_user!
33

4-
def show
5-
end
4+
def show; end
65

76
end

config/database.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default: &default
33
host: localhost
44
encoding: utf8
55
username: postgres # Change it to your username
6-
password: 123456 # Change it to your password
6+
password: postgres # Change it to your password
77
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
88
timeout: 5000
99

db/schema.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2018_04_24_083654) do
13+
ActiveRecord::Schema.define(version: 2019_02_18_131410) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -23,6 +23,23 @@
2323
t.datetime "updated_at", null: false
2424
end
2525

26+
create_table "admins", force: :cascade do |t|
27+
t.string "email", default: "", null: false
28+
t.string "encrypted_password", default: "", null: false
29+
t.string "reset_password_token"
30+
t.datetime "reset_password_sent_at"
31+
t.datetime "remember_created_at"
32+
t.integer "sign_in_count", default: 0, null: false
33+
t.datetime "current_sign_in_at"
34+
t.datetime "last_sign_in_at"
35+
t.inet "current_sign_in_ip"
36+
t.inet "last_sign_in_ip"
37+
t.datetime "created_at", null: false
38+
t.datetime "updated_at", null: false
39+
t.index ["email"], name: "index_admins_on_email", unique: true
40+
t.index ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true
41+
end
42+
2643
create_table "users", force: :cascade do |t|
2744
t.string "email", default: "", null: false
2845
t.string "encrypted_password", default: "", null: false

public/404.html

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,36 @@
1818
margin: 4em auto 0;
1919
}
2020

21+
.rails-default-error-page h1 {
22+
font-size: 100%;
23+
color: #730E15;
24+
line-height: 1.5em;
25+
}
26+
2127
.rails-default-error-page div.dialog > div {
22-
border: 1px solid #CCC;
23-
border-right-color: #999;
24-
border-left-color: #999;
2528
border-bottom-color: #BBB;
2629
border-top: #B00100 solid 4px;
2730
border-top-left-radius: 9px;
2831
border-top-right-radius: 9px;
2932
background-color: white;
3033
padding: 7px 12% 0;
31-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32-
}
33-
34-
.rails-default-error-page h1 {
35-
font-size: 100%;
36-
color: #730E15;
37-
line-height: 1.5em;
3834
}
3935

4036
.rails-default-error-page div.dialog > p {
4137
margin: 0 0 1em;
4238
padding: 1em;
4339
background-color: #F7F7F7;
44-
border: 1px solid #CCC;
45-
border-right-color: #999;
46-
border-left-color: #999;
4740
border-bottom-color: #999;
4841
border-bottom-left-radius: 4px;
4942
border-bottom-right-radius: 4px;
5043
border-top-color: #DADADA;
5144
color: #666;
45+
}
46+
47+
.rails-default-error-page div.dialog > div, .rails-default-error-page div.dialog > p {
48+
border: 1px solid #CCC;
49+
border-right-color: #999;
50+
border-left-color: #999;
5251
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
5352
}
5453
</style>

public/422.html

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,36 @@
1818
margin: 4em auto 0;
1919
}
2020

21+
.rails-default-error-page h1 {
22+
font-size: 100%;
23+
color: #730E15;
24+
line-height: 1.5em;
25+
}
26+
2127
.rails-default-error-page div.dialog > div {
22-
border: 1px solid #CCC;
23-
border-right-color: #999;
24-
border-left-color: #999;
2528
border-bottom-color: #BBB;
2629
border-top: #B00100 solid 4px;
2730
border-top-left-radius: 9px;
2831
border-top-right-radius: 9px;
2932
background-color: white;
3033
padding: 7px 12% 0;
31-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32-
}
33-
34-
.rails-default-error-page h1 {
35-
font-size: 100%;
36-
color: #730E15;
37-
line-height: 1.5em;
3834
}
3935

4036
.rails-default-error-page div.dialog > p {
4137
margin: 0 0 1em;
4238
padding: 1em;
4339
background-color: #F7F7F7;
44-
border: 1px solid #CCC;
45-
border-right-color: #999;
46-
border-left-color: #999;
4740
border-bottom-color: #999;
4841
border-bottom-left-radius: 4px;
4942
border-bottom-right-radius: 4px;
5043
border-top-color: #DADADA;
5144
color: #666;
45+
}
46+
47+
.rails-default-error-page div.dialog > div, .rails-default-error-page div.dialog > p {
48+
border: 1px solid #CCC;
49+
border-right-color: #999;
50+
border-left-color: #999;
5251
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
5352
}
5453
</style>

public/500.html

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,36 @@
1818
margin: 4em auto 0;
1919
}
2020

21+
.rails-default-error-page h1 {
22+
font-size: 100%;
23+
color: #730E15;
24+
line-height: 1.5em;
25+
}
26+
2127
.rails-default-error-page div.dialog > div {
22-
border: 1px solid #CCC;
23-
border-right-color: #999;
24-
border-left-color: #999;
2528
border-bottom-color: #BBB;
2629
border-top: #B00100 solid 4px;
2730
border-top-left-radius: 9px;
2831
border-top-right-radius: 9px;
2932
background-color: white;
3033
padding: 7px 12% 0;
31-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32-
}
33-
34-
.rails-default-error-page h1 {
35-
font-size: 100%;
36-
color: #730E15;
37-
line-height: 1.5em;
3834
}
3935

4036
.rails-default-error-page div.dialog > p {
4137
margin: 0 0 1em;
4238
padding: 1em;
4339
background-color: #F7F7F7;
44-
border: 1px solid #CCC;
45-
border-right-color: #999;
46-
border-left-color: #999;
4740
border-bottom-color: #999;
4841
border-bottom-left-radius: 4px;
4942
border-bottom-right-radius: 4px;
5043
border-top-color: #DADADA;
5144
color: #666;
45+
}
46+
47+
.rails-default-error-page div.dialog > div, .rails-default-error-page div.dialog > p {
48+
border: 1px solid #CCC;
49+
border-right-color: #999;
50+
border-left-color: #999;
5251
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
5352
}
5453
</style>

0 commit comments

Comments
 (0)