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
@@ -1,67 +0,0 @@
1
- require 'yaml'
2
-
3
- module Adhearsion
4
-
5
- ##
6
- # This class isn't yet tied into Adhearsion.
7
- #
8
- class HostDefinition
9
-
10
- SUPPORTED_KEYS = [:host, :username, :password, :key, :name]
11
-
12
- cattr_reader :definitions
13
- @@definitions ||= []
14
-
15
- class << self
16
- def import_from_data_structure(local_definitions)
17
- case local_definitions
18
- when Array
19
- local_definitions.each do |definition|
20
- raise HostDefinitionException, "Unrecognized definition: #{definition}" unless definition.is_a?(Hash)
21
- end
22
- local_definitions.map { |definition| new definition }
23
- when Hash
24
- local_definitions.map do |(name,definition)|
25
- new definition.merge(:name => name)
26
- end
27
- else
28
- raise HostDefinitionException, "Unrecognized definition #{local_definitions}"
29
- end
30
- end
31
-
32
- def import_from_yaml(yaml_string)
33
- import_from_data_structure YAML.load(yaml_string)
34
- end
35
-
36
- def import_from_yaml_file(file)
37
- import_from_yaml YAML.load_file(file)
38
- end
39
-
40
- def clear_definitions!
41
- definitions.clear
42
- end
43
- end
44
-
45
- attr_reader :name, :host, :username, :password, :key
46
- def initialize(hash)
47
- @host, @username, @password, @key, @name = hash.values_at(*SUPPORTED_KEYS)
48
- @name ||= new_guid
49
-
50
- unrecognized_keys = hash.keys - SUPPORTED_KEYS
51
- raise HostDefinitionException, "Unrecognized key(s): #{unrecognized_keys.map(&:inspect).to_sentence}" if unrecognized_keys.any?
52
- raise HostDefinitionException, "You must supply a password or key!" if username && !(password || key)
53
- raise HostDefinitionException, "You must supply a username!" unless username
54
- raise HostDefinitionException, 'You cannot supply both a password and key!' if password && key
55
- raise HostDefinitionException, 'You must supply a host!' unless host
56
-
57
- self.class.definitions << self
58
- end
59
-
60
- class HostDefinitionException < StandardError
61
-
62
- end
63
-
64
- end
65
-
66
-
67
- end
@@ -1,86 +0,0 @@
1
- require 'adhearsion/voip/asterisk'
2
- module Adhearsion
3
- class Initializer
4
-
5
- class AsteriskInitializer
6
-
7
- cattr_accessor :config, :agi_server, :ami_client
8
- class << self
9
-
10
- def start
11
- self.config = AHN_CONFIG.asterisk
12
- self.agi_server = initialize_agi
13
- self.ami_client = VoIP::Asterisk.manager_interface = initialize_ami if config.ami_enabled?
14
- join_server_thread_after_initialized
15
-
16
- # Make sure we stop everything when we shutdown
17
- Events.register_callback(:shutdown) do
18
- ahn_log.info "Shutting down with #{Adhearsion.active_calls.size} active calls"
19
- self.stop
20
- end
21
- end
22
-
23
- def stop
24
- agi_server.graceful_shutdown
25
- ami_client.disconnect! if ami_client
26
- end
27
-
28
- private
29
-
30
- def initialize_agi
31
- VoIP::Asterisk::AGI::Server.new :host => config.listening_host,
32
- :port => config.listening_port
33
- end
34
-
35
- def initialize_ami
36
- options = ami_options
37
- start_ami_after_initialized
38
- VoIP::Asterisk::Manager::ManagerInterface.new(options).tap do
39
- class << VoIP::Asterisk
40
- if respond_to?(:manager_interface)
41
- ahn_log.warn "Asterisk.manager_interface already initialized?"
42
- else
43
- def manager_interface
44
- Adhearsion::Initializer::AsteriskInitializer.ami_client
45
- end
46
- end
47
- end
48
- end
49
- end
50
-
51
- def ami_options
52
- %w(host port username password events auto_reconnect).inject({}) do |options, property|
53
- options[property.to_sym] = config.ami.send property
54
- options
55
- end
56
- end
57
-
58
- def join_server_thread_after_initialized
59
- Events.register_callback(:after_initialized) do
60
- begin
61
- agi_server.start
62
- rescue => e
63
- ahn_log.fatal "Failed to start AGI server! #{e.inspect}"
64
- abort
65
- end
66
- end
67
- IMPORTANT_THREADS << agi_server
68
- end
69
-
70
- def start_ami_after_initialized
71
- Events.register_callback(:after_initialized) do
72
- begin
73
- self.ami_client.connect!
74
- rescue Errno::ECONNREFUSED
75
- ahn_log.ami.error "Connection refused when connecting to AMI! Please check your configuration."
76
- rescue => e
77
- ahn_log.ami.error "Error connecting to AMI! #{e.inspect}"
78
- end
79
- end
80
- end
81
-
82
- end
83
- end
84
-
85
- end
86
- end
@@ -1,324 +0,0 @@
1
- module Adhearsion
2
- class Configuration
3
- module ConfigurationEntryPoint
4
- def add_configuration_for(name)
5
- configuration_class_name = "#{name}Configuration"
6
- lowercased_name = name.to_s.underscore
7
-
8
- class_eval(<<-EVAL, __FILE__, __LINE__)
9
- def enable_#{lowercased_name}(configuration_options = {})
10
- @#{lowercased_name}_configuration = #{configuration_class_name}.new(configuration_options)
11
- end
12
-
13
- def #{lowercased_name}
14
- @#{lowercased_name}_configuration
15
- end
16
-
17
- def #{lowercased_name}_enabled?
18
- !#{lowercased_name}.nil?
19
- end
20
- EVAL
21
- end
22
- end
23
- extend ConfigurationEntryPoint
24
-
25
- class << self
26
- def configure(&block)
27
- if Adhearsion.const_defined?(:AHN_CONFIG)
28
- yield AHN_CONFIG if block_given?
29
- else
30
- Adhearsion.const_set(:AHN_CONFIG, new(&block))
31
- end
32
- end
33
- end
34
-
35
- attr_accessor :automatically_answer_incoming_calls
36
- attr_accessor :end_call_on_hangup
37
- attr_accessor :end_call_on_error
38
- attr_accessor :components_to_load
39
-
40
- def initialize
41
- @automatically_answer_incoming_calls = true
42
- @end_call_on_hangup = true
43
- @end_call_on_error = true
44
- @components_to_load = []
45
- yield self if block_given?
46
- end
47
-
48
- def ahnrc
49
- @ahnrc
50
- end
51
-
52
- ##
53
- # Load the contents of an .ahnrc file into this Configuration.
54
- #
55
- # @param [String, Hash] ahnrc String of YAML .ahnrc data or a Hash of the pre-loaded YAML data structure
56
- #
57
- def ahnrc=(new_ahnrc)
58
- case new_ahnrc
59
- when Hash
60
- @raw_ahnrc = new_ahnrc.to_yaml.freeze
61
- @ahnrc = new_ahnrc.clone.freeze
62
- when String
63
- @raw_ahnrc = new_ahnrc.clone.freeze
64
- @ahnrc = YAML.load(new_ahnrc).freeze
65
- end
66
- end
67
-
68
- def logging(options)
69
- Adhearsion::Logging.logging_level = options[:level] if options.has_key? :level
70
- Adhearsion::Logging::AdhearsionLogger.outputters = Array(options[:outputters]) if options.has_key? :outputters
71
- Adhearsion::Logging::AdhearsionLogger.formatters = Array(options[:formatters]) if options.has_key? :formatters
72
- Adhearsion::Logging::AdhearsionLogger.formatters = Array(options[:formatter]) * Adhearsion::Logging::AdhearsionLogger.outputters.count if options.has_key? :formatter
73
- end
74
-
75
- def add_component(*list)
76
- AHN_CONFIG.components_to_load |= list
77
- end
78
-
79
- ##
80
- # Adhearsion's .ahnrc file is used to define paths to certain parts of the framework. For example, the name dialplan.rb
81
- # is actually specified in .ahnrc. This file can actually be just a filename, a filename with a glob (.e.g "*.rb"), an
82
- # Array of filenames or even an Array of globs.
83
- #
84
- # @param [String,Array] String segments which convey the nesting of Hash keys through .ahnrc
85
- # @raise [RuntimeError] If ahnrc has not been set yet with #ahnrc=()
86
- # @raise [NameError] If the path through the ahnrc is invalid
87
- #
88
- def files_from_setting(*path_through_config)
89
- raise RuntimeError, "No ahnrc has been set yet!" unless @ahnrc
90
- queried_nested_setting = path_through_config.flatten.inject(@ahnrc) do |hash,key_name|
91
- if hash.kind_of?(Hash) && hash.has_key?(key_name)
92
- hash[key_name]
93
- else
94
- raise NameError, "Paths #{path_through_config.inspect} not found in .ahnrc!"
95
- end
96
- end
97
- raise NameError, "Paths #{path_through_config.inspect} not found in .ahnrc!" unless queried_nested_setting
98
- queried_nested_setting = Array queried_nested_setting
99
- queried_nested_setting.map { |filename| files_from_glob(filename) }.flatten.uniq
100
- end
101
-
102
- private
103
-
104
- def files_from_glob(glob)
105
- Dir.glob "#{AHN_ROOT}/#{glob}"
106
- end
107
-
108
- class AbstractConfiguration
109
- extend ConfigurationEntryPoint
110
-
111
- class << self
112
- private
113
- def abstract_method!
114
- raise "Must be implemented in subclasses"
115
- end
116
- end
117
-
118
- def initialize(overrides = {})
119
- overrides.each_pair do |attribute, value|
120
- send("#{attribute}=", value)
121
- end
122
- end
123
- end
124
-
125
- # Abstract superclass for AsteriskConfiguration and FreeSwitchConfiguration.
126
- class TelephonyPlatformConfiguration < AbstractConfiguration
127
- attr_accessor :listening_port
128
- attr_accessor :listening_host
129
-
130
- class << self
131
- def default_listening_port
132
- abstract_method!
133
- end
134
-
135
- def default_listening_host
136
- '0.0.0.0'
137
- end
138
- end
139
-
140
- def initialize(overrides = {})
141
- @listening_host = overrides.has_key?(:host) ? overrides.delete(:host) : self.class.default_listening_host
142
- @listening_port = overrides.has_key?(:port) ? overrides.delete(:port) : self.class.default_listening_port
143
- super
144
- end
145
- end
146
-
147
- class AsteriskConfiguration < TelephonyPlatformConfiguration
148
- attr_accessor :speech_engine
149
- attr_accessor :argument_delimiter
150
-
151
- class << self
152
- def default_listening_port
153
- 4573
154
- end
155
-
156
- # Keep Asterisk 1.4 (and prior) as the default to protect upgraders
157
- # This setting only applies to AGI. AMI delimiters are always
158
- # auto-detected.
159
- def default_argument_delimiter
160
- '|'
161
- end
162
- end
163
-
164
- def initialize(overrides = {})
165
- @argument_delimiter = self.class.default_argument_delimiter
166
- super
167
- end
168
-
169
- class AMIConfiguration < AbstractConfiguration
170
- attr_accessor :port, :username, :password, :events, :host, :auto_reconnect
171
-
172
- class << self
173
- def default_port
174
- 5038
175
- end
176
-
177
- def default_events
178
- false
179
- end
180
-
181
- def default_host
182
- 'localhost'
183
- end
184
-
185
- def default_auto_reconnect
186
- true
187
- end
188
- end
189
-
190
- def initialize(overrides = {})
191
- self.host = self.class.default_host
192
- self.port = self.class.default_port
193
- self.events = self.class.default_events
194
- self.auto_reconnect = self.class.default_auto_reconnect
195
- super
196
- end
197
- end
198
- add_configuration_for :AMI
199
- end
200
- add_configuration_for :Asterisk
201
-
202
- class FreeswitchConfiguration < TelephonyPlatformConfiguration
203
- class << self
204
- def default_listening_port
205
- 4572
206
- end
207
- end
208
- end
209
- add_configuration_for :Freeswitch
210
-
211
- class DatabaseConfiguration < AbstractConfiguration
212
- attr_accessor :connection_options, :orm
213
- def initialize(options)
214
- @orm = options.delete(:orm) || :active_record # TODO: ORM is a misnomer
215
- @connection_options = options
216
- end
217
- end
218
- add_configuration_for :Database
219
-
220
- class LdapConfiguration < AbstractConfiguration
221
- attr_accessor :connection_options
222
- def initialize(options)
223
- @connection_options = options
224
- end
225
- end
226
- add_configuration_for :Ldap
227
-
228
- class DrbConfiguration < AbstractConfiguration
229
- attr_accessor :port
230
- attr_accessor :host
231
- attr_accessor :acl
232
-
233
- # ACL = Access Control List
234
-
235
- class << self
236
- def default_port
237
- 9050
238
- end
239
-
240
- def default_host
241
- 'localhost'
242
- end
243
- end
244
-
245
- def initialize(overrides = {})
246
- self.port = overrides[:port] || self.class.default_port
247
- self.host = overrides[:host] || self.class.default_host
248
- self.acl = overrides[:raw_acl]
249
-
250
- unless acl
251
- self.acl = []
252
- [*overrides[ :deny]].compact.each { |ip| acl << 'deny' << ip }
253
- [*overrides[:allow]].compact.each { |ip| acl << 'allow' << ip }
254
- acl.concat %w[allow 127.0.0.1] if acl.empty?
255
- end
256
- end
257
- end
258
- add_configuration_for :Drb
259
-
260
- class RailsConfiguration < AbstractConfiguration
261
-
262
- attr_accessor :rails_root, :environment
263
- def initialize(options)
264
- path_to_rails, environment = check_options options
265
- @rails_root = File.expand_path(path_to_rails)
266
- @environment = environment.to_sym
267
- end
268
-
269
- private
270
-
271
- def check_options(options)
272
- options = options.clone
273
- path = options.delete :path
274
- env = options.delete :env
275
- raise ArgumentError, "Unrecognied argument(s) #{options.keys.to_sentence} in Rails initializer!" unless options.size.zero?
276
- raise ArgumentError, "Must supply an :env argument to the Rails initializer!" unless env
277
- raise ArgumentError, "Must supply an :path argument to the Rails initializer!" unless path
278
- [path, env]
279
- end
280
-
281
- end
282
- add_configuration_for :Rails
283
-
284
- class XMPPConfiguration < AbstractConfiguration
285
-
286
- attr_accessor :jid, :password, :server, :port
287
- def initialize(options)
288
- jid, password, server, port = check_options options
289
- @jid = jid
290
- @password = password
291
- @server = server
292
- @port = port
293
- end
294
-
295
- class << self
296
- def default_port
297
- 5222
298
- end
299
- end
300
-
301
- private
302
-
303
- def check_options(options)
304
- options = options.clone
305
- jid = options.delete :jid
306
- password = options.delete :password
307
- server = options.delete :server
308
- port = options.delete :port
309
- raise ArgumentError, "Unrecognied argument(s) #{options.keys.to_sentence} in XMPP initializer!" unless options.size.zero?
310
- raise ArgumentError, "Must supply a :jid argument to the XMPP initializer!" unless jid
311
- raise ArgumentError, "Must supply a :password argument to the XMPP initializer!" unless password
312
- if server
313
- port ||= self.class.default_port
314
- else
315
- raise ArgumentError, "Must supply a :server argument as well as :port to the XMPP initializer!" if port
316
- end
317
- [jid, password, server, port]
318
- end
319
-
320
- end
321
- add_configuration_for :XMPP
322
-
323
- end
324
- end