Class: RServiceBus2::Config
- Inherits:
-
Object
- Object
- RServiceBus2::Config
- Defined in:
- lib/rservicebus2/config.rb
Overview
Marshals configuration information for an rservicebus host
Direct Known Subclasses
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#contract_list ⇒ Object
readonly
Returns the value of attribute contract_list.
-
#error_queue_name ⇒ Object
readonly
Returns the value of attribute error_queue_name.
-
#forward_received_messages_to ⇒ Object
readonly
Returns the value of attribute forward_received_messages_to.
-
#forward_sent_messages_to ⇒ Object
readonly
Returns the value of attribute forward_sent_messages_to.
-
#handler_path_list ⇒ Object
readonly
Returns the value of attribute handler_path_list.
-
#lib_list ⇒ Object
readonly
Returns the value of attribute lib_list.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
-
#message_endpoint_mappings ⇒ Object
readonly
Returns the value of attribute message_endpoint_mappings.
-
#mq_host ⇒ Object
readonly
Returns the value of attribute mq_host.
-
#saga_path_list ⇒ Object
readonly
Returns the value of attribute saga_path_list.
-
#stat_output_countdown ⇒ Object
readonly
Returns the value of attribute stat_output_countdown.
-
#subscription_uri ⇒ Object
readonly
Returns the value of attribute subscription_uri.
Instance Method Summary collapse
- #configure_mq ⇒ Object
- #ensure_contract_file_exists(path) ⇒ Object
- #get_value(name, default = nil) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#load_contracts ⇒ Object
Marshals paths for contracts Note.
-
#load_handler_path_list ⇒ Object
Marshals paths for message handlers Note.
- #load_host_section ⇒ Object
-
#load_libs ⇒ Object
Marshals paths for lib Note.
- #load_saga_path_list ⇒ Object
-
#load_working_dir_list ⇒ Object
Marshals paths for working_dirs Note.
- #log(string) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
10 11 12 13 14 15 |
# File 'lib/rservicebus2/config.rb', line 10 def initialize puts 'Cannot instantiate config directly.' puts 'For production, use ConfigFromEnv.' puts 'For debugging or testing, you could try ConfigFromSetter' abort end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def app_name @app_name end |
#contract_list ⇒ Object (readonly)
Returns the value of attribute contract_list.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def contract_list @contract_list end |
#error_queue_name ⇒ Object (readonly)
Returns the value of attribute error_queue_name.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def error_queue_name @error_queue_name end |
#forward_received_messages_to ⇒ Object (readonly)
Returns the value of attribute forward_received_messages_to.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def @forward_received_messages_to end |
#forward_sent_messages_to ⇒ Object (readonly)
Returns the value of attribute forward_sent_messages_to.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def @forward_sent_messages_to end |
#handler_path_list ⇒ Object (readonly)
Returns the value of attribute handler_path_list.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def handler_path_list @handler_path_list end |
#lib_list ⇒ Object (readonly)
Returns the value of attribute lib_list.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def lib_list @lib_list end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def max_retries @max_retries end |
#message_endpoint_mappings ⇒ Object (readonly)
Returns the value of attribute message_endpoint_mappings.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def @message_endpoint_mappings end |
#mq_host ⇒ Object (readonly)
Returns the value of attribute mq_host.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def mq_host @mq_host end |
#saga_path_list ⇒ Object (readonly)
Returns the value of attribute saga_path_list.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def saga_path_list @saga_path_list end |
#stat_output_countdown ⇒ Object (readonly)
Returns the value of attribute stat_output_countdown.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def stat_output_countdown @stat_output_countdown end |
#subscription_uri ⇒ Object (readonly)
Returns the value of attribute subscription_uri.
4 5 6 |
# File 'lib/rservicebus2/config.rb', line 4 def subscription_uri @subscription_uri end |
Instance Method Details
#configure_mq ⇒ Object
125 126 127 128 |
# File 'lib/rservicebus2/config.rb', line 125 def configure_mq @mq_host = get_value('MQ', 'beanstalk://localhost') self end |
#ensure_contract_file_exists(path) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rservicebus2/config.rb', line 70 def ensure_contract_file_exists(path) unless File.exist?(path) || File.exist?("#{path}.rb") puts 'Error while processing contracts' puts "*** path, #{path}, provided does not exist as a file" abort end unless File.extname(path) == '' || File.extname(path) == '.rb' puts 'Error while processing contracts' puts "*** path, #{path}, should point to a ruby file, with extention .rb" abort end end |
#get_value(name, default = nil) ⇒ Object
21 22 23 24 25 |
# File 'lib/rservicebus2/config.rb', line 21 def get_value(name, default = nil) value = (ENV[name].nil? || ENV[name] == '') ? default : ENV[name] log "Env value: #{name}: #{value}" value end |
#load_contracts ⇒ Object
Marshals paths for contracts Note. .rb extension is optional Expected format: /one/two/contracts
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rservicebus2/config.rb', line 86 def load_contracts @contract_list = [] # This is a guard clause in case no Contracts have been specified # If any guard clauses have been specified, then execution should drop # to the second block return self if get_value('CONTRACTS').nil? get_value('CONTRACTS', './contract').split(';').each do |path| ensure_contract_file_exists(path) @contract_list << path end self end |
#load_handler_path_list ⇒ Object
Marshals paths for message handlers Note. trailing slashs will be stripped Expected format: <path 1>;<path 2>
30 31 32 33 34 35 36 37 38 |
# File 'lib/rservicebus2/config.rb', line 30 def load_handler_path_list paths = get_value('MSGHANDLERPATH', './messagehandler') @handler_path_list = [] paths.split(';').each do |path| @handler_path_list << path.strip.chomp('/') end self end |
#load_host_section ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rservicebus2/config.rb', line 50 def load_host_section @app_name = get_value('APPNAME', 'RServiceBus2') @error_queue_name = get_value('ERROR_QUEUE_NAME', 'error') @max_retries = get_value('MAX_RETRIES', '5').to_i @stat_output_countdown = get_value('STAT_OUTPUT_COUNTDOWN', '100').to_i @subscription_uri = get_value('SUBSCRIPTION_URI', "file:///tmp/#{app_name}_subscriptions.yaml") audit_queue_name = get_value('AUDIT_QUEUE_NAME') if audit_queue_name.nil? @forward_sent_messages_to = get_value('FORWARD_SENT_MESSAGES_TO') @forward_received_messages_to = get_value('FORWARD_RECEIVED_MESSAGES_TO') else @forward_sent_messages_to = audit_queue_name @forward_received_messages_to = audit_queue_name end self end |
#load_libs ⇒ Object
Marshals paths for lib Note. .rb extension is optional Expected format: /one/two/contracts
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rservicebus2/config.rb', line 103 def load_libs @lib_list = [] paths = get_value('LIB') paths = './lib' if paths.nil? && File.exist?('./lib') return self if paths.nil? paths.split(';').each do |path| log "Loading libs from, #{path}" unless File.exist?(path) puts 'Error while processing libs' puts "*** path, #{path}, should point to a ruby file, with extention .rb, or" puts "*** path, #{path}, should point to a directory than conatins ruby files, that have extention .rb" abort end @lib_list << path end self end |
#load_saga_path_list ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/rservicebus2/config.rb', line 40 def load_saga_path_list paths = get_value('SAGAPATH', './Saga') @saga_path_list = [] paths.split(';').each do |path| @saga_path_list << path.strip.chomp('/') end self end |
#load_working_dir_list ⇒ Object
Marshals paths for working_dirs Note. trailing slashs will be stripped Expected format: <path 1>;<path 2>
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/rservicebus2/config.rb', line 133 def load_working_dir_list puts "Config.load_working_dir_list.1" puts "Config.load_working_dir_list.2 #{@contract_list}" path_list = get_value('WORKING_DIR') return self if path_list.nil? path_list.split(';').each do |path| path = path.strip.chomp('/') unless Dir.exist?("#{path}") puts 'Error while processing working directory list' puts "*** path, #{path}, does not exist" abort end @handler_path_list << "#{path}/messagehandler" if Dir.exist?("#{path}/messagehandler") @saga_path_list << "#{path}/saga" if Dir.exist?("#{path}/saga") @contract_list << "#{path}/contract.rb" if File.exist?( "#{path}/contract.rb" ) @lib_list << "#{path}/lib" if File.exist?("#{path}/lib") end self end |
#log(string) ⇒ Object
17 18 19 |
# File 'lib/rservicebus2/config.rb', line 17 def log(string) puts string end |