Class: Hexx::Storage::Repositories::SQL

Inherits:
Base
  • Object
show all
Defined in:
lib/hexx/storage/repositories/sql.rb

Overview

Container for the ROM :sql repository settings

Instance Attribute Summary collapse

Attributes inherited from Base

#root

Instance Method Summary collapse

Methods inherited from Base

#[], #keys, #load, #setup

Constructor Details

#initialize(uri:, root: nil, log: nil, **options) ⇒ SQL

Returns a new instance of SQL.



14
15
16
17
18
# File 'lib/hexx/storage/repositories/sql.rb', line 14

def initialize(uri:, root: nil, log: nil, **options)
  @uri     = uri
  @options = options
  super
end

Instance Attribute Details

#migrationsString?

The path to migration directory for the current repository

Returns:

  • (String, nil)


23
24
25
# File 'lib/hexx/storage/repositories/sql.rb', line 23

def migrations
  @migrations
end

#optionsString? (readonly)

The path to migration directory for the current repository

Returns:

  • (String, nil)


23
24
25
# File 'lib/hexx/storage/repositories/sql.rb', line 23

def options
  @options
end

#uriString? (readonly)

The path to migration directory for the current repository

Returns:

  • (String, nil)


23
24
25
# File 'lib/hexx/storage/repositories/sql.rb', line 23

def uri
  @uri
end

Instance Method Details

#adapterSymbol

Returns the name of the adapter

Returns:

  • (Symbol)


61
62
63
# File 'lib/hexx/storage/repositories/sql.rb', line 61

def adapter
  :sql
end

#connSequel::Database

Retuns the Sequel connection for the repository

Returns:

  • (Sequel::Database)


38
39
40
41
42
43
44
# File 'lib/hexx/storage/repositories/sql.rb', line 38

def conn
  @conn ||= begin
    conn = Sequel.connect uri, **options
    conn.loggers << logger
    conn
  end
end

#migratorROM::SQL::Migration::Migrator

Returns the migrator for the repository

Returns:

  • (ROM::SQL::Migration::Migrator)


49
50
51
52
53
54
55
56
# File 'lib/hexx/storage/repositories/sql.rb', line 49

def migrator
  @migrator ||= begin
    rom   = ROM::SQL::Migration::Migrator
    null  = Naught.build { |config| config.impersonate rom }
    klass = migrations ? rom : null
    klass.new conn, path: migrations
  end
end

#settingsArray

Returns the array of settings for the ROM repository

Returns:

  • (Array)


68
69
70
# File 'lib/hexx/storage/repositories/sql.rb', line 68

def settings
  [adapter, (migrations ? [conn, migrator: migrator] : conn)]
end