Skip to content

Commit e007cd7

Browse files
committed
Code style for models
1 parent db88871 commit e007cd7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+628
-651
lines changed

app/models/ability.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# CanCan ability definitions.
24
#
35
# See: https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities

app/models/action_token.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'securerandom'
24

35
# Each user may have 0..1 password reset keys.
@@ -12,13 +14,13 @@ class ActionToken < ActiveRecord::Base
1214

1315
before_create :randomize_token
1416

15-
enum action: [:confirm_email, :reset_password, :enroll_course]
17+
enum action: %i[confirm_email reset_password enroll_course]
1618

1719
def self.generate_password_reset_key_for(user)
1820
old_key = user.password_reset_key
19-
old_key.destroy if old_key
21+
old_key&.destroy
2022

21-
key = self.create!(user: user, action: :reset_password, expires_at: Time.now + 72.hours)
23+
key = create!(user: user, action: :reset_password, expires_at: Time.now + 72.hours)
2224
user.action_tokens << key
2325
key
2426
end

app/models/api_version.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ApiVersion
24
API_VERSION = 7 # To be incremented on BC-breaking changes
35
end

app/models/assistantship.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Assistantship < ActiveRecord::Base
24
belongs_to :user
35
belongs_to :course

app/models/available_point.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Caches points that can be awarded from an exercise.
24
# Awarded points don't have a hard reference to these because
35
# these are recreated every time a course is refreshed.
@@ -7,8 +9,8 @@ class AvailablePoint < ActiveRecord::Base
79
include Swagger::Blocks
810

911
swagger_schema :AvailablePoint do
10-
key :required, [
11-
:id, :exercise_id, :name, :require_review
12+
key :required, %i[
13+
id exercise_id name require_review
1214
]
1315

1416
property :id, type: :integer, example: 1

app/models/awarded_point.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Stores when a point (course_id, name) has been awared to a particular user.
24
#
35
# There is a reference to the submission that first awarded the point, but this
@@ -8,7 +10,7 @@ class AwardedPoint < ActiveRecord::Base
810
include Swagger::Blocks
911

1012
swagger_schema :AwardedPoint do
11-
key :required, [:id, :course_id, :user_id, :submission_id, :name, :created_at]
13+
key :required, %i[id course_id user_id submission_id name created_at]
1214

1315
property :id, type: :integer, example: 1
1416
property :course_id, type: :integer, example: 1
@@ -19,18 +21,18 @@ class AwardedPoint < ActiveRecord::Base
1921
end
2022

2123
def point_as_json
22-
as_json only: [
23-
:id,
24-
:course_id,
25-
:user_id,
26-
:submission_id,
27-
:name,
28-
:created_at
24+
as_json only: %i[
25+
id
26+
course_id
27+
user_id
28+
submission_id
29+
name
30+
created_at
2931
]
3032
end
3133

3234
swagger_schema :AwardedPointWithExerciseId do
33-
key :required, [:awarded_point, :exercise_id]
35+
key :required, %i[awarded_point exercise_id]
3436

3537
property :awarded_point do
3638
key :"$ref", :AwardedPoint

app/models/certificate.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Certificate < ActiveRecord::Base
24
belongs_to :user
35
belongs_to :course
@@ -35,8 +37,7 @@ def generate
3537
margin_bottom: '0.20in',
3638
margin_left: '0.20in',
3739
image_quality: 100,
38-
image_dpi: 300,
39-
).to_pdf
40+
image_dpi: 300).to_pdf
4041
end
4142

4243
def path

app/models/comet_server.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'rest_client'
24

35
# Represents the configured tmc-comet server.
@@ -32,7 +34,7 @@ def client_url
3234
def try_publish(channel, msg)
3335
publish(channel, msg)
3436
true
35-
rescue
37+
rescue StandardError
3638
::Rails.logger.error "Failed to publish to #{publish_url}: #{$!}"
3739
false
3840
end

app/models/comment.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Comment < ActiveRecord::Base
24
belongs_to :user
35
belongs_to :submission

0 commit comments

Comments
 (0)