2019-07-30 21:29:24 +00:00
# frozen_string_literal: true
2020-06-12 20:03:43 +00:00
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
2018-03-25 17:30:42 +00:00
class SlugCopyNamingAlgorithm < CopyNamingAlgorithm
attr_accessor :klass , :nonprofit_id
# @param [Class] klass
def initialize ( klass , nonprofit_id )
2019-07-30 21:29:24 +00:00
@klass = klass
@nonprofit_id = nonprofit_id
2018-03-25 17:30:42 +00:00
end
def copy_addition
2019-07-30 21:29:24 +00:00
'_copy'
2018-03-25 17:30:42 +00:00
end
def max_copies
30
end
def get_name_for_entity ( name_entity )
name_entity . slug
end
def get_already_used_name_entities ( base_name )
2019-07-30 21:29:24 +00:00
end_name = '\\_copy\\_\\d{2}'
2018-03-25 17:30:42 +00:00
@klass . method ( :where ) . call ( 'slug SIMILAR TO ? AND nonprofit_id = ? AND (deleted IS NULL OR deleted = false)' , base_name + end_name , nonprofit_id ) . select ( 'slug' )
end
2019-07-30 21:29:24 +00:00
end