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 = {}

dashboard =
  Ruote::Dashboard.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 =
%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, #dump, #empty?, #expression_wfids, #find_expressions, #find_root_expression, #find_root_expressions, #get_configuration, #get_engine_variable, #get_msgs, #get_schedules, #get_trackers, #put_engine_variable, #put_msg, #put_schedule, #remove_process, #replace_engine_configuration, #reserve, #worker

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_for(args.first['type']).send(method_name, *args)
    end
  elsif type.is_a?(Fixnum)
    define_method(method_name) do |*args|
      storage_for(args[type]).send(method_name, *args)
    end
  else
    type = type.to_s
    define_method(method_name) do |*args|
      storage_for(type).send(method_name, *args)
    end
  end
end

Instance Method Details

#add_type(type) ⇒ Object

The dilemma for the CompositeStorage with add_type is “to which real storage should the new type get added”. The solution: do nothing.


103
104
# File 'lib/ruote/storage/composite_storage.rb', line 103

def add_type(type)
end