adhearsion 1.2.6 → 2.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/.gitignore +17 -10
  2. data/CHANGELOG.md +273 -0
  3. data/Gemfile +1 -1
  4. data/Guardfile +17 -0
  5. data/README.markdown +61 -9
  6. data/Rakefile +16 -48
  7. data/adhearsion.gemspec +21 -7
  8. data/bin/ahn +3 -1
  9. data/cucumber.yml +4 -0
  10. data/features/app_generator.feature +42 -0
  11. data/features/cli.feature +108 -0
  12. data/features/step_definitions/app_generator_steps.rb +6 -0
  13. data/features/step_definitions/cli_steps.rb +74 -0
  14. data/features/support/aruba_helper.rb +22 -0
  15. data/features/support/env.rb +37 -0
  16. data/features/support/utils.rb +8 -0
  17. data/lib/adhearsion.rb +85 -41
  18. data/lib/adhearsion/call.rb +176 -0
  19. data/lib/adhearsion/call_controller.rb +134 -0
  20. data/lib/adhearsion/call_controller/dial.rb +70 -0
  21. data/lib/adhearsion/call_controller/input.rb +173 -0
  22. data/lib/adhearsion/call_controller/menu.rb +124 -0
  23. data/lib/adhearsion/call_controller/output.rb +267 -0
  24. data/lib/adhearsion/call_controller/record.rb +42 -0
  25. data/lib/adhearsion/call_controller/utility.rb +60 -0
  26. data/lib/adhearsion/calls.rb +81 -0
  27. data/lib/adhearsion/cli.rb +1 -3
  28. data/lib/adhearsion/cli_commands.rb +142 -0
  29. data/lib/adhearsion/configuration.rb +149 -0
  30. data/lib/adhearsion/console.rb +19 -8
  31. data/lib/adhearsion/dialplan_controller.rb +9 -0
  32. data/lib/adhearsion/events.rb +84 -0
  33. data/lib/adhearsion/foundation/all.rb +0 -7
  34. data/lib/adhearsion/foundation/custom_daemonizer.rb +4 -6
  35. data/lib/adhearsion/foundation/exception_handler.rb +9 -0
  36. data/lib/adhearsion/foundation/object.rb +26 -8
  37. data/lib/adhearsion/foundation/synchronized_hash.rb +3 -6
  38. data/lib/adhearsion/foundation/thread_safety.rb +17 -1
  39. data/lib/adhearsion/generators/app/app_generator.rb +4 -13
  40. data/lib/adhearsion/generators/app/templates/Gemfile +10 -5
  41. data/lib/adhearsion/generators/app/templates/Procfile +1 -0
  42. data/lib/adhearsion/generators/app/templates/README.md +28 -0
  43. data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +41 -0
  44. data/lib/adhearsion/generators/app/templates/{components/simon_game → lib}/simon_game.rb +6 -18
  45. data/lib/adhearsion/generators/app/templates/script/ahn +2 -2
  46. data/lib/adhearsion/initializer.rb +151 -293
  47. data/lib/adhearsion/initializer/logging.rb +33 -0
  48. data/lib/adhearsion/logging.rb +65 -69
  49. data/lib/adhearsion/menu_dsl.rb +15 -0
  50. data/lib/adhearsion/menu_dsl/calculated_match.rb +39 -0
  51. data/lib/adhearsion/menu_dsl/calculated_match_collection.rb +41 -0
  52. data/lib/adhearsion/menu_dsl/fixnum_match_calculator.rb +18 -0
  53. data/lib/adhearsion/menu_dsl/match_calculator.rb +36 -0
  54. data/lib/adhearsion/{voip/menu_state_machine/menu_class.rb → menu_dsl/menu.rb} +38 -40
  55. data/lib/adhearsion/menu_dsl/menu_builder.rb +69 -0
  56. data/lib/adhearsion/menu_dsl/range_match_calculator.rb +55 -0
  57. data/lib/adhearsion/menu_dsl/string_match_calculator.rb +21 -0
  58. data/lib/adhearsion/outbound_call.rb +64 -0
  59. data/lib/adhearsion/plugin.rb +319 -0
  60. data/lib/adhearsion/plugin/collection.rb +19 -0
  61. data/lib/adhearsion/plugin/initializer.rb +37 -0
  62. data/lib/adhearsion/plugin/methods_container.rb +6 -0
  63. data/lib/adhearsion/process.rb +94 -0
  64. data/lib/adhearsion/punchblock_plugin.rb +29 -0
  65. data/lib/adhearsion/punchblock_plugin/initializer.rb +137 -0
  66. data/lib/adhearsion/router.rb +30 -0
  67. data/lib/adhearsion/router/route.rb +42 -0
  68. data/lib/adhearsion/script_ahn_loader.rb +2 -2
  69. data/lib/adhearsion/tasks.rb +14 -9
  70. data/lib/adhearsion/tasks/configuration.rb +26 -0
  71. data/lib/adhearsion/tasks/plugins.rb +17 -0
  72. data/lib/adhearsion/version.rb +8 -14
  73. data/spec/adhearsion/call_controller/dial_spec.rb +138 -0
  74. data/spec/adhearsion/call_controller/input_spec.rb +278 -0
  75. data/spec/adhearsion/call_controller/menu_spec.rb +120 -0
  76. data/spec/adhearsion/call_controller/output_spec.rb +466 -0
  77. data/spec/adhearsion/call_controller/record_spec.rb +125 -0
  78. data/spec/adhearsion/call_controller_spec.rb +395 -0
  79. data/spec/adhearsion/call_spec.rb +438 -0
  80. data/spec/adhearsion/calls_spec.rb +47 -0
  81. data/spec/adhearsion/configuration_spec.rb +308 -0
  82. data/spec/adhearsion/dialplan_controller_spec.rb +26 -0
  83. data/spec/adhearsion/events_spec.rb +112 -0
  84. data/spec/adhearsion/initializer/logging_spec.rb +58 -0
  85. data/spec/adhearsion/initializer_spec.rb +209 -122
  86. data/spec/adhearsion/logging_spec.rb +58 -47
  87. data/spec/adhearsion/menu_dsl/calculated_match_collection_spec.rb +56 -0
  88. data/spec/adhearsion/menu_dsl/calculated_match_spec.rb +57 -0
  89. data/spec/adhearsion/menu_dsl/fixnum_match_calculator_spec.rb +33 -0
  90. data/spec/adhearsion/menu_dsl/match_calculator_spec.rb +13 -0
  91. data/spec/adhearsion/menu_dsl/menu_builder_spec.rb +118 -0
  92. data/spec/adhearsion/menu_dsl/menu_spec.rb +210 -0
  93. data/spec/adhearsion/menu_dsl/range_match_calculator_spec.rb +28 -0
  94. data/spec/adhearsion/menu_dsl/string_match_calculator_spec.rb +36 -0
  95. data/spec/adhearsion/menu_dsl_spec.rb +12 -0
  96. data/spec/adhearsion/outbound_call_spec.rb +174 -0
  97. data/spec/adhearsion/plugin_spec.rb +489 -0
  98. data/spec/adhearsion/process_spec.rb +34 -0
  99. data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +294 -0
  100. data/spec/adhearsion/router/route_spec.rb +99 -0
  101. data/spec/adhearsion/router_spec.rb +106 -0
  102. data/spec/adhearsion_spec.rb +46 -0
  103. data/spec/spec_helper.rb +14 -14
  104. data/spec/support/call_controller_test_helpers.rb +48 -0
  105. data/spec/support/initializer_stubs.rb +8 -13
  106. data/spec/support/punchblock_mocks.rb +6 -0
  107. metadata +255 -253
  108. data/CHANGELOG +0 -174
  109. data/bin/ahnctl +0 -68
  110. data/bin/jahn +0 -43
  111. data/examples/asterisk_manager_interface/standalone.rb +0 -51
  112. data/lib/adhearsion/commands.rb +0 -302
  113. data/lib/adhearsion/component_manager.rb +0 -278
  114. data/lib/adhearsion/component_manager/component_tester.rb +0 -54
  115. data/lib/adhearsion/component_manager/spec_framework.rb +0 -18
  116. data/lib/adhearsion/events_support.rb +0 -65
  117. data/lib/adhearsion/foundation/blank_slate.rb +0 -3
  118. data/lib/adhearsion/foundation/event_socket.rb +0 -205
  119. data/lib/adhearsion/foundation/future_resource.rb +0 -36
  120. data/lib/adhearsion/foundation/metaprogramming.rb +0 -17
  121. data/lib/adhearsion/foundation/numeric.rb +0 -13
  122. data/lib/adhearsion/foundation/pseudo_guid.rb +0 -10
  123. data/lib/adhearsion/foundation/relationship_properties.rb +0 -42
  124. data/lib/adhearsion/foundation/string.rb +0 -26
  125. data/lib/adhearsion/generators/app/templates/.ahnrc +0 -34
  126. data/lib/adhearsion/generators/app/templates/README +0 -8
  127. data/lib/adhearsion/generators/app/templates/components/ami_remote/ami_remote.rb +0 -15
  128. data/lib/adhearsion/generators/app/templates/components/disabled/HOW_TO_ENABLE +0 -7
  129. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/README.markdown +0 -47
  130. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.rb +0 -34
  131. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.yml +0 -12
  132. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/README.markdown +0 -3
  133. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +0 -11
  134. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
  135. data/lib/adhearsion/generators/app/templates/config/startup.rb +0 -81
  136. data/lib/adhearsion/generators/app/templates/dialplan.rb +0 -3
  137. data/lib/adhearsion/generators/app/templates/events.rb +0 -33
  138. data/lib/adhearsion/host_definitions.rb +0 -67
  139. data/lib/adhearsion/initializer/asterisk.rb +0 -86
  140. data/lib/adhearsion/initializer/configuration.rb +0 -324
  141. data/lib/adhearsion/initializer/database.rb +0 -60
  142. data/lib/adhearsion/initializer/drb.rb +0 -31
  143. data/lib/adhearsion/initializer/freeswitch.rb +0 -22
  144. data/lib/adhearsion/initializer/ldap.rb +0 -57
  145. data/lib/adhearsion/initializer/rails.rb +0 -41
  146. data/lib/adhearsion/initializer/xmpp.rb +0 -42
  147. data/lib/adhearsion/tasks/components.rb +0 -32
  148. data/lib/adhearsion/tasks/database.rb +0 -5
  149. data/lib/adhearsion/tasks/deprecations.rb +0 -59
  150. data/lib/adhearsion/tasks/generating.rb +0 -20
  151. data/lib/adhearsion/tasks/lint.rb +0 -4
  152. data/lib/adhearsion/voip/asterisk.rb +0 -4
  153. data/lib/adhearsion/voip/asterisk/agi_server.rb +0 -121
  154. data/lib/adhearsion/voip/asterisk/commands.rb +0 -1966
  155. data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +0 -140
  156. data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +0 -102
  157. data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +0 -250
  158. data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +0 -240
  159. data/lib/adhearsion/voip/asterisk/config_manager.rb +0 -64
  160. data/lib/adhearsion/voip/asterisk/manager_interface.rb +0 -697
  161. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +0 -1681
  162. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +0 -341
  163. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +0 -78
  164. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +0 -87
  165. data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +0 -80
  166. data/lib/adhearsion/voip/call.rb +0 -521
  167. data/lib/adhearsion/voip/call_routing.rb +0 -64
  168. data/lib/adhearsion/voip/commands.rb +0 -17
  169. data/lib/adhearsion/voip/constants.rb +0 -39
  170. data/lib/adhearsion/voip/conveniences.rb +0 -18
  171. data/lib/adhearsion/voip/dial_plan.rb +0 -252
  172. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +0 -151
  173. data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +0 -37
  174. data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +0 -27
  175. data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +0 -124
  176. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +0 -69
  177. data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +0 -16
  178. data/lib/adhearsion/voip/dsl/numerical_string.rb +0 -128
  179. data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +0 -48
  180. data/lib/adhearsion/voip/freeswitch/event_handler.rb +0 -58
  181. data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +0 -129
  182. data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +0 -38
  183. data/lib/adhearsion/voip/freeswitch/oes_server.rb +0 -195
  184. data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +0 -80
  185. data/lib/adhearsion/voip/menu_state_machine/matchers.rb +0 -123
  186. data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +0 -57
  187. data/lib/adhearsion/xmpp/connection.rb +0 -61
  188. data/lib/theatre.rb +0 -147
  189. data/lib/theatre/README.markdown +0 -64
  190. data/lib/theatre/callback_definition_loader.rb +0 -86
  191. data/lib/theatre/guid.rb +0 -23
  192. data/lib/theatre/invocation.rb +0 -131
  193. data/lib/theatre/namespace_manager.rb +0 -153
  194. data/lib/theatre/version.rb +0 -2
  195. data/spec/adhearsion/cli_spec.rb +0 -306
  196. data/spec/adhearsion/component_manager_spec.rb +0 -292
  197. data/spec/adhearsion/constants_spec.rb +0 -8
  198. data/spec/adhearsion/drb_spec.rb +0 -65
  199. data/spec/adhearsion/fixtures/dialplan.rb +0 -3
  200. data/spec/adhearsion/foundation/event_socket_spec.rb +0 -168
  201. data/spec/adhearsion/host_definitions_spec.rb +0 -79
  202. data/spec/adhearsion/initializer/configuration_spec.rb +0 -291
  203. data/spec/adhearsion/initializer/loading_spec.rb +0 -154
  204. data/spec/adhearsion/initializer/paths_spec.rb +0 -74
  205. data/spec/adhearsion/relationship_properties_spec.rb +0 -54
  206. data/spec/adhearsion/voip/asterisk/agi_server_spec.rb +0 -473
  207. data/spec/adhearsion/voip/asterisk/ami/ami_spec.rb +0 -550
  208. data/spec/adhearsion/voip/asterisk/ami/lexer/ami_fixtures.yml +0 -30
  209. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story +0 -291
  210. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story.rb +0 -241
  211. data/spec/adhearsion/voip/asterisk/ami/lexer/story_helper.rb +0 -124
  212. data/spec/adhearsion/voip/asterisk/commands_spec.rb +0 -3241
  213. data/spec/adhearsion/voip/asterisk/config_file_generators/agents_spec.rb +0 -251
  214. data/spec/adhearsion/voip/asterisk/config_file_generators/queues_spec.rb +0 -323
  215. data/spec/adhearsion/voip/asterisk/config_file_generators/voicemail_spec.rb +0 -306
  216. data/spec/adhearsion/voip/asterisk/config_manager_spec.rb +0 -127
  217. data/spec/adhearsion/voip/asterisk/menu_command/calculated_match_spec.rb +0 -109
  218. data/spec/adhearsion/voip/asterisk/menu_command/matchers_spec.rb +0 -97
  219. data/spec/adhearsion/voip/call_routing_spec.rb +0 -125
  220. data/spec/adhearsion/voip/dialplan_manager_spec.rb +0 -468
  221. data/spec/adhearsion/voip/dsl/dialing_dsl_spec.rb +0 -270
  222. data/spec/adhearsion/voip/dsl/dispatcher_spec.rb +0 -82
  223. data/spec/adhearsion/voip/dsl/dispatcher_spec_helper.rb +0 -45
  224. data/spec/adhearsion/voip/dsl/parser_spec.rb +0 -69
  225. data/spec/adhearsion/voip/freeswitch/basic_connection_manager_spec.rb +0 -39
  226. data/spec/adhearsion/voip/freeswitch/inbound_connection_manager_spec.rb +0 -39
  227. data/spec/adhearsion/voip/freeswitch/oes_server_spec.rb +0 -9
  228. data/spec/adhearsion/voip/numerical_string_spec.rb +0 -61
  229. data/spec/adhearsion/voip/phone_number_spec.rb +0 -45
  230. data/spec/support/the_following_code.rb +0 -3
  231. data/spec/theatre/dsl_examples/simple_before_call.rb +0 -7
  232. data/spec/theatre/dsl_spec.rb +0 -69
  233. data/spec/theatre/invocation_spec.rb +0 -182
  234. data/spec/theatre/namespace_spec.rb +0 -125
  235. data/spec/theatre/spec_helper_spec.rb +0 -28
  236. data/spec/theatre/theatre_class_spec.rb +0 -148
@@ -0,0 +1,33 @@
1
+ require 'logging'
2
+
3
+ module Adhearsion
4
+ class Initializer
5
+ class Logging
6
+ class << self
7
+
8
+ def start(_appenders = nil, level = :info, formatter = nil)
9
+ ::Logging.init Adhearsion::Logging::LOG_LEVELS
10
+
11
+ ::Logging.logger.root.appenders = _appenders.nil? ? appenders : _appenders
12
+
13
+ ::Logging.logger.root.level = level
14
+
15
+ ::Logging.logger.root.appenders.each do |appender|
16
+ appender.layout = formatter
17
+ end unless formatter.nil?
18
+ end
19
+
20
+ # default appenders
21
+ def appenders
22
+ @appenders ||= [::Logging.appenders.stdout(
23
+ 'stdout',
24
+ :layout => ::Logging.layouts.pattern(
25
+ :pattern => Adhearsion::Logging.adhearsion_pattern,
26
+ :color_scheme => 'bright'
27
+ )
28
+ )]
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,12 +1,29 @@
1
- require 'log4r'
1
+ require 'logging'
2
2
 
3
3
  module Adhearsion
4
4
  module Logging
5
5
 
6
- @@logging_level_lock = Mutex.new
6
+ LOG_LEVELS = %w(TRACE DEBUG INFO WARN ERROR FATAL)
7
+
8
+ METHOD = :logger
7
9
 
8
10
  class << self
9
11
 
12
+ ::Logging.color_scheme 'bright',
13
+ :levels => {
14
+ :info => :green,
15
+ :warn => :yellow,
16
+ :error => :red,
17
+ :fatal => [:white, :on_red]
18
+ },
19
+ :date => :blue,
20
+ :logger => :cyan,
21
+ :message => :magenta
22
+
23
+ def adhearsion_pattern
24
+ '[%d] %-5l %c: %m\n'
25
+ end
26
+
10
27
  def silence!
11
28
  self.logging_level = :fatal
12
29
  end
@@ -15,96 +32,75 @@ module Adhearsion
15
32
  self.logging_level = :info
16
33
  end
17
34
 
18
- def logging_level=(new_logging_level)
19
- new_logging_level = Log4r.const_get(new_logging_level.to_s.upcase)
20
- @@logging_level_lock.synchronize do
21
- @@logging_level = new_logging_level
22
- Log4r::Logger.each_logger do |logger|
23
- logger.level = new_logging_level
24
- end
25
- end
35
+ def reset
36
+ ::Logging.reset
26
37
  end
27
- alias :level= :logging_level=
28
38
 
29
- def logging_level(level = nil)
30
- return self.logging_level= level unless level.nil?
31
- @@logging_level_lock.synchronize do
32
- return @@logging_level ||= Log4r::INFO
39
+ def start
40
+ ::Logging.init LOG_LEVELS
41
+ ::Logging::Logger[:root].level = :info
42
+ ::Logging.logger.root.appenders = [::Logging.appenders.stdout('stdout')]
43
+ self.send :_set_formatter, ::Logging::Layouts.basic(:format_as => :string, :backtrace => true)
44
+
45
+ LOG_LEVELS.each do |level|
46
+ Adhearsion::Logging.const_defined?(level) or Adhearsion::Logging.const_set(level, ::Logging::LEVELS[::Logging.levelify(level)])
33
47
  end
34
48
  end
35
- alias :level :logging_level
36
- end
37
49
 
38
- class AdhearsionLogger < Log4r::Logger
50
+ def logging_level=(new_logging_level)
51
+ ::Logging::Logger[:root].level = new_logging_level
52
+ end
39
53
 
40
- @@outputters = [Log4r::Outputter.stdout]
54
+ alias :level= :logging_level=
41
55
 
42
- class << self
43
- def sanitized_logger_name(name)
44
- name.to_s.gsub(/\W/, '').downcase
45
- end
56
+ def logging_level
57
+ ::Logging::Logger[:root].level
58
+ end
46
59
 
47
- def outputters
48
- @@outputters
49
- end
60
+ def get_logger(logger_name)
61
+ ::Logging::Logger[logger_name]
62
+ end
50
63
 
51
- def outputters=(other)
52
- @@outputters = other
53
- end
64
+ alias :level :logging_level
54
65
 
55
- def formatters
56
- @@outputters.map &:formatter
57
- end
66
+ def sanitized_logger_name(name)
67
+ name.to_s.gsub(/\W/, '').downcase
68
+ end
58
69
 
59
- def formatters=(other)
60
- other.each_with_index do |formatter, i|
61
- outputter = @@outputters[i]
62
- outputter.formatter = formatter if outputter
63
- end
64
- end
70
+ def outputters=(outputters)
71
+ ::Logging.logger.root.appenders = outputters
65
72
  end
66
73
 
67
- def initialize(*args)
68
- super
69
- redefine_outputters
74
+ alias :appenders= :outputters=
75
+
76
+ def outputters
77
+ ::Logging.logger.root.appenders
70
78
  end
71
79
 
72
- def redefine_outputters
73
- self.outputters = @@outputters
80
+ alias :appenders :outputters
81
+
82
+ def formatter=(formatter)
83
+ _set_formatter(formatter)
74
84
  end
75
85
 
76
- def method_missing(logger_name, *args, &block)
77
- define_logging_method logger_name, self.class.new(logger_name.to_s)
78
- send self.class.sanitized_logger_name(logger_name), *args, &block
86
+ alias :layout= :formatter=
87
+
88
+ def formatter
89
+ ::Logging.logger.root.appenders.first.layout
79
90
  end
80
91
 
92
+ alias :layout :formatter
93
+
81
94
  private
82
95
 
83
- def define_logging_method(name, logger)
84
- # Can't use Module#define_method() because blocks in Ruby 1.8.x can't
85
- # have their own block arguments.
86
- self.class.class_eval(<<-CODE, __FILE__, __LINE__)
87
- def #{self.class.sanitized_logger_name name}(*args, &block)
88
- logger = Log4r::Logger['#{name}']
89
- if args.any? || block_given?
90
- logger.info(*args, &block)
91
- else
92
- logger
93
- end
94
- end
95
- CODE
96
+ def _set_formatter(formatter)
97
+ ::Logging.logger.root.appenders.each do |appender|
98
+ appender.layout = formatter
99
+ end
96
100
  end
97
- end
98
-
99
- DefaultAdhearsionLogger = AdhearsionLogger.new 'ahn'
100
101
 
101
- end
102
- end
102
+ end
103
103
 
104
- def ahn_log(*args)
105
- if args.any?
106
- Adhearsion::Logging::DefaultAdhearsionLogger.info(*args)
107
- else
108
- Adhearsion::Logging::DefaultAdhearsionLogger
104
+ start unless ::Logging.const_defined? :MAX_LEVEL_LENGTH
109
105
  end
110
106
  end
@@ -0,0 +1,15 @@
1
+ module Adhearsion
2
+ module MenuDSL
3
+ extend ActiveSupport::Autoload
4
+
5
+ autoload :Exceptions
6
+ autoload :CalculatedMatch
7
+ autoload :CalculatedMatchCollection
8
+ autoload :MatchCalculator
9
+ autoload :FixnumMatchCalculator
10
+ autoload :RangeMatchCalculator
11
+ autoload :StringMatchCalculator
12
+ autoload :MenuBuilder
13
+ autoload :Menu
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ module Adhearsion
2
+ module MenuDSL
3
+ class CalculatedMatch
4
+
5
+ def self.failed_match!(pattern, query, match_payload)
6
+ new :pattern => pattern, :query => query, :match_payload => match_payload
7
+ end
8
+
9
+ attr_reader :match_payload, :potential_matches, :exact_matches, :pattern, :query, :block
10
+
11
+ def initialize(options = {})
12
+ @pattern, @query, @match_payload, @block = options.values_at :pattern, :query, :match_payload, :block
13
+ @potential_matches = options[:potential_matches] ? Array(options[:potential_matches]) : []
14
+ @exact_matches = options[:exact_matches] ? Array(options[:exact_matches]) : []
15
+ end
16
+
17
+ def exact_match?
18
+ exact_matches.any?
19
+ end
20
+
21
+ def potential_match?
22
+ potential_matches.any?
23
+ end
24
+
25
+ def failed_match?
26
+ !(potential_match? || exact_match?)
27
+ end
28
+
29
+ def type_of_match
30
+ if exact_match?
31
+ :exact
32
+ elsif potential_match?
33
+ :potential
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,41 @@
1
+ module Adhearsion
2
+ module MenuDSL
3
+ class CalculatedMatchCollection
4
+ attr_reader :calculated_matches, :potential_matches, :exact_matches,
5
+ :actual_potential_matches, :actual_exact_matches
6
+
7
+ def initialize
8
+ @calculated_matches = []
9
+ @potential_matches = []
10
+ @exact_matches = []
11
+ @actual_potential_matches = []
12
+ @actual_exact_matches = []
13
+ end
14
+
15
+ def <<(calculated_match)
16
+ calculated_matches << calculated_match
17
+ actual_potential_matches.concat calculated_match.potential_matches
18
+ actual_exact_matches.concat calculated_match.exact_matches
19
+
20
+ potential_matches << calculated_match if calculated_match.potential_match?
21
+ exact_matches << calculated_match if calculated_match.exact_match?
22
+ end
23
+
24
+ def potential_match_count
25
+ actual_potential_matches.size
26
+ end
27
+
28
+ def exact_match_count
29
+ actual_exact_matches.size
30
+ end
31
+
32
+ def potential_match?
33
+ potential_match_count > 0
34
+ end
35
+
36
+ def exact_match?
37
+ exact_match_count > 0
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,18 @@
1
+ module Adhearsion
2
+ module MenuDSL
3
+ class FixnumMatchCalculator < MatchCalculator
4
+
5
+ def match(query)
6
+ numeric_query = coerce_to_numeric query
7
+ exact_match, potential_match = nil
8
+ if pattern == numeric_query
9
+ exact_match = pattern
10
+ elsif pattern.to_s.starts_with? query.to_s
11
+ potential_match = pattern
12
+ end
13
+ new_calculated_match :query => query, :exact_matches => exact_match, :potential_matches => potential_match
14
+ end
15
+
16
+ end # class FixnumMatchCalculator
17
+ end
18
+ end
@@ -0,0 +1,36 @@
1
+ module Adhearsion
2
+ module MenuDSL
3
+ class MatchCalculator
4
+
5
+ class << self
6
+
7
+ def build_with_pattern(pattern, match_payload, &block)
8
+ class_for_pattern(pattern).new pattern, match_payload, &block
9
+ end
10
+
11
+ private
12
+
13
+ def class_for_pattern(pattern)
14
+ MenuDSL.const_get "#{pattern.class.name.camelize}MatchCalculator"
15
+ end
16
+ end
17
+
18
+ attr_reader :pattern, :match_payload, :block
19
+
20
+ def initialize(pattern, match_payload, &block)
21
+ @pattern, @match_payload, @block = pattern, match_payload, block
22
+ end
23
+
24
+ protected
25
+
26
+ def new_calculated_match(options)
27
+ CalculatedMatch.new({:pattern => pattern, :match_payload => match_payload, :block => block}.merge(options))
28
+ end
29
+
30
+ def coerce_to_numeric(victim)
31
+ victim.kind_of?(Numeric) ? victim : (victim.to_s =~ /^\d+$/ ? victim.to_s.to_i : nil )
32
+ end
33
+
34
+ end # class MatchCalculator
35
+ end
36
+ end
@@ -1,22 +1,20 @@
1
- require 'adhearsion/voip/menu_state_machine/menu_builder'
2
1
  module Adhearsion
3
- module VoIP
2
+ module MenuDSL
3
+
4
4
  class Menu
5
5
 
6
6
  DEFAULT_MAX_NUMBER_OF_TRIES = 1
7
- DEFAULT_TIMEOUT = 5 # seconds
8
-
9
- relationships :menu_builder => MenuBuilder
7
+ DEFAULT_TIMEOUT = 5
10
8
 
11
9
  attr_reader :builder, :timeout, :tries_count, :max_number_of_tries
12
- def initialize(options={}, &block)
13
- @tries_count = 0 # Counts the number of tries the menu's been executed
14
10
 
15
- @timeout = options[:timeout] || DEFAULT_TIMEOUT
16
- @max_number_of_tries = options[:tries] || DEFAULT_MAX_NUMBER_OF_TRIES
11
+ def initialize(options = {}, &block)
12
+ @tries_count = 0 # Counts the number of tries the menu's been executed
13
+ @timeout = options[:timeout] || DEFAULT_TIMEOUT
14
+ @max_number_of_tries = options[:tries] || DEFAULT_MAX_NUMBER_OF_TRIES
15
+ @builder = MenuDSL::MenuBuilder.new
17
16
 
18
- @builder = menu_builder.new
19
- yield @builder
17
+ @builder.build &block
20
18
 
21
19
  initialize_digit_buffer
22
20
  end
@@ -38,17 +36,16 @@ module Adhearsion
38
36
  end
39
37
 
40
38
  def continue
41
- raise MenuGetAnotherDigitOrTimeout if digit_buffer_empty?
39
+ return get_another_digit_or_timeout! if digit_buffer_empty?
42
40
 
43
41
  calculated_matches = builder.calculate_matches_for digit_buffer_string
44
42
 
45
43
  if calculated_matches.exact_match_count >= 1
46
44
  first_exact_match = calculated_matches.exact_matches.first
47
45
  if calculated_matches.potential_match_count.zero?
48
- # Match found with no extenuating ambiguities! Go with the first exact match
49
- menu_result_found! first_exact_match.match_payload, digit_buffer_string
46
+ menu_result_found! first_exact_match, digit_buffer_string
50
47
  else
51
- get_another_digit_or_finish!(first_exact_match.match_payload, first_exact_match.query)
48
+ get_another_digit_or_finish! first_exact_match.match_payload, first_exact_match.query
52
49
  end
53
50
  elsif calculated_matches.potential_match_count >= 1
54
51
  get_another_digit_or_timeout!
@@ -67,56 +64,59 @@ module Adhearsion
67
64
  end
68
65
 
69
66
  def execute_invalid_hook
70
- builder.execute_hook_for(:invalid, digit_buffer_string)
67
+ builder.execute_hook_for :invalid, digit_buffer_string
71
68
  end
72
69
 
73
70
  def execute_timeout_hook
74
- builder.execute_hook_for(:premature_timeout, digit_buffer_string)
71
+ builder.execute_hook_for :timeout, digit_buffer_string
75
72
  end
76
73
 
77
74
  def execute_failure_hook
78
- builder.execute_hook_for(:failure, digit_buffer_string)
75
+ builder.execute_hook_for :failure, digit_buffer_string
79
76
  end
80
77
 
81
78
  protected
82
79
 
83
80
  # If you're using a more complex class in subclasses, you may want to override this method in addition to the
84
- # digit_buffer, digit_buffer_empty, and digit_buffer_string methods
81
+ # digit buffer, digit_buffer_empty, and digit_buffer_string methods
85
82
  def initialize_digit_buffer
86
83
  @digit_buffer = ClearableStringBuffer.new
87
84
  end
88
85
 
89
86
  def invalid!
90
- raise MenuResultInvalid
87
+ MenuResultInvalid.new
91
88
  end
92
89
 
93
- def menu_result_found!(match_payload, new_extension)
94
- raise MenuResultFound.new(match_payload, new_extension)
90
+ def menu_result_found!(match_object, new_extension)
91
+ MenuResultFound.new(match_object, new_extension)
95
92
  end
96
93
 
97
94
  def get_another_digit_or_finish!(match_payload, new_extension)
98
- raise MenuGetAnotherDigitOrFinish.new(match_payload, new_extension)
95
+ MenuGetAnotherDigitOrFinish.new(match_payload, new_extension)
99
96
  end
100
97
 
101
98
  def get_another_digit_or_timeout!
102
- raise MenuGetAnotherDigitOrTimeout
99
+ MenuGetAnotherDigitOrTimeout.new
103
100
  end
104
101
 
105
102
  # The superclass from which all message-like exceptions descend. It should never
106
103
  # be instantiated directly.
107
- class MenuResult < StandardError; end
104
+ MenuResult = Class.new
105
+ MenuResultDone = Class.new MenuResult
108
106
 
109
- # Raised when the user's input matches
110
107
  class MenuResultFound < MenuResult
111
- attr_reader :match_payload, :new_extension
112
- def initialize(match_payload, new_extension)
108
+
109
+ attr_reader :match_object, :new_extension
110
+
111
+ def initialize(match_object, new_extension)
113
112
  super()
114
- @match_payload = match_payload
113
+ @match_object = match_object
115
114
  @new_extension = new_extension
116
115
  end
117
- end
118
116
 
119
- module MenuGetAnotherDigit; end
117
+ end #class MenuResultFound < MenuResult
118
+
119
+ MenuGetAnotherDigit = Module.new
120
120
 
121
121
  class MenuGetAnotherDigitOrFinish < MenuResultFound
122
122
  include MenuGetAnotherDigit
@@ -126,13 +126,10 @@ module Adhearsion
126
126
  include MenuGetAnotherDigit
127
127
  end
128
128
 
129
- class MenuResultFound < MenuResult; end
130
-
131
- # Raised when the user's input matches no patterns
132
- class MenuResultInvalid < MenuResult; end
129
+ MenuResultInvalid = Class.new MenuResult
133
130
 
134
- # For our default purposes, we need the digit_buffer to behave much like a normal String except that it should
135
- # handle its own resetting (clearing).
131
+ # For our default purpose, we need the digit_buffer to behave much like a normal String except that it should
132
+ # handle its own resetting (clearing)
136
133
  class ClearableStringBuffer < String
137
134
  def clear!
138
135
  replace ""
@@ -141,9 +138,10 @@ module Adhearsion
141
138
  def <<(other)
142
139
  super other.to_s
143
140
  end
144
-
145
141
  end
146
142
 
147
- end
143
+
144
+ end # class Menu
145
+
148
146
  end
149
- end
147
+ end