2024-09-10 21:00:40 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Account::AttributionDomains
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
validates :attribution_domains_as_text, domain: { multiline: true }, lines: { maximum: 100 }, if: -> { local? && will_save_change_to_attribution_domains? }
|
|
|
|
end
|
|
|
|
|
|
|
|
def attribution_domains_as_text
|
|
|
|
self[:attribution_domains].join("\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
def attribution_domains_as_text=(str)
|
|
|
|
self[:attribution_domains] = str.split.filter_map do |line|
|
2024-09-13 20:37:15 +09:00
|
|
|
line
|
|
|
|
.strip
|
|
|
|
.delete_prefix('http://')
|
|
|
|
.delete_prefix('https://')
|
|
|
|
.delete_prefix('*.')
|
2024-09-10 21:00:40 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_be_attributed_from?(domain)
|
|
|
|
segments = domain.split('.')
|
|
|
|
variants = segments.map.with_index { |_, i| segments[i..].join('.') }.to_set
|
|
|
|
self[:attribution_domains].to_set.intersect?(variants)
|
|
|
|
end
|
|
|
|
end
|