Module: Tou::Generator

Defined in:
lib/tou/generator.rb

Overview

When included into an ActiveRecord, will generate a TOU and prefill it into the “id” attribute if it is blank. Add this module to your records to set their IDs using Tou.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(into) ⇒ Object



6
7
8
9
# File 'lib/tou/generator.rb', line 6

def self.included(into)
  into.before_validation :generate_and_write_touid!
  super
end

Instance Method Details

#generate_and_write_touid!Object



11
12
13
# File 'lib/tou/generator.rb', line 11

def generate_and_write_touid!
  write_attribute("id", Tou.uuid) if read_attribute("id").blank?
end