-
-
Save travisdmathis/fc2811bfe8383eecabe7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compare_child_names_to_new_folder_name(folder_name, children) | |
children.each do |child| | |
if folder_name == child.name | |
return false | |
else | |
return true | |
end | |
end | |
end | |
def is_catalog_unique?(catalogs, user, folder_name) | |
folder_name = folder_name.gsub("+", " ") | |
if catalogs.blank? | |
@catalog = user.root_catalog | |
children = @catalog.live_children | |
self.compare_child_names_to_new_folder_name(folder_name, children) | |
else | |
catalogs.each do |catalog_id| | |
@catalog = user.role.catalogs.find_by_id(catalog_id) | |
children = @catalog.live_children | |
self.compare_child_names_to_new_folder_name(folder_name, children) | |
end | |
end | |
end |
beauby
commented
Dec 29, 2014
def is_catalog_unique?(catalogs, user, folder_name)
folder_name = folder_name.gsub("+", " ")
catalogs = if catalogs.blank? then [user.root_catalog] else catalogs.map { |c_id| user.role.catalogs.find_by_id(c_id) } end
catalogs.all? do |catalog|
!catalog.live_children.any? { |child| child == folder_name }
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment