FEATURE: support regex in rake post:remap (#5201)

This commit is contained in:
Kyle Zhao
2017-10-03 20:47:53 -04:00
committed by Sam
parent 4ee2fcd3d5
commit 0342324b47
3 changed files with 76 additions and 22 deletions

View File

@@ -91,6 +91,16 @@ class Post < ActiveRecord::Base
q.order('posts.created_at ASC')
}
scope :raw_match, -> (pattern, type = 'string') {
type = type&.downcase
case type
when 'string'
where('raw ILIKE ?', "%#{pattern}%")
when 'regex'
where('raw ~ ?', pattern)
end
}
delegate :username, to: :user