Prefer 1.day
. Open
Rails.cache.fetch(['current_user', object.id, 'created_days'], expires_in: 1.days) do
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for correct grammar when using ActiveSupport's core extensions to the numeric classes.
Example:
# bad
3.day.ago
1.months.ago
# good
3.days.ago
1.month.ago
Do not use to_time
on Date objects, because they know nothing about the time zone in use. Open
((Time.now - object.created_at.to_time)/1.day).round
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for the correct use of Date methods, such as Date.today, Date.current etc.
Using Date.today is dangerous, because it doesn't know anything about Rails time zone. You must use Time.zone.today instead.
The cop also reports warnings when you are using 'to_time' method, because it doesn't know about Rails time zone either.
Two styles are supported for this cop. When EnforcedStyle is 'strict' then the Date methods (today, current, yesterday, tomorrow) are prohibited and the usage of both 'totime' and 'totimeincurrent_zone' is reported as warning.
When EnforcedStyle is 'flexible' then only 'Date.today' is prohibited and only 'to_time' is reported as warning.
Example: EnforcedStyle: strict
# bad
Date.current
Date.yesterday
Date.today
date.to_time
date.to_time_in_current_zone
# good
Time.zone.today
Time.zone.today - 1.day
Example: EnforcedStyle: flexible (default)
# bad
Date.today
date.to_time
# good
Time.zone.today
Time.zone.today - 1.day
Date.current
Date.yesterday
date.to_time_in_current_zone
Surrounding space missing for operator /
. (https://github.com/bbatsov/ruby-style-guide#spaces-operators) Open
((Time.now - object.created_at.to_time)/1.day).round
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks that operators have space around them, except for ** which should not have surrounding space.
Example:
# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b
# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b
Line is too long. [143/120] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
attributes :id, :nickname, :city, :realname, :gender, :birthday, :company, :title, :bio, :avatar_url, :banned, :created_days, :mobile, :email
- Create a ticketCreate a ticket
- Exclude checks
Do not use Time.now
without zone. Use one of Time.zone.now
, Time.current
, Time.now.in_time_zone
, Time.now.utc
, Time.now.getlocal
, Time.now.iso8601
, Time.now.jisx0301
, Time.now.rfc3339
, Time.now.to_i
, Time.now.to_f
instead. (https://github.com/bbatsov/rails-style-guide#time, http://danilenko.org/2012/7/6/rails_timezones) Open
((Time.now - object.created_at.to_time)/1.day).round
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for the use of Time methods without zone.
Built on top of Ruby on Rails style guide (https://github.com/bbatsov/rails-style-guide#time) and the article http://danilenko.org/2012/7/6/rails_timezones/ .
Two styles are supported for this cop. When EnforcedStyle is 'strict' then only use of Time.zone is allowed.
When EnforcedStyle is 'flexible' then it's also allowed to use Time.intimezone.
Example:
# always offense
Time.now
Time.parse('2015-03-02 19:05:37')
# no offense
Time.zone.now
Time.zone.parse('2015-03-02 19:05:37')
# no offense only if style is 'flexible'
Time.current
DateTime.strptime(str, "%Y-%m-%d %H:%M %Z").in_time_zone
Time.at(timestamp).in_time_zone