Class: Lims::Core::Persistence::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/lims-core/persistence/store.rb

Overview

A store represents a persistent datastore, where object can be saved and restored. A connection to a database, for example.

Direct Known Subclasses

Logger::Store, Lims::Core::Persistence::Sequel::Store

Constant Summary

DIRTY_ATTRIBUTE_STRATEGY_DEEP_COPY =
1
DIRTY_ATTRIBUTE_STRATEGY_SHA1 =
2
DIRTY_ATTRIBUTE_STRATEGY_MD5 =
3
DIRTY_ATTRIBUTE_STRATEGY_QUICK_HASH =
4

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) dirty_attribute_strategy

Returns the value of attribute dirty_attribute_strategy



19
20
21
# File 'lib/lims-core/persistence/store.rb', line 19

def dirty_attribute_strategy
  @dirty_attribute_strategy
end

Class Method Details

+ (Module) base_module

Retrieves the effective module of a class Useful to call "sibling" classes.

Examples:

class Sequel::Store < Store
  def session
     base_module::Session
end

session will return a Sequel::Session instead of a ::Session.

Returns:

  • (Module)


37
38
39
40
41
42
# File 'lib/lims-core/persistence/store.rb', line 37

def self.base_module
  @base_module ||= begin
                    base_name = name.sub(/::\w+$/, '')
                    constant(base_name)
                  end
end

+ (Object) const_missing(name)



12
13
14
# File 'lib/lims-core/persistence/store.rb', line 12

def self.const_missing(name)
  super(name)
end

Instance Method Details

- (Object) base_module



43
44
45
# File 'lib/lims-core/persistence/store.rb', line 43

def base_module
  self.class.base_module
end

- (Object) create_session(*params)

Create a session If a session is given a parameter return in instead of creating a new one.



60
61
62
63
# File 'lib/lims-core/persistence/store.rb', line 60

def create_session(*params)
  return params.first if(params.size >= 1 && params.first.is_a?(Session))
  base_module::Session.new(self, *params)
end

- (Object) transaction

Execute given block within a transaction If it make sense.



67
68
69
# File 'lib/lims-core/persistence/store.rb', line 67

def transaction
  yield
end

- (Object) with_session(*params) {|session| ... }

Create a session and pass it to the block. This is the only way to get a session.

Parameters:

Yield Parameters:

  • session (Session)

    the created session.

Returns:

  • the value of the block



52
53
54
# File 'lib/lims-core/persistence/store.rb', line 52

def with_session(*params, &block)
  create_session(*params).with_session(&block)
end