Class: AutoResp::AutoResponder

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

Constant Summary collapse

ARHOME =
"#{ENV["HOME"]}/.auto_response"
RULES =
"#{ARHOME}/rules"

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ AutoResponder

Returns a new instance of AutoResponder.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/auto_response.rb', line 23

def initialize(config = {})

  @config             = config
  @rule_manager       = RuleManager.new
  @logger             = init_logger

  @logger.debug { "Starting AutoResp v#{VERSION}" }
  @logger.debug { "Listening at " << "#{ip_address}:#{proxy_port}".yellow }

  init_autoresponse_home
  load_rules
  monitor_rules_change
end

Instance Method Details

#add_rule(*args, &block) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/auto_response.rb', line 109

def add_rule(*args, &block)
  case args.first
  when Hash
    rules.merge! args.first
  when String
    rules[args[0]] = args[1]
  when Regexp
    if block_given?
      rules[args[0]] = block
    else
      rules[args[0]] = args[1]
    end
  end
end

#clear_rulesObject



128
129
130
# File 'lib/auto_response.rb', line 128

def clear_rules
  rules.clear
end

#rulesObject



124
125
126
# File 'lib/auto_response.rb', line 124

def rules
  @rule_manager.rules
end

#startObject



92
93
94
95
96
# File 'lib/auto_response.rb', line 92

def start
  log_rules
  start_proxy
  start_viewer
end

#stopObject



103
104
105
106
107
# File 'lib/auto_response.rb', line 103

def stop
  @server.shutdown
  @viewer_thread.kill
  @proxy_thread.kill
end

#stop_and_exitObject



98
99
100
101
# File 'lib/auto_response.rb', line 98

def stop_and_exit
  stop
  exit
end