Module: Diametric::Persistence

Defined in:
lib/diametric/persistence.rb,
lib/diametric/persistence/rest.rb,
lib/diametric/persistence/peer.rb,
lib/diametric/persistence/common.rb,
lib/diametric/persistence/function.rb,
lib/diametric/persistence/rest_function.rb,
lib/diametric/persistence/peer_function.rb

Overview

Persistence is the main entry point for adding persistence to your diametric entities.

Defined Under Namespace

Modules: Common, Peer, PeerFunction, REST, RestFunction Classes: Function

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.conn_typeObject (readonly)

Returns the value of attribute conn_type


4
5
6
# File 'lib/diametric/persistence.rb', line 4

def conn_type
  @conn_type
end

Class Method Details

.establish_base_connection(options) ⇒ Object

Establish a base connection for your application that is used unless specified otherwise. This method can establish connections in either REST or peer mode, depending on the supplied options.

Examples:

Connecting in peer-mode (JRuby required)

Diametric::Persistence.establish_base_connection({:uri => "datomic:free://localhost:4334/my-db"})

Connecting in REST-mode

Diametric::Persistence.establish_base_connection({:uri      => "http://localhost:9000/",
                                                  :database => "my-db",
                                                  :storage  => "my-dbalias"})

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

def self.establish_base_connection(options)
  @_persistence_class = persistence_class(options[:uri])
  @_persistence_class.connect(options)
end

.included(base) ⇒ Object

Including Diametric::Persistence after establishing a base connection will include the appropriate Persistence class (REST or Peer)


24
25
26
# File 'lib/diametric/persistence.rb', line 24

def self.included(base)
  base.send(:include, @_persistence_class) if @_persistence_class
end

.peer?Boolean


28
29
30
# File 'lib/diametric/persistence.rb', line 28

def self.peer?
  @conn_type == :peer
end

.rest?Boolean


32
33
34
# File 'lib/diametric/persistence.rb', line 32

def self.rest?
  @conn_type == :rest
end