Skip to content

Commit

Permalink
Add another good example for RelativeDateConstant
Browse files Browse the repository at this point in the history
The current good example seems to discourage the usage of a constant
completely. Add another good example to showcase how to continue using a
constant and have things working dynamically.
  • Loading branch information
ngan committed Dec 14, 2019
1 parent 8dd305c commit 703f18e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/rubocop/cop/rails/relative_date_constant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ module Rails
#
# # good
# class SomeClass
# EXPIRES = 1.week
#
# def self.expired_at
# EXPIRES.since
# end
# end
#
# # good
# class SomeClass
# def self.expired_at
# 1.week.since
# end
Expand Down
9 changes: 9 additions & 0 deletions manual/cops_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,15 @@ class SomeClass
EXPIRED_AT = 1.week.since
end

# good
class SomeClass
EXPIRES = 1.week

def self.expired_at
EXPIRES.since
end
end

# good
class SomeClass
def self.expired_at
Expand Down

0 comments on commit 703f18e

Please sign in to comment.