Sha256: 62b94439b27f2802731192f3f431415f82be7cecd40737b300dff965b6dff19f

Contents?: true

Size: 439 Bytes

Versions: 1

Compression:

Stored size: 439 Bytes

Contents

module Tou
  # 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.
  module Generator
    def self.included(into)
      into.before_validation :generate_and_write_touid!
      super
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tou-0.1.0 lib/tou/generator.rb