From 703f18ef656d76907c92c9a664747c605a2fbe3c Mon Sep 17 00:00:00 2001 From: Ngan Pham Date: Fri, 13 Dec 2019 20:00:04 -0800 Subject: [PATCH] Add another good example for RelativeDateConstant 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. --- lib/rubocop/cop/rails/relative_date_constant.rb | 9 +++++++++ manual/cops_rails.md | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/rubocop/cop/rails/relative_date_constant.rb b/lib/rubocop/cop/rails/relative_date_constant.rb index e0d708772a..cbb2451933 100644 --- a/lib/rubocop/cop/rails/relative_date_constant.rb +++ b/lib/rubocop/cop/rails/relative_date_constant.rb @@ -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 diff --git a/manual/cops_rails.md b/manual/cops_rails.md index e26535346a..ec7388ffbf 100644 --- a/manual/cops_rails.md +++ b/manual/cops_rails.md @@ -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