Class: Land::Attribution

Inherits:
ApplicationRecord show all
Includes:
TableName
Defined in:
app/models/land/attribution.rb

Constant Summary collapse

KEYS =
%w[
  ad_type
  ad_group
  affiliate
  app
  bid_match_type
  brand
  campaign
  content
  creative
  device_type
  experiment
  keyword
  match_type
  medium
  network
  placement
  position
  search_term
  source
  subsource
  target
]

Class Method Summary collapse

Class Method Details

.digest(params) ⇒ Object



58
59
60
# File 'app/models/land/attribution.rb', line 58

def digest(params)
  Digest::SHA2.base64digest transform(params).values.map(&:name).sort.join("\n")
end

.lookup(params) ⇒ Object



52
53
54
55
56
# File 'app/models/land/attribution.rb', line 52

def lookup(params)
  where(transform(params)).first_or_create
rescue ActiveRecord::RecordNotUnique
  retry
end

.transform(params) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/land/attribution.rb', line 40

def transform(params)
  hash = params.slice(*KEYS)

  filter = {}

  hash.each do |k, v|
    filter[k.foreign_key] = "Land::#{k.classify}".constantize[v]
  end

  filter
end