Module: ActiveRecord::Sixguid::ClassMethods

Defined in:
lib/six-updater-web/vendor/plugins/six-guid/lib/six/guid.rb

Instance Method Summary collapse

Instance Method Details

#six_guid(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/six-updater-web/vendor/plugins/six-guid/lib/six/guid.rb', line 12

def six_guid(options = {})
  class_eval do
    #  set_primary_key options[:column] if options[:column]

    before_create :assign_guid

    # Give this record a guid id.  Public method so people can call it before save if necessary.
    def assign_guid
      unless self.id
        begin
          self.id = UUIDTools::UUID.timestamp_create().to_s
        rescue
          self.id = UUIDTools::UUID.random_create().to_s
        end
      end
    end
  end
end