Sha256: 4d36ba57c5351cdc7a90bdb4475c04ea9b5fb9cea545e212580ef0e04237f59e

Contents?: true

Size: 644 Bytes

Versions: 1

Compression:

Stored size: 644 Bytes

Contents

module ActiveRecordUUID

  module ActiveRecord
    def pk_uuid
      self.primary_key = :id
      self.sequence_name = nil
      before_create do
        self.id = ActiveRecordUUID.random unless self.id
      end
    end

    def attr_uuid(name)
      before_create do
        self.send("#{name}=", ActiveRecordUUID.random) unless self.send("#{name}")
      end
    end
  end

  module TableDefinition
    def uuid(name, options={})
      @columns.delete @columns_hash.delete('id') if options[:primary_key]
      column(name, :string, limit: 36, null: options[:null] || !options[:primary_key], primary: options[:primary_key])
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord_uuid-0.0.2 lib/activerecord_uuid/active_record_extension.rb