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.



28
29
30
31
32
33
34
35
36
# File 'lib/autoresponse.rb', line 28

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

Instance Method Details

#add_rule(*args, &block) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/autoresponse.rb', line 86

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



105
106
107
# File 'lib/autoresponse.rb', line 105

def clear_rules
  rules.clear
end

#rulesObject



101
102
103
# File 'lib/autoresponse.rb', line 101

def rules
  @rule_manager.rules
end

#startObject



67
68
69
70
71
72
73
# File 'lib/autoresponse.rb', line 67

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

#stopObject



80
81
82
83
84
# File 'lib/autoresponse.rb', line 80

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

#stop_and_exitObject



75
76
77
78
# File 'lib/autoresponse.rb', line 75

def stop_and_exit
  stop
  exit
end