Class: AutoResp::AutoResponder

Inherits:
Object
  • Object
show all
Defined in:
lib/autoresponse.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.



19
20
21
22
23
24
25
26
# File 'lib/autoresponse.rb', line 19

def initialize(config={})
  @config = config
  @rule_manager = RuleManager.new
  init_autoresponse_home
  init_proxy_server
  load_rules
  monitor_rules_change
end

Instance Method Details

#add_rule(*args, &block) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/autoresponse.rb', line 64

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



83
84
85
# File 'lib/autoresponse.rb', line 83

def clear_rules
  rules.clear
end

#rulesObject



79
80
81
# File 'lib/autoresponse.rb', line 79

def rules
  @rule_manager.rules
end

#startObject



48
49
50
51
# File 'lib/autoresponse.rb', line 48

def start
  @thread = Thread.new { @server.start }
  @thread.join
end

#stopObject



58
59
60
61
62
# File 'lib/autoresponse.rb', line 58

def stop
  puts "\nshuting down"
  @server.shutdown
  @thread.kill
end

#stop_and_exitObject



53
54
55
56
# File 'lib/autoresponse.rb', line 53

def stop_and_exit
  stop
  exit
end