cartodb/app/models/visualization/name_checker.rb

24 lines
471 B
Ruby
Raw Normal View History

2020-06-15 10:58:47 +08:00
require_relative './collection'
module CartoDB
module Visualization
class NameChecker
def initialize(user)
@user = user
end
def available?(candidate)
!taken_names_for.include?(candidate)
end
private
def taken_names_for
@taken_names ||= Carto::Visualization::where(user_id: user.id).select(:name).map(&:name)
end
attr_reader :user
end # NameChecker
end # Visualization
end # CartoDB