Module: Legion::Transport::Common
Instance Method Summary collapse
-
#channel ⇒ Object
rubocop:enable all.
- #channel_open? ⇒ Boolean
- #close ⇒ Object
- #close! ⇒ Object
-
#deep_merge(original, new) ⇒ Object
rubocop:disable all.
- #generate_consumer_tag(lex_name: nil, runner_name: nil, thread: Thread.current.object_id) ⇒ Object
- #open_channel(_options = {}) ⇒ Object
- #options_builder(first, *args) ⇒ Object
Instance Method Details
#channel ⇒ Object
rubocop:enable all
50 51 52 |
# File 'lib/legion/transport/common.rb', line 50 def channel @channel ||= Legion::Transport::Connection.channel end |
#channel_open? ⇒ Boolean
10 11 12 |
# File 'lib/legion/transport/common.rb', line 10 def channel_open? channel.open? end |
#close ⇒ Object
60 61 62 63 64 |
# File 'lib/legion/transport/common.rb', line 60 def close Legion::Logging.error 'close called' Legion::Logging.warn 'close called, but method is called close!' close! end |
#close! ⇒ Object
54 55 56 57 58 |
# File 'lib/legion/transport/common.rb', line 54 def close! Legion::Logging.error 'close! called' false unless Legion::Transport::Connection.channel_open? Legion::Transport::Connection.channel.close end |
#deep_merge(original, new) ⇒ Object
rubocop:disable all
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/legion/transport/common.rb', line 27 def deep_merge(original, new) {} unless original.is_a?(Hash) && new.is_a?(Hash) original unless new.is_a? Hash new unless original.is_a? Hash new if original.nil? || original.empty? original if new.nil? || new.empty? new.each do |k, v| unless original.key?(k) original[k] = v next end original[k.to_sym] = if [original[k.to_sym], new[k.to_sym]].all? { |a| a.is_a? Hash } deep_merge(original[k], new[k]) else new[k] end end original end |
#generate_consumer_tag(lex_name: nil, runner_name: nil, thread: Thread.current.object_id) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/legion/transport/common.rb', line 66 def generate_consumer_tag(lex_name: nil, runner_name: nil, thread: Thread.current.object_id) tag = "#{Legion::Settings[:client][:name]}_" tag.concat("#{lex_name}_") unless lex_name.nil? tag.concat("#{runner_name}_") unless runner_name.nil? tag.concat("#{thread}_") tag.concat(SecureRandom.hex) tag end |
#open_channel(_options = {}) ⇒ Object
6 7 8 |
# File 'lib/legion/transport/common.rb', line 6 def open_channel( = {}) @channel = Legion::Transport::Connection.channel end |
#options_builder(first, *args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/legion/transport/common.rb', line 14 def (first, *args) = nil args.each do |option| = if .nil? deep_merge(first, option) else deep_merge(, option) end end end |