Class: RuoteKit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ruote-kit/configuration.rb

Overview

RuoteKit configuration handling

Defined Under Namespace

Classes: ParticipantRegistrationProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



32
33
34
35
36
# File 'lib/ruote-kit/configuration.rb', line 32

def initialize
  self.work_directory = File.join( Dir.pwd, "work_#{RuoteKit.env}" )
  self.run_engine = true
  self.run_worker = false
end

Instance Attribute Details

#run_engineObject

Whether to run the engine or not (defaults to true)



27
28
29
# File 'lib/ruote-kit/configuration.rb', line 27

def run_engine
  @run_engine
end

#run_workerObject

Whether to run a single worker or not (defaults to false)



30
31
32
# File 'lib/ruote-kit/configuration.rb', line 30

def run_worker
  @run_worker
end

#work_directoryObject

Working directory for the engine (if using file system persistence)



21
22
23
# File 'lib/ruote-kit/configuration.rb', line 21

def work_directory
  @work_directory
end

#workersObject

Number of workers to spawn (1 by default)



24
25
26
# File 'lib/ruote-kit/configuration.rb', line 24

def workers
  @workers
end

Instance Method Details

#do_participant_registrationObject



78
79
80
81
# File 'lib/ruote-kit/configuration.rb', line 78

def do_participant_registration
  return nil unless @participant_registration_block && RuoteKit.engine
  ParticipantRegistrationProxy.instance_eval(&@participant_registration_block)
end

#modeObject

Return the selected ruote-kit mode



39
40
41
# File 'lib/ruote-kit/configuration.rb', line 39

def mode
  @mode ||= :file_system
end

#mode=(mode) ⇒ Object

Set the ruote-kit mode

Raises:

  • (ArgumentError)


44
45
46
47
# File 'lib/ruote-kit/configuration.rb', line 44

def mode=( mode )
  raise ArgumentError, "Unsupported mode (#{mode})" unless [ :transient, :file_system ].include?( mode )
  @mode = mode
end

#register(&block) ⇒ Object



73
74
75
76
# File 'lib/ruote-kit/configuration.rb', line 73

def register &block
  @participant_registration_block = block
  do_participant_registration
end

#set_storage(klass, *args) ⇒ Object

Sets a custom storage



50
51
52
53
# File 'lib/ruote-kit/configuration.rb', line 50

def set_storage( klass, *args )
  @storage = [ klass, args ]
  @mode = :custom
end

#storage_instanceObject

Return the best suited storage class for the current mode



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ruote-kit/configuration.rb', line 56

def storage_instance

  if @storage
    klass, args = @storage
    return klass.new( *args )
  end

  case mode
  when :transient
    require 'ruote/storage/hash_storage'
    Ruote::HashStorage.new
  when :file_system
    require 'ruote/storage/fs_storage'
    Ruote::FsStorage.new( self.work_directory )
  end
end