Class: Metry::Storage::PredictableKeyFactory
- Inherits:
-
Object
- Object
- Metry::Storage::PredictableKeyFactory
- Defined in:
- lib/metry/storage.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #create_pk(row) ⇒ Object
- #id_for(row) ⇒ Object
-
#initialize ⇒ PredictableKeyFactory
constructor
A new instance of PredictableKeyFactory.
Constructor Details
#initialize ⇒ PredictableKeyFactory
Returns a new instance of PredictableKeyFactory.
104 105 106 |
# File 'lib/metry/storage.rb', line 104 def initialize clear end |
Instance Method Details
#clear ⇒ Object
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 |