mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-03 02:21:33 +00:00
Improve concern syntax and definition
This commit is contained in:
@@ -8,11 +8,9 @@
|
||||
# This may become obsolete with Spree 2.3.
|
||||
# https://github.com/spree/spree/commits/master/core/lib/spree/core/permalinks.rb
|
||||
module PermalinkGenerator
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
end
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
class_methods do
|
||||
def find_available_value(existing, requested)
|
||||
return requested unless existing.include?(requested)
|
||||
|
||||
@@ -25,6 +23,8 @@ module PermalinkGenerator
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_unique_permalink(requested)
|
||||
existing = others.where("permalink LIKE ?", "#{requested}%").pluck(:permalink)
|
||||
self.class.find_available_value(existing, requested)
|
||||
|
||||
Reference in New Issue
Block a user