Class: Bumbleworks::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/bumbleworks/configuration.rb

Overview

Stores configuration information

Configuration information is loaded from a configuration block defined within the client application.

Examples:

Standard settings

Bumbleworks.configure do |c|
  c.definitions_directory = '/path/to/ruote/definitions/directory'
  c.storage = Redis.new(:host => '127.0.0.1', :db => 0, :thread_safe => true)
  # ...
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



148
149
150
151
152
# File 'lib/bumbleworks/configuration.rb', line 148

def initialize
  @storage_adapters = []
  @storage_options = {}
  @timeout ||= 5
end

Instance Attribute Details

#storage_adaptersObject (readonly)

Returns the value of attribute storage_adapters.



15
16
17
# File 'lib/bumbleworks/configuration.rb', line 15

def storage_adapters
  @storage_adapters
end

Class Method Details

.define_setting(name) ⇒ Object



18
19
20
21
# File 'lib/bumbleworks/configuration.rb', line 18

def define_setting(name)
  defined_settings << name
  attr_accessor name
end

.defined_settingsObject



23
24
25
# File 'lib/bumbleworks/configuration.rb', line 23

def defined_settings
  @defined_settings ||= []
end

Instance Method Details

#add_storage_adapter(adapter) ⇒ Object

Add a storage adapter to the set of possible adapters. Takes an object that responds to ‘driver`, `use?`, `storage_class`, and `display_name`.

Raises:

  • (ArgumentError)


209
210
211
212
213
214
215
# File 'lib/bumbleworks/configuration.rb', line 209

def add_storage_adapter(adapter)
  raise ArgumentError, "#{adapter} is not a Bumbleworks storage adapter" unless
    [:driver, :use?, :new_storage, :allow_history_storage?, :storage_class, :display_name].all? { |m| adapter.respond_to?(m) }

  @storage_adapters << adapter
  @storage_adapters
end

#clear!Object

Clears all memoize variables and configuration settings



242
243
244
245
246
# File 'lib/bumbleworks/configuration.rb', line 242

def clear!
  defined_settings.each {|setting| instance_variable_set("@#{setting}", nil)}
  @storage_adapters = []
  @definitions_folder = @participants_folder = @tasks_folder = nil
end

#definitions_directoryObject

Path where Bumbleworks will look for ruote process defintiions to load. The path can be relative or absolute. Relative paths are relative to Bumbleworks.root.



158
159
160
# File 'lib/bumbleworks/configuration.rb', line 158

def definitions_directory
  @definitions_folder ||= default_definition_directory
end

#error_handlersObject



248
249
250
# File 'lib/bumbleworks/configuration.rb', line 248

def error_handlers
  @error_handlers ||= [Bumbleworks::ErrorLogger]
end

#loggerObject



232
233
234
# File 'lib/bumbleworks/configuration.rb', line 232

def logger
  @logger ||= Bumbleworks::SimpleLogger
end

#observersObject



236
237
238
# File 'lib/bumbleworks/configuration.rb', line 236

def observers
  @observers ||= []
end

#participants_directoryObject

Path where Bumbleworks will look for ruote participants to load. The path can be relative or absolute. Relative paths are relative to Bumbleworks.root.



166
167
168
# File 'lib/bumbleworks/configuration.rb', line 166

def participants_directory
  @participants_folder ||= default_participant_directory
end

#rootObject

Root folder where Bumbleworks looks for ruote assets (participants, process_definitions, etc.) The root path must be absolute. It can be defined through a configuration block:

Bumbleworks.configure { |c| c.root = '/somewhere' }

Or directly:

Bumbleworks.root = '/somewhere/else/'

If the root is not defined, Bumbleworks will use the root of known frameworks (Rails, Sinatra and Rory). Otherwise, it will raise an error if not defined.

Raises:



195
196
197
198
199
200
201
202
203
204
# File 'lib/bumbleworks/configuration.rb', line 195

def root
  @root ||= case
    when defined?(Rails) then Rails.root
    when defined?(Rory) then Rory.root
    when defined?(Padrino) then Padrino.root
    when defined?(Sinatra::Application) then Sinatra::Application.root
  end
  raise UndefinedSetting.new("Bumbleworks.root must be set") unless @root
  @root
end

#storage_adapterObject

If storage_adapter is not explicitly set, find first registered adapter that can use Bumbleworks.storage.



220
221
222
223
224
225
226
227
228
229
230
# File 'lib/bumbleworks/configuration.rb', line 220

def storage_adapter
  @storage_adapter ||= begin
    all_adapters = storage_adapters
    raise UndefinedSetting, "No storage adapters configured" if all_adapters.empty?
    adapter = all_adapters.detect do |potential_adapter|
      potential_adapter.use?(storage)
    end
    raise UndefinedSetting, "Storage is missing or not supported.  Supported: #{all_adapters.map(&:display_name).join(', ')}" unless adapter
    adapter
  end
end

#store_historyObject

Default history storage to true



179
180
181
# File 'lib/bumbleworks/configuration.rb', line 179

def store_history
  @store_history.nil? ? true : @store_history
end

#tasks_directoryObject

Path where Bumbleworks will look for task modules to load. The path can be relative or absolute. Relative paths are relative to Bumbleworks.root.



174
175
176
# File 'lib/bumbleworks/configuration.rb', line 174

def tasks_directory
  @tasks_folder ||= default_tasks_directory
end