sevenscale-adhearsion 0.7.1003 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +8 -2
- data/EVENTS +11 -0
- data/Rakefile +92 -26
- data/adhearsion.gemspec +131 -23
- data/app_generators/ahn/ahn_generator.rb +21 -7
- data/app_generators/ahn/templates/.ahnrc +10 -4
- data/app_generators/ahn/templates/Rakefile +7 -2
- data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +15 -0
- data/app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE +7 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/config.yml +12 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
- data/app_generators/ahn/templates/components/simon_game/{lib/simon_game.rb → simon_game.rb} +14 -19
- data/app_generators/ahn/templates/config/startup.rb +3 -6
- data/app_generators/ahn/templates/dialplan.rb +2 -3
- data/app_generators/ahn/templates/events.rb +32 -6
- data/bin/jahn +10 -0
- data/examples/asterisk_manager_interface/standalone.rb +51 -0
- data/lib/adhearsion/cli.rb +140 -23
- data/lib/adhearsion/component_manager/component_tester.rb +55 -0
- data/lib/adhearsion/component_manager/spec_framework.rb +24 -0
- data/lib/adhearsion/component_manager.rb +169 -238
- data/lib/adhearsion/events_support.rb +59 -237
- data/lib/adhearsion/{core_extensions → foundation}/all.rb +0 -0
- data/lib/adhearsion/{blank_slate.rb → foundation/blank_slate.rb} +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/custom_daemonizer.rb +0 -0
- data/lib/adhearsion/foundation/event_socket.rb +203 -0
- data/lib/adhearsion/foundation/future_resource.rb +36 -0
- data/lib/adhearsion/{core_extensions → foundation}/global.rb +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/metaprogramming.rb +0 -0
- data/lib/adhearsion/foundation/numeric.rb +13 -0
- data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
- data/lib/adhearsion/{core_extensions → foundation}/relationship_properties.rb +2 -0
- data/lib/adhearsion/foundation/string.rb +26 -0
- data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
- data/lib/adhearsion/{core_extensions → foundation}/thread_safety.rb +0 -0
- data/lib/adhearsion/host_definitions.rb +5 -1
- data/lib/adhearsion/initializer/asterisk.rb +33 -11
- data/lib/adhearsion/initializer/configuration.rb +58 -6
- data/lib/adhearsion/initializer/database.rb +3 -46
- data/lib/adhearsion/initializer/drb.rb +9 -3
- data/lib/adhearsion/initializer/freeswitch.rb +3 -3
- data/lib/adhearsion/initializer/rails.rb +1 -1
- data/lib/adhearsion/initializer.rb +213 -87
- data/lib/adhearsion/tasks/deprecations.rb +59 -0
- data/lib/adhearsion/tasks.rb +2 -1
- data/lib/adhearsion/version.rb +3 -3
- data/lib/adhearsion/voip/asterisk/agi_server.rb +6 -6
- data/lib/adhearsion/voip/asterisk/commands.rb +100 -2
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1754 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +286 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +562 -0
- data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
- data/lib/adhearsion/voip/asterisk.rb +1 -8
- data/lib/adhearsion/voip/call.rb +5 -1
- data/lib/adhearsion/voip/dial_plan.rb +74 -61
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +1 -1
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +2 -6
- data/lib/adhearsion/voip/dsl/numerical_string.rb +2 -2
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +2 -2
- data/lib/adhearsion.rb +16 -11
- data/lib/theatre/README.markdown +64 -0
- data/lib/theatre/callback_definition_loader.rb +84 -0
- data/lib/theatre/guid.rb +23 -0
- data/lib/theatre/invocation.rb +121 -0
- data/lib/theatre/namespace_manager.rb +153 -0
- data/lib/theatre/version.rb +2 -0
- data/lib/theatre.rb +151 -0
- metadata +60 -147
- data/Manifest.txt +0 -151
- data/README.txt +0 -5
- data/ahn_generators/component/USAGE +0 -5
- data/ahn_generators/component/component_generator.rb +0 -57
- data/ahn_generators/component/templates/configuration.rb +0 -0
- data/ahn_generators/component/templates/lib/lib.rb.erb +0 -3
- data/ahn_generators/component/templates/test/test.rb.erb +0 -12
- data/ahn_generators/component/templates/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
- data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +0 -31
- data/lib/adhearsion/core_extensions/array.rb +0 -0
- data/lib/adhearsion/core_extensions/guid.rb +0 -5
- data/lib/adhearsion/core_extensions/hash.rb +0 -0
- data/lib/adhearsion/core_extensions/numeric.rb +0 -4
- data/lib/adhearsion/core_extensions/proc.rb +0 -0
- data/lib/adhearsion/core_extensions/pseudo_uuid.rb +0 -11
- data/lib/adhearsion/core_extensions/publishable.rb +0 -73
- data/lib/adhearsion/core_extensions/string.rb +0 -26
- data/lib/adhearsion/core_extensions/thread.rb +0 -13
- data/lib/adhearsion/core_extensions/time.rb +0 -0
- data/lib/adhearsion/distributed/gateways/dbus_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/osa_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/rest_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/soap_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +0 -9
- data/lib/adhearsion/distributed/peer_finder.rb +0 -0
- data/lib/adhearsion/distributed/remote_cli.rb +0 -0
- data/lib/adhearsion/hooks.rb +0 -57
- data/lib/adhearsion/initializer/paths.rb +0 -55
- data/lib/adhearsion/voip/asterisk/ami/actions.rb +0 -238
- data/lib/adhearsion/voip/asterisk/ami/machine.rb +0 -871
- data/lib/adhearsion/voip/asterisk/ami/machine.rl +0 -109
- data/lib/adhearsion/voip/asterisk/ami/parser.rb +0 -262
- data/lib/adhearsion/voip/asterisk/ami.rb +0 -147
- data/spec/fixtures/dialplan.rb +0 -3
- data/spec/initializer/test_configuration.rb +0 -267
- data/spec/initializer/test_loading.rb +0 -162
- data/spec/initializer/test_paths.rb +0 -43
- data/spec/sample.rb +0 -9
- data/spec/silence.rb +0 -10
- data/spec/test_ahn_command.rb +0 -149
- data/spec/test_code_quality.rb +0 -87
- data/spec/test_component_manager.rb +0 -97
- data/spec/test_constants.rb +0 -8
- data/spec/test_drb.rb +0 -104
- data/spec/test_events.rb +0 -136
- data/spec/test_helper.rb +0 -106
- data/spec/test_hooks.rb +0 -15
- data/spec/test_host_definitions.rb +0 -79
- data/spec/test_initialization.rb +0 -124
- data/spec/test_logging.rb +0 -80
- data/spec/test_relationship_properties.rb +0 -54
- data/spec/voip/asterisk/ami_response_definitions.rb +0 -23
- data/spec/voip/asterisk/config_file_generators/test_agents.rb +0 -253
- data/spec/voip/asterisk/config_file_generators/test_queues.rb +0 -325
- data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +0 -306
- data/spec/voip/asterisk/menu_command/test_calculated_match.rb +0 -111
- data/spec/voip/asterisk/menu_command/test_matchers.rb +0 -98
- data/spec/voip/asterisk/mock_ami_server.rb +0 -176
- data/spec/voip/asterisk/test_agi_server.rb +0 -453
- data/spec/voip/asterisk/test_ami.rb +0 -227
- data/spec/voip/asterisk/test_commands.rb +0 -2006
- data/spec/voip/asterisk/test_config_manager.rb +0 -129
- data/spec/voip/dsl/dispatcher_spec_helper.rb +0 -45
- data/spec/voip/dsl/test_dialing_dsl.rb +0 -268
- data/spec/voip/dsl/test_dispatcher.rb +0 -82
- data/spec/voip/dsl/test_parser.rb +0 -87
- data/spec/voip/freeswitch/test_basic_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_inbound_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_oes_server.rb +0 -9
- data/spec/voip/test_call_routing.rb +0 -127
- data/spec/voip/test_dialplan_manager.rb +0 -442
- data/spec/voip/test_numerical_string.rb +0 -48
- data/spec/voip/test_phone_number.rb +0 -36
- data/test/test_ahn_generator.rb +0 -59
- data/test/test_component_generator.rb +0 -52
- data/test/test_generator_helper.rb +0 -20
@@ -1,6 +1,32 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
##
|
2
|
+
# In this file you can define callbacks for different aspects of the framework. Below is an example:
|
3
|
+
##
|
4
|
+
#
|
5
|
+
# events.asterisk.before_call.each do |call|
|
6
|
+
# # This simply logs the extension for all calls going through this Adhearsion app.
|
7
|
+
# extension = call.variables[:extension]
|
8
|
+
# ahn_log "Got a new call with extension #{extension}"
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
##
|
12
|
+
# Asterisk Manager Interface example:
|
13
|
+
#
|
14
|
+
# events.asterisk.manager_interface.each do |event|
|
15
|
+
# ahn_log.events event.inspect
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# This assumes you gave :events => true to the config.asterisk.enable_ami method in config/startup.rb
|
19
|
+
#
|
20
|
+
##
|
21
|
+
# Here is a list of the events included by default:
|
22
|
+
#
|
23
|
+
# - events.asterisk.manager_interface
|
24
|
+
# - events.after_initialized
|
25
|
+
# - events.shutdown
|
26
|
+
# - events.asterisk.before_call
|
27
|
+
# - events.asterisk.failed_call
|
28
|
+
# - events.asterisk.call_hangup
|
29
|
+
#
|
30
|
+
#
|
31
|
+
# Note: events are mostly for components to register and expose to you.
|
32
|
+
##
|
data/bin/jahn
CHANGED
@@ -29,4 +29,14 @@ require 'adhearsion/cli'
|
|
29
29
|
# file from an app.
|
30
30
|
# require 'adhearsion/jruby'
|
31
31
|
|
32
|
+
abort(<<-MESSAGE) unless RUBY_PLATFORM =~ /java/
|
33
|
+
You must use jahn with JRuby! Are you running this script after installing Adhearsion with non-JRuby RubyGems?
|
34
|
+
|
35
|
+
If you don't want to install Adhearsion with the JRuby version of RubyGems, try running jahn directly with an absolute path:
|
36
|
+
|
37
|
+
#{File.expand_path(__FILE__)} start your_app_name
|
38
|
+
|
39
|
+
Note: You must have the jruby executable in your $PATH and $JRUBY_HOME set.
|
40
|
+
MESSAGE
|
41
|
+
|
32
42
|
Adhearsion::CLI::AhnCommand.execute!
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# This is a file which shows you how to use the Asterisk Manager Interface library in a standalone Ruby script.
|
2
|
+
|
3
|
+
PATH_TO_ADHEARSION = File.join(File.dirname(__FILE__), "/../..")
|
4
|
+
|
5
|
+
MANAGER_CONNECTION_INFORMATION = {
|
6
|
+
:host => "10.0.1.97",
|
7
|
+
:username => "jicksta",
|
8
|
+
:password => "roflcopter",
|
9
|
+
:events => true
|
10
|
+
}
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
begin
|
14
|
+
require 'adhearsion'
|
15
|
+
rescue LoadError
|
16
|
+
begin
|
17
|
+
require File.join(PATH_TO_ADHEARSION, "/lib/adhearsion")
|
18
|
+
rescue LoadError
|
19
|
+
abort "Could not find Adhearsion! Please update the PATH_TO_ADHEARSION constant in this file"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'adhearsion/voip/asterisk/manager_interface'
|
24
|
+
|
25
|
+
# If you'd like to see the AMI protocol data, change this to :debug
|
26
|
+
Adhearsion::Logging.logging_level = :warn
|
27
|
+
|
28
|
+
# This makes addressing the ManagerInterface class a little cleaner
|
29
|
+
include Adhearsion::VoIP::Asterisk::Manager
|
30
|
+
|
31
|
+
# Let's instantiate a new ManagerInterface object and have it automatically connect using the Hash we defined above.
|
32
|
+
interface = ManagerInterface.connect MANAGER_CONNECTION_INFORMATION
|
33
|
+
|
34
|
+
# Send an AMI action with our new ManagerInterface object. This will return an Array of SIPPeer events.
|
35
|
+
sip_peers = interface.send_action "SIPPeers"
|
36
|
+
|
37
|
+
# Pretty-print the SIP peers on the server
|
38
|
+
|
39
|
+
if sip_peers.any?
|
40
|
+
sip_peers.each do |peer|
|
41
|
+
# Uncomment the following line to view all the headers for each peer.
|
42
|
+
# p peer.headers
|
43
|
+
|
44
|
+
peer_name = peer.headers["ObjectName"]
|
45
|
+
peer_status = peer.headers["Status"]
|
46
|
+
|
47
|
+
puts "#{peer_name}: #{peer_status}"
|
48
|
+
end
|
49
|
+
else
|
50
|
+
puts "This Asterisk server has no SIP peers!"
|
51
|
+
end
|
data/lib/adhearsion/cli.rb
CHANGED
@@ -6,16 +6,26 @@ module Adhearsion
|
|
6
6
|
USAGE = <<USAGE
|
7
7
|
Usage:
|
8
8
|
ahn create /path/to/directory
|
9
|
-
ahn start [daemon] [directory]
|
9
|
+
ahn start [daemon] [/path/to/directory]
|
10
10
|
ahn version|-v|--v|-version|--version
|
11
11
|
ahn help|-h|--h|--help|-help
|
12
|
-
|
13
|
-
|
14
|
-
ahn
|
12
|
+
|
13
|
+
ahn enable component COMPONENT_NAME
|
14
|
+
ahn disable component COMPONENT_NAME
|
15
|
+
ahn create component COMPONENT_NAME
|
15
16
|
USAGE
|
16
17
|
|
17
18
|
def self.execute!
|
18
19
|
CommandHandler.send(*parse_arguments)
|
20
|
+
rescue CommandHandler::CLIException => error
|
21
|
+
fail_and_print_usage error
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Provides a small abstraction of Kernel::abort().
|
26
|
+
#
|
27
|
+
def self.fail_and_print_usage(error)
|
28
|
+
Kernel.abort "#{error.message}\n\n#{USAGE}"
|
19
29
|
end
|
20
30
|
|
21
31
|
def self.parse_arguments(args=ARGV.clone)
|
@@ -23,14 +33,14 @@ USAGE
|
|
23
33
|
case action
|
24
34
|
when /^-?-?h(elp)?$/, nil then [:help]
|
25
35
|
when /^-?-?v(ersion)?$/ then [:version]
|
26
|
-
when
|
27
|
-
[:create, args
|
36
|
+
when "create"
|
37
|
+
[:create, *args]
|
28
38
|
when 'start'
|
29
39
|
pid_file_regexp = /^--pid-file=(.+)$/
|
30
40
|
if args.size > 3
|
31
|
-
|
41
|
+
fail_and_print_usage "Too many arguments supplied!" if args.size > 3
|
32
42
|
elsif args.size == 3
|
33
|
-
|
43
|
+
fail_and_print_usage "Unrecognized final argument #{args.last}" unless args.last =~ pid_file_regexp
|
34
44
|
pid_file = args.pop[pid_file_regexp, 1]
|
35
45
|
else
|
36
46
|
pid_file = nil
|
@@ -42,11 +52,19 @@ USAGE
|
|
42
52
|
elsif args.size == 1
|
43
53
|
path, daemon = args.first, false
|
44
54
|
else
|
45
|
-
|
55
|
+
fail_and_print_usage "Invalid format for the start CLI command!"
|
46
56
|
end
|
47
57
|
[:start, path, daemon, pid_file]
|
48
58
|
when '-'
|
49
59
|
[:start, Dir.pwd]
|
60
|
+
when "enable", "disable"
|
61
|
+
if args.size == 1
|
62
|
+
raise CommandHandler::UnknownCommand, "Must supply an argument for what you wish to #{action}"
|
63
|
+
elsif args.size == 2
|
64
|
+
[action, *args]
|
65
|
+
else
|
66
|
+
raise CommandHandler::UnknownCommand, "Too many arguments supplied!"
|
67
|
+
end
|
50
68
|
else
|
51
69
|
[action, *args]
|
52
70
|
end
|
@@ -54,15 +72,56 @@ USAGE
|
|
54
72
|
|
55
73
|
module CommandHandler
|
56
74
|
class << self
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
75
|
+
|
76
|
+
def create(*args)
|
77
|
+
if args.size.zero?
|
78
|
+
raise CommandHandler::UnknownCommand.new("Must specify something to create!")
|
79
|
+
elsif args.size == 1
|
80
|
+
# We're creating a project
|
81
|
+
path = args.first
|
82
|
+
require 'rubigen'
|
83
|
+
require 'rubigen/scripts/generate'
|
84
|
+
source = RubiGen::PathSource.new(:application,
|
85
|
+
File.join(File.dirname(__FILE__), "../../app_generators"))
|
86
|
+
RubiGen::Base.reset_sources
|
87
|
+
RubiGen::Base.append_sources source
|
88
|
+
RubiGen::Scripts::Generate.new.run([path], :generator => 'ahn')
|
89
|
+
elsif args.size == 2
|
90
|
+
# We're creating a feature (e.g. a component)
|
91
|
+
feature_type, component_name = args
|
92
|
+
|
93
|
+
if feature_type != "component"
|
94
|
+
# At the moment, only components can be created.
|
95
|
+
raise CommandHandler::UnknownCommand.new("Don't know how to create '#{feature_type}'")
|
96
|
+
end
|
97
|
+
|
98
|
+
if component_name !~ /^[a-z][\w_]+$/
|
99
|
+
raise CommandHandler::ComponentError.new("Component name must be lowercase alphanumeric characters " +
|
100
|
+
"and begin with a character")
|
101
|
+
end
|
102
|
+
|
103
|
+
app_path = PathString.from_application_subdirectory Dir.pwd
|
104
|
+
|
105
|
+
raise PathInvalid.new(Dir.pwd) if app_path.nil?
|
106
|
+
|
107
|
+
new_component_dir = app_path + "/components/#{component_name}"
|
108
|
+
raise ComponentError.new("Component #{component_name} already exists!") if File.exists?(new_component_dir)
|
109
|
+
|
110
|
+
# Everything's good. Let's create the component
|
111
|
+
Dir.mkdir new_component_dir
|
112
|
+
File.open(new_component_dir + "/#{component_name}.rb","w") do |file|
|
113
|
+
file.puts <<-RUBY
|
114
|
+
# See http://docs.adhearsion.com for more information on how to write components or
|
115
|
+
# look at the examples in newly-created projects.
|
116
|
+
RUBY
|
117
|
+
end
|
118
|
+
File.open(new_component_dir + "/config.yml","w") do |file|
|
119
|
+
file.puts '# You can use this file for component-specific configuration.'
|
120
|
+
end
|
121
|
+
puts "Created blank component '#{component_name}' at components/#{component_name}"
|
122
|
+
else
|
123
|
+
raise CommandHandler::UnknownCommand.new("Provided too many arguments to 'create'")
|
124
|
+
end
|
66
125
|
end
|
67
126
|
|
68
127
|
def start(path, daemon=false, pid_file=nil)
|
@@ -78,26 +137,84 @@ USAGE
|
|
78
137
|
puts USAGE
|
79
138
|
end
|
80
139
|
|
140
|
+
def enable(type, name)
|
141
|
+
case type
|
142
|
+
when "component"
|
143
|
+
app_path = PathString.from_application_subdirectory Dir.pwd
|
144
|
+
if app_path
|
145
|
+
disabled_component_path = File.join app_path, "components", "disabled", name
|
146
|
+
enabled_component_path = File.join app_path, "components", name
|
147
|
+
if File.directory? disabled_component_path
|
148
|
+
FileUtils.mv disabled_component_path, enabled_component_path
|
149
|
+
puts "Enabled component #{name}"
|
150
|
+
else
|
151
|
+
raise ComponentError.new("There is no components/disabled directory!")
|
152
|
+
end
|
153
|
+
else
|
154
|
+
raise PathInvalid.new(Dir.pwd)
|
155
|
+
end
|
156
|
+
else
|
157
|
+
raise UnknownCommand.new("enable #{type}")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def disable(type, name)
|
162
|
+
case type
|
163
|
+
when "component"
|
164
|
+
app_path = PathString.from_application_subdirectory Dir.pwd
|
165
|
+
if app_path
|
166
|
+
disabled_dir = File.join app_path, "components", "disabled"
|
167
|
+
|
168
|
+
disabled_component_path = File.join disabled_dir, name
|
169
|
+
enabled_component_path = File.join app_path, "components", name
|
170
|
+
|
171
|
+
Dir.mkdir disabled_dir unless File.directory?(disabled_dir)
|
172
|
+
|
173
|
+
if File.directory? enabled_component_path
|
174
|
+
if File.directory?(disabled_component_path)
|
175
|
+
raise ComponentError.new("There is already a disabled component at #{disabled_component_path}")
|
176
|
+
else
|
177
|
+
FileUtils.mv enabled_component_path, disabled_component_path
|
178
|
+
puts "Disabled component #{name}"
|
179
|
+
end
|
180
|
+
else
|
181
|
+
raise ComponentError.new("Could not find component #{name} at #{enabled_component_path} !")
|
182
|
+
end
|
183
|
+
else
|
184
|
+
raise PathInvalid.new(Dir.pwd)
|
185
|
+
end
|
186
|
+
else
|
187
|
+
raise UnknownCommand.new("disable #{type}")
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
81
191
|
def method_missing(action, *args)
|
82
192
|
raise UnknownCommand, [action, *args] * " "
|
83
193
|
end
|
194
|
+
|
195
|
+
private
|
196
|
+
|
84
197
|
end
|
85
198
|
|
86
|
-
class
|
199
|
+
class CLIException < Exception; end
|
200
|
+
|
201
|
+
class UnknownCommand < CLIException
|
87
202
|
def initialize(cmd)
|
88
|
-
super "Unknown command: #{cmd}
|
203
|
+
super "Unknown command: #{cmd}"
|
89
204
|
end
|
90
205
|
end
|
91
206
|
|
92
|
-
class
|
207
|
+
class ComponentError < CLIException; end
|
208
|
+
|
209
|
+
class UnknownProject < CLIException
|
93
210
|
def initialize(project)
|
94
211
|
super "Application #{project} does not exist! Have you installed it?"
|
95
212
|
end
|
96
213
|
end
|
97
214
|
|
98
|
-
class PathInvalid <
|
215
|
+
class PathInvalid < CLIException
|
99
216
|
def initialize(path)
|
100
|
-
super "Directory #{path} does not
|
217
|
+
super "Directory #{path} does not belong to an Adhearsion project!"
|
101
218
|
end
|
102
219
|
end
|
103
220
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ComponentTester
|
2
|
+
|
3
|
+
class << self
|
4
|
+
|
5
|
+
##
|
6
|
+
#
|
7
|
+
#
|
8
|
+
# @return [Module] an anonymous module which includes the ComponentTester module.
|
9
|
+
#
|
10
|
+
def new(component_name, component_directory)
|
11
|
+
component_directory = File.expand_path component_directory
|
12
|
+
main_file = component_directory + "/#{component_name}/#{component_name}.rb"
|
13
|
+
|
14
|
+
component_manager = Adhearsion::Components::ComponentManager.new(component_directory)
|
15
|
+
component_module = Adhearsion::Components::ComponentManager::ComponentDefinitionContainer.load_file main_file
|
16
|
+
|
17
|
+
Module.new do
|
18
|
+
|
19
|
+
extend ComponentTester
|
20
|
+
|
21
|
+
(class << self; self; end).send(:define_method, :component_manager) { component_manager }
|
22
|
+
(class << self; self; end).send(:define_method, :component_name) { component_name }
|
23
|
+
(class << self; self; end).send(:define_method, :component_module) { component_module }
|
24
|
+
(class << self; self; end).send(:define_method, :component_directory) { component_directory }
|
25
|
+
|
26
|
+
|
27
|
+
define_method(:component_manager) { component_manager }
|
28
|
+
define_method(:component_name) { component_name }
|
29
|
+
define_method(:component_module) { component_module }
|
30
|
+
define_method(:component_directory) { component_directory }
|
31
|
+
|
32
|
+
def self.const_missing(name)
|
33
|
+
component_module.const_get name
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def helper_method(name)
|
41
|
+
Object.new.extend(component_module).method(name)
|
42
|
+
end
|
43
|
+
|
44
|
+
def config
|
45
|
+
component_manager.configuration_for_component_named component_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def initialize!
|
49
|
+
metadata = component_module.metaclass.send(:instance_variable_get, :@metadata)
|
50
|
+
if metadata && metadata[:initialization_block].kind_of?(Proc)
|
51
|
+
metadata[:initialization_block].call
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'adhearsion/component_manager/component_tester'
|
2
|
+
begin
|
3
|
+
require 'spec'
|
4
|
+
rescue LoadError
|
5
|
+
abort 'You do not have the "rspec" gem installed! You must install it to continue.\n\nsudo gem install rspec\n\n'
|
6
|
+
end
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'rr'
|
10
|
+
rescue LoadError
|
11
|
+
abort 'You do not have the "rr" gem installed! You must install it to continue.\n\nsudo gem install rr\n\n'
|
12
|
+
end
|
13
|
+
|
14
|
+
module ComponentConfigurationSpecHelper
|
15
|
+
def mock_component_config_with(new_config)
|
16
|
+
Object.send(:remove_const, :COMPONENTS) rescue nil
|
17
|
+
Object.send(:const_set, :COMPONENTS, OpenStruct.new(new_config))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Spec::Runner.configure do |config|
|
22
|
+
config.mock_with :rr
|
23
|
+
config.include ComponentConfigurationSpecHelper
|
24
|
+
end
|