Sha256: d11ce23be2b3a2129a3a3a6579ede355f3192a536d4f666a1844a82b99d30b10

Contents?: true

Size: 609 Bytes

Versions: 1

Compression:

Stored size: 609 Bytes

Contents

# Store the relationship between UUID and ActiveRecord instance
class Uuidify::Uuid < ActiveRecord::Base
  if Rails::VERSION::MAJOR == 3
    attr_accessible :model_name, :model_id, :model_uuid
  end

  def self.uuid_storage_type
    connection.adapter_name == "PostgreSQL" ? :string : :binary
  end
  
  def self.uuid_to_sql_string uuid
    if uuid_storage_type == :string
      uuid.to_s
    else
      uuid.raw
    end
  end

  def self.uuid_from_sql_string string
    if uuid_storage_type == :string
      UUIDTools::UUID.parse(string)
    else
      UUIDTools::UUID.parse_raw(string)
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uuidify-0.5.0 app/models/uuidify/uuid.rb