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.

Constant Summary collapse

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

#dirty_attribute_strategyObject

The dirty-attribute strategy decides how object modification is detected to avoid saved unmodified object.



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

def dirty_attribute_strategy
  @dirty_attribute_strategy
end

Class Method Details

.base_moduleModule

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

.const_missing(name) ⇒ Object



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

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

Instance Method Details

#base_moduleObject



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

def base_module
  self.class.base_module
end

#create_session(*params) ⇒ Object

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

#transactionObject

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

#with_session(*params) {|session| ... } ⇒ Object

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