Class: PgHaMigrations::Extension

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_ha_migrations/extension.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Extension

Returns a new instance of Extension.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/pg_ha_migrations/extension.rb', line 5

def initialize(name)
  @name = name

  @schema, @version = ActiveRecord::Base.connection.select_rows(<<~SQL).first
    SELECT nspname, extversion
    FROM pg_namespace JOIN pg_extension
      ON pg_namespace.oid = pg_extension.extnamespace
    WHERE pg_extension.extname = #{ActiveRecord::Base.connection.quote(name)}
    LIMIT 1
  SQL
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/pg_ha_migrations/extension.rb', line 3

def name
  @name
end

#schemaObject (readonly)

Returns the value of attribute schema.



3
4
5
# File 'lib/pg_ha_migrations/extension.rb', line 3

def schema
  @schema
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/pg_ha_migrations/extension.rb', line 3

def version
  @version
end

Instance Method Details

#installed?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/pg_ha_migrations/extension.rb', line 31

def installed?
  !!schema && !!version
end

#major_versionObject



23
24
25
26
27
28
29
# File 'lib/pg_ha_migrations/extension.rb', line 23

def major_version
  return unless version

  Gem::Version.new(version)
    .segments
    .first
end

#quoted_schemaObject



17
18
19
20
21
# File 'lib/pg_ha_migrations/extension.rb', line 17

def quoted_schema
  return unless schema

  PG::Connection.quote_ident(schema)
end