Class: ProcessBot::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/process_bot/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Options

Returns a new instance of Options.



4
5
6
# File 'lib/process_bot/options.rb', line 4

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/process_bot/options.rb', line 2

def options
  @options
end

Instance Method Details

#[](key) ⇒ Object



8
9
10
# File 'lib/process_bot/options.rb', line 8

def [](key)
  options[key]
end

#application_basenameObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/process_bot/options.rb', line 27

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

#eventsObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/process_bot/options.rb', line 12

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

#fetchObject



23
24
25
# File 'lib/process_bot/options.rb', line 23

def fetch(...)
  options.fetch(...)
end

#possible_process_titlesObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/process_bot/options.rb', line 41

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 << options.fetch(:application)

  possible_names
end

#possible_process_titles_joined_regexObject



53
54
55
56
57
58
59
60
61
# File 'lib/process_bot/options.rb', line 53

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

Returns:

  • (Boolean)


63
64
65
66
67
# File 'lib/process_bot/options.rb', line 63

def present?(key)
  return true if options.key?(key) && options[key]

  false
end

#release_pathObject



69
70
71
# File 'lib/process_bot/options.rb', line 69

def release_path
  @release_path ||= fetch(:release_path)
end

#set(key, value) ⇒ Object



73
74
75
# File 'lib/process_bot/options.rb', line 73

def set(key, value)
  options[key] = value
end