Avoid "Overwriting existing method open" warning

In Ruby, the Kernel class defined the `open` method, which is available
for (almost) every object. So creating a scope with the name `open`
generates a warning indicating we are overwriting the existing `open`
method.

While this warning is pretty much harmless and we could ignore it, it
generates a lot of noise in the logs. So I'm "undefining" the method
before generating the scope, so we don't get the warning all the time.
This commit is contained in:
Javi Martín
2019-10-23 18:05:25 +02:00
parent 26e050b9f2
commit 69e3e67c85
2 changed files with 2 additions and 0 deletions

View File

@@ -55,6 +55,7 @@ class Budget < ApplicationRecord
scope :reviewing_ballots, -> { where(phase: "reviewing_ballots") } scope :reviewing_ballots, -> { where(phase: "reviewing_ballots") }
scope :finished, -> { where(phase: "finished") } scope :finished, -> { where(phase: "finished") }
class << self; undef :open; end
scope :open, -> { where.not(phase: "finished") } scope :open, -> { where.not(phase: "finished") }
def self.current def self.current

View File

@@ -54,6 +54,7 @@ class Legislation::Process < ApplicationRecord
validates :background_color, format: { allow_blank: true, with: CSS_HEX_COLOR } validates :background_color, format: { allow_blank: true, with: CSS_HEX_COLOR }
validates :font_color, format: { allow_blank: true, with: CSS_HEX_COLOR } validates :font_color, format: { allow_blank: true, with: CSS_HEX_COLOR }
class << self; undef :open; end
scope :open, -> { where("start_date <= ? and end_date >= ?", Date.current, Date.current) } scope :open, -> { where("start_date <= ? and end_date >= ?", Date.current, Date.current) }
scope :active, -> { where("end_date >= ?", Date.current) } scope :active, -> { where("end_date >= ?", Date.current) }
scope :past, -> { where("end_date < ?", Date.current) } scope :past, -> { where("end_date < ?", Date.current) }