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.



104
105
106
# File 'lib/metry/storage.rb', line 104

def initialize
  clear
end

Instance Method Details

#clearObject



125
126
127
# File 'lib/metry/storage.rb', line 125

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

#create_pk(row) ⇒ Object



108
109
110
111
112
113
# File 'lib/metry/storage.rb', line 108

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



115
116
117
118
119
120
121
122
123
# File 'lib/metry/storage.rb', line 115

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