class Bumbleworks::Configuration
Stores configuration information
Configuration
information is loaded from a configuration block defined within the client application.
@example 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
Attributes
Public Class Methods
# File lib/bumbleworks/configuration.rb, line 18 def define_setting(name) defined_settings << name attr_accessor name end
# File lib/bumbleworks/configuration.rb, line 23 def defined_settings @defined_settings ||= [] end
# File lib/bumbleworks/configuration.rb, line 179 def initialize @storage_adapters = [] @storage_options = {} @cached_paths = {} @timeout ||= 5 end
Public Instance Methods
Add a storage adapter to the set of possible adapters. Takes an object that responds to `driver`, `use?`, `storage_class`, and `display_name`.
# File lib/bumbleworks/configuration.rb, line 263 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
Clears all memoize variables and configuration settings
# File lib/bumbleworks/configuration.rb, line 296 def clear! defined_settings.each {|setting| instance_variable_set("@#{setting}", nil)} @storage_adapters = [] @cached_paths = {} end
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.
# File lib/bumbleworks/configuration.rb, line 190 def definitions_directory @cached_paths[:definitions_directory] ||= look_up_configured_path( :definitions_directory, :defaults => ['process_definitions', 'processes'] ) end
Default entity_classes
to empty array
# File lib/bumbleworks/configuration.rb, line 237 def entity_classes @entity_classes ||= [] end
# File lib/bumbleworks/configuration.rb, line 302 def error_handlers @error_handlers ||= [Bumbleworks::ErrorLogger] end
# File lib/bumbleworks/configuration.rb, line 286 def logger @logger ||= Bumbleworks::SimpleLogger end
# File lib/bumbleworks/configuration.rb, line 290 def observers @observers ||= [] end
Path where Bumbleworks
will look for the participant registration file. The path can be relative or absolute. Relative paths are relative to Bumbleworks.root.
# File lib/bumbleworks/configuration.rb, line 223 def participant_registration_file @cached_paths[:participant_registration_file] ||= look_up_configured_path( :participant_registration_file, :defaults => ['participants.rb'], :file => true ) end
Path where Bumbleworks
will look for ruote participants to load. The path can be relative or absolute. Relative paths are relative to Bumbleworks.root.
# File lib/bumbleworks/configuration.rb, line 201 def participants_directory look_up_configured_path( :participants_directory, :defaults => ['participants'] ) end
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), appending “lib/bumbleworks”. Otherwise, it will raise an error if not defined.
# File lib/bumbleworks/configuration.rb, line 253 def root @root ||= begin raise UndefinedSetting.new("Bumbleworks.root must be set") unless framework_root File.join(framework_root, "lib", "bumbleworks") end end
If storage_adapter
is not explicitly set, find first registered adapter that can use Bumbleworks.storage.
# File lib/bumbleworks/configuration.rb, line 274 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
Default history storage to true
# File lib/bumbleworks/configuration.rb, line 232 def store_history @store_history.nil? ? true : @store_history end
Path where Bumbleworks
will look for task modules to load. The path can be relative or absolute. Relative paths are relative to Bumbleworks.root.
# File lib/bumbleworks/configuration.rb, line 212 def tasks_directory @cached_paths[:tasks_directory] ||= look_up_configured_path( :tasks_directory, :defaults => ['tasks'] ) end
Private Instance Methods
# File lib/bumbleworks/configuration.rb, line 308 def defined_settings self.class.defined_settings end
# File lib/bumbleworks/configuration.rb, line 340 def first_existing_default_path(possible_paths, options = {}) defaults = [possible_paths].flatten.compact.map { |d| File.join(root, d) } defaults.detect do |default| path_resolves?(default, :file => options[:file]) end end
# File lib/bumbleworks/configuration.rb, line 312 def framework_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 end
If the user explicitly declared a path, raises an exception if the path was not found. Missing default paths do not raise an exception since no paths are required.
# File lib/bumbleworks/configuration.rb, line 350 def look_up_configured_path(path_type, options = {}) return @cached_paths[path_type] if @cached_paths.has_key?(path_type) if user_defined_path = user_configured_path(path_type) if path_resolves?(user_defined_path, :file => options[:file]) return user_defined_path else raise Bumbleworks::InvalidSetting, "#{Bumbleworks::Support.humanize(path_type)} not found (looked for #{user_defined_path || defaults.join(', ')})" end end first_existing_default_path(options[:defaults], :file => options[:file]) end
# File lib/bumbleworks/configuration.rb, line 321 def path_resolves?(path, options = {}) if options[:file] File.file?(path.to_s) else File.directory?(path.to_s) end end
# File lib/bumbleworks/configuration.rb, line 329 def user_configured_path(path_type) user_defined_path = instance_variable_get("@#{path_type}") if user_defined_path if user_defined_path[0] == '/' user_defined_path else File.join(root, user_defined_path) end end end