Module: AR::UUID::Utils

Defined in:
lib/ar/uuid/utils.rb

Constant Summary collapse

EXTENSIONS_SQL =
"select\n  extname\nfrom pg_extension\nwhere\n  extname in ('uuid-ossp', 'pgcrypto')\norder by 1\nlimit 1\n"
FUNCTION_NAMES =

rubocop:disable Style/MutableConstant

{ # rubocop:disable Style/MutableConstant
  "uuid-ossp" => "uuid_generate_v4()",
  "pgcrypto" => "gen_random_uuid()"
}

Class Method Summary collapse

Class Method Details

.belongs_to_required_by_defaultObject



42
43
44
45
46
47
48
# File 'lib/ar/uuid/utils.rb', line 42

def self.belongs_to_required_by_default
  if ::ActiveRecord::Base.respond_to?(:belongs_to_required_by_default)
    ::ActiveRecord::Base.belongs_to_required_by_default
  else
    false
  end
end

.uuid_default_functionObject



38
39
40
# File 'lib/ar/uuid/utils.rb', line 38

def self.uuid_default_function
  FUNCTION_NAMES.fetch(uuid_extname)
end

.uuid_extnameObject



30
31
32
33
34
35
36
# File 'lib/ar/uuid/utils.rb', line 30

def self.uuid_extname
  connection = ::ActiveRecord::Base.connection
  result = connection.execute(EXTENSIONS_SQL).first
  raise MissingExtensionError unless result

  result.fetch("extname")
end