Class: ProcessBot::Options
- Inherits:
-
Object
- Object
- ProcessBot::Options
- Defined in:
- lib/process_bot/options.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #application_basename ⇒ Object
- #events ⇒ Object
- #fetch ⇒ Object
-
#initialize(options = {}) ⇒ Options
constructor
A new instance of Options.
- #possible_process_titles ⇒ Object
- #possible_process_titles_joined_regex ⇒ Object
- #present?(key) ⇒ Boolean
- #release_path ⇒ Object
- #set(key, value) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Options
Returns a new instance of Options.
14 15 16 |
# File 'lib/process_bot/options.rb', line 14 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'lib/process_bot/options.rb', line 2 def @options end |
Class Method Details
.from_args(args) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/process_bot/options.rb', line 4 def self.from_args(args) = ProcessBot::Options.new args.each do |key, value| .set(key, value) end end |
Instance Method Details
#[](key) ⇒ Object
18 19 20 |
# File 'lib/process_bot/options.rb', line 18 def [](key) [key] end |
#application_basename ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/process_bot/options.rb', line 37 def application_basename @application_basename ||= begin app_path_parts = release_path.split("/") if release_path.include?("/releases/") app_path_parts.pop(2) elsif release_path.end_with?("/current") app_path_parts.pop end app_path_parts.last end end |
#events ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/process_bot/options.rb', line 22 def events @events ||= begin require "knjrbfw" event_handler = ::Knj::Event_handler.new event_handler.add_event(name: :on_process_started) event_handler.add_event(name: :on_socket_opened) event_handler end end |
#fetch ⇒ Object
33 34 35 |
# File 'lib/process_bot/options.rb', line 33 def fetch(...) .fetch(...) end |
#possible_process_titles ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/process_bot/options.rb', line 51 def possible_process_titles possible_names = [] # Sidekiq name can by current Rails root base name possible_names << application_basename # Sidekiq name can be set tag name (but we wrongly read application for some reason?) possible_names << .fetch(:application) possible_names end |
#possible_process_titles_joined_regex ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/process_bot/options.rb', line 63 def possible_process_titles_joined_regex possible_process_titles_joined_regex = "" possible_process_titles.each_with_index do |possible_name, index| possible_process_titles_joined_regex << "|" if index >= 1 possible_process_titles_joined_regex << Regexp.escape(possible_name) end possible_process_titles_joined_regex end |
#present?(key) ⇒ Boolean
73 74 75 76 77 |
# File 'lib/process_bot/options.rb', line 73 def present?(key) return true if .key?(key) && [key] false end |
#release_path ⇒ Object
79 80 81 |
# File 'lib/process_bot/options.rb', line 79 def release_path @release_path ||= fetch(:release_path) end |
#set(key, value) ⇒ Object
83 84 85 |
# File 'lib/process_bot/options.rb', line 83 def set(key, value) [key] = value end |