Class: Ruote::CompositeStorage

Inherits:
Object
  • Object
show all
Includes:
StorageBase
Defined in:
lib/ruote/storage/composite_storage.rb

Overview

This storage allows for mixing of storage implementation or simply mixing of storage physical backend.

opts = {}

engine =
  Ruote::Engine.new(
    Ruote::Worker.new(
      Ruote::CompositeStorage.new(
        Ruote::FsStorage.new('ruote_work', opts),
        'msgs' => Ruote::HashStorage.new(opts))))

In this example, everything goes to the FsStorage, except the messages (msgs) that go to an in-memory storage.

Constant Summary collapse

TYPES =

def add_type (type) end

%w[
  variables
  msgs
  expressions
  errors
  schedules
  configurations
  workitems
]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StorageBase

#clear, #context, #context=, #copy_to, #delete_schedule, #empty?, #expression_wfids, #find_root_expression, #get_configuration, #get_engine_variable, #get_msgs, #get_schedules, #get_trackers, #put_engine_variable, #put_msg, #put_schedule, #replace_engine_configuration, #reserve

Constructor Details

#initialize(default_storage, storages) ⇒ CompositeStorage

Returns a new instance of CompositeStorage.



50
51
52
53
54
# File 'lib/ruote/storage/composite_storage.rb', line 50

def initialize(default_storage, storages)

  @default_storage = default_storage
  @storages = storages
end

Class Method Details

.delegate(method_name, type = nil) ⇒ Object

A class method ‘delegate’, to tell this storage how to deal with each method composing a storage.

Followed by a list of ‘delegations’.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ruote/storage/composite_storage.rb', line 61

def self.delegate(method_name, type=nil)

  if type == nil
    define_method(method_name) do |*args|
      storage(args.first['type']).send(method_name, *args)
    end
  elsif type.is_a?(Fixnum)
    define_method(method_name) do |*args|
      storage(args[type]).send(method_name, *args)
    end
  else
    type = type.to_s
    define_method(method_name) do |*args|
      storage(type).send(method_name, *args)
    end
  end
end