Class: Metry::Storage::PredictableKeyFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/metry/storage.rb

Instance Method Summary collapse

Constructor Details

#initializePredictableKeyFactory

Returns a new instance of PredictableKeyFactory.



116
117
118
# File 'lib/metry/storage.rb', line 116

def initialize
  clear
end

Instance Method Details

#clearObject



137
138
139
# File 'lib/metry/storage.rb', line 137

def clear
  @ids = {:event => 0, :goal => 0, :visitor => 0}
end

#create_pk(row) ⇒ Object



120
121
122
123
124
125
# File 'lib/metry/storage.rb', line 120

def create_pk(row)
  return row if row['_id']
  row.delete('_id')      # in case it exists but the value is nil
  row['_id'] ||= id_for(row).to_s
  row
end

#id_for(row) ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/metry/storage.rb', line 127

def id_for(row)
  if row["event"]
    @ids[:event] += 1
  elsif row["name"] && row["path"]
    @ids[:goal] += 1
  else
    @ids[:visitor] += 1
  end
end