Class: LB::Persistence

Inherits:
Object
  • Object
show all
Defined in:
lib/lb/persistence.rb,
lib/lb/persistence/types.rb,
lib/lb/persistence/version.rb,
lib/lb/persistence/settings.rb,
lib/lb/persistence/functions.rb,
lib/lb/persistence/relation/joins.rb

Overview

Persistence

Defined Under Namespace

Modules: Functions, Relation, Types Classes: Settings

Constant Summary collapse

VERSION =

Version

'0.3.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Persistence

Returns a new instance of Persistence.



20
21
22
# File 'lib/lb/persistence.rb', line 20

def initialize(settings)
  @settings = settings
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



18
19
20
# File 'lib/lb/persistence.rb', line 18

def settings
  @settings
end

Instance Method Details

#configuration_for(connection) ⇒ ROM::Configuration

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create ROM configuration for given connection or URI

Parameters:

  • (Sequel::Database | String)

Returns:

  • (ROM::Configuration)


99
100
101
# File 'lib/lb/persistence.rb', line 99

def configuration_for(connection)
  ROM::Configuration.new(:sql, connection)
end

#configure_for(connection) ⇒ ROM::Configuration

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Configure ROM for given connection or URI

Parameters:

  • (Sequel::Database | String)

Returns:

  • (ROM::Configuration)


65
66
67
# File 'lib/lb/persistence.rb', line 65

def configure_for(connection)
  configure(configuration_for(connection))
end

#connect(*args) ⇒ Sequel::Database

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Connect to database definied by given URI

Parameters:

  • (String)
  • (Hash)

Returns:

  • (Sequel::Database)


53
54
55
# File 'lib/lb/persistence.rb', line 53

def connect(*args)
  Sequel.connect(*args)
end

#containerROM::Conatainer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get ROM container

Returns:

  • (ROM::Conatainer)


30
31
32
# File 'lib/lb/persistence.rb', line 30

def container
  @container ||= rom_setup(uri)
end

#container_from(config) ⇒ ROM::Container

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create ROM container for given config

Parameters:

  • config (ROM::Configuration)

Returns:

  • (ROM::Container)


87
88
89
# File 'lib/lb/persistence.rb', line 87

def container_from(config)
  ROM.container(config)
end

#repository(repository) ⇒ ROM::Repository

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get ROM Repository instance for Repository class

Returns:

  • (ROM::Repository)


40
41
42
# File 'lib/lb/persistence.rb', line 40

def repository(repository)
  repository.new(container)
end

#uriString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get URI

Returns:

  • (String)


75
76
77
# File 'lib/lb/persistence.rb', line 75

def uri
  @uri ||= settings.database_uri
end