adhearsion-cw 1.0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +109 -0
- data/EVENTS +11 -0
- data/Gemfile +3 -0
- data/LICENSE +456 -0
- data/Rakefile +134 -0
- data/adhearsion.gemspec +174 -0
- data/app_generators/ahn/USAGE +5 -0
- data/app_generators/ahn/ahn_generator.rb +97 -0
- data/app_generators/ahn/templates/.ahnrc +34 -0
- data/app_generators/ahn/templates/Gemfile +7 -0
- data/app_generators/ahn/templates/README +8 -0
- data/app_generators/ahn/templates/Rakefile +27 -0
- 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/restful_rpc/README.markdown +11 -0
- data/app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb +48 -0
- data/app_generators/ahn/templates/components/disabled/restful_rpc/restful_rpc.rb +91 -0
- data/app_generators/ahn/templates/components/disabled/restful_rpc/restful_rpc.yml +34 -0
- data/app_generators/ahn/templates/components/disabled/restful_rpc/spec/restful_rpc_spec.rb +251 -0
- data/app_generators/ahn/templates/components/disabled/sandbox/sandbox.rb +104 -0
- data/app_generators/ahn/templates/components/disabled/sandbox/sandbox.yml +2 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.yml +12 -0
- data/app_generators/ahn/templates/components/disabled/xmpp_gateway/README.markdown +3 -0
- data/app_generators/ahn/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +11 -0
- data/app_generators/ahn/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
- data/app_generators/ahn/templates/components/simon_game/simon_game.rb +56 -0
- data/app_generators/ahn/templates/config/startup.rb +74 -0
- data/app_generators/ahn/templates/dialplan.rb +3 -0
- data/app_generators/ahn/templates/events.rb +32 -0
- data/bin/ahn +29 -0
- data/bin/ahnctl +68 -0
- data/bin/jahn +43 -0
- data/examples/asterisk_manager_interface/standalone.rb +51 -0
- data/lib/adhearsion/cli.rb +296 -0
- data/lib/adhearsion/component_manager/component_tester.rb +53 -0
- data/lib/adhearsion/component_manager/spec_framework.rb +18 -0
- data/lib/adhearsion/component_manager.rb +272 -0
- data/lib/adhearsion/events_support.rb +84 -0
- data/lib/adhearsion/foundation/all.rb +15 -0
- data/lib/adhearsion/foundation/blank_slate.rb +3 -0
- data/lib/adhearsion/foundation/custom_daemonizer.rb +45 -0
- data/lib/adhearsion/foundation/event_socket.rb +205 -0
- data/lib/adhearsion/foundation/future_resource.rb +36 -0
- data/lib/adhearsion/foundation/metaprogramming.rb +17 -0
- data/lib/adhearsion/foundation/numeric.rb +13 -0
- data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
- data/lib/adhearsion/foundation/relationship_properties.rb +42 -0
- data/lib/adhearsion/foundation/string.rb +26 -0
- data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
- data/lib/adhearsion/foundation/thread_safety.rb +7 -0
- data/lib/adhearsion/host_definitions.rb +67 -0
- data/lib/adhearsion/initializer/asterisk.rb +87 -0
- data/lib/adhearsion/initializer/configuration.rb +321 -0
- data/lib/adhearsion/initializer/database.rb +60 -0
- data/lib/adhearsion/initializer/drb.rb +31 -0
- data/lib/adhearsion/initializer/freeswitch.rb +22 -0
- data/lib/adhearsion/initializer/ldap.rb +57 -0
- data/lib/adhearsion/initializer/rails.rb +41 -0
- data/lib/adhearsion/initializer/xmpp.rb +42 -0
- data/lib/adhearsion/initializer.rb +394 -0
- data/lib/adhearsion/logging.rb +92 -0
- data/lib/adhearsion/tasks/components.rb +32 -0
- data/lib/adhearsion/tasks/database.rb +5 -0
- data/lib/adhearsion/tasks/deprecations.rb +59 -0
- data/lib/adhearsion/tasks/generating.rb +20 -0
- data/lib/adhearsion/tasks/lint.rb +4 -0
- data/lib/adhearsion/tasks/testing.rb +37 -0
- data/lib/adhearsion/tasks.rb +17 -0
- data/lib/adhearsion/version.rb +35 -0
- data/lib/adhearsion/voip/asterisk/agi_server.rb +115 -0
- data/lib/adhearsion/voip/asterisk/commands.rb +1581 -0
- data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +140 -0
- data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +102 -0
- data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +250 -0
- data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +240 -0
- data/lib/adhearsion/voip/asterisk/config_manager.rb +71 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1681 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +341 -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 +705 -0
- data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +80 -0
- data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
- data/lib/adhearsion/voip/asterisk.rb +4 -0
- data/lib/adhearsion/voip/call.rb +498 -0
- data/lib/adhearsion/voip/call_routing.rb +64 -0
- data/lib/adhearsion/voip/commands.rb +9 -0
- data/lib/adhearsion/voip/constants.rb +39 -0
- data/lib/adhearsion/voip/conveniences.rb +18 -0
- data/lib/adhearsion/voip/dial_plan.rb +250 -0
- data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +37 -0
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +151 -0
- data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +27 -0
- data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +124 -0
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +69 -0
- data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +16 -0
- data/lib/adhearsion/voip/dsl/numerical_string.rb +128 -0
- data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +48 -0
- data/lib/adhearsion/voip/freeswitch/event_handler.rb +58 -0
- data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +129 -0
- data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +38 -0
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +195 -0
- data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +80 -0
- data/lib/adhearsion/voip/menu_state_machine/matchers.rb +123 -0
- data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +57 -0
- data/lib/adhearsion/voip/menu_state_machine/menu_class.rb +149 -0
- data/lib/adhearsion/xmpp/connection.rb +61 -0
- data/lib/adhearsion.rb +46 -0
- 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 +323 -0
data/bin/ahn
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This is the main executable file.
|
4
|
+
|
5
|
+
# Adhearsion, open source collaboration framework
|
6
|
+
# Copyright (C) 2006,2007,2008 Jay Phillips
|
7
|
+
#
|
8
|
+
# This library is free software; you can redistribute it and/or modify it under
|
9
|
+
# the terms of the GNU Lesser General Public License as published by the Free
|
10
|
+
# Software Foundation; either version 2.1 of the License, or (at your option)
|
11
|
+
# any later version.
|
12
|
+
#
|
13
|
+
# This library is distributed in the hope that it will be useful, but WITHOUT
|
14
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
16
|
+
# details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU Lesser General Public License along
|
19
|
+
# with this library; if not, write to the Free Software Foundation, Inc.,
|
20
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
|
22
|
+
$:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
require 'bundler/setup'
|
26
|
+
require 'adhearsion'
|
27
|
+
require 'adhearsion/cli'
|
28
|
+
|
29
|
+
Adhearsion::CLI::AhnCommand.execute!
|
data/bin/ahnctl
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# ahnctl - Adhearsion daemon controller
|
4
|
+
#
|
5
|
+
# Adhearsion, open source collaboration framework
|
6
|
+
# Copyright (C) 2006,2007,2008 Jay Phillips
|
7
|
+
#
|
8
|
+
# This library is free software; you can redistribute it and/or
|
9
|
+
# modify it under the terms of the GNU Lesser General Public
|
10
|
+
# License as published by the Free Software Foundation; either
|
11
|
+
# version 2.1 of the License, or (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This library is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
# Lesser General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU Lesser General Public
|
19
|
+
# License along with this library; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
|
22
|
+
USAGE = "Usage: ahnctl start|stop|restart /path/to/adhearsion/app [--pid-file=/path/to/pid_file.pid]"
|
23
|
+
|
24
|
+
# Blow up if the CLI arguments are invalid
|
25
|
+
abort USAGE unless (2..3).include?(ARGV.size) && %w[start stop restart].include?(ARGV.first)
|
26
|
+
|
27
|
+
# By default, ahnctl will use the version of Adhearsion it was installed with.
|
28
|
+
|
29
|
+
pid_file = ARGV.pop if ARGV.size == 3
|
30
|
+
ahn_command = File.expand_path File.dirname(__FILE__) + "/ahn"
|
31
|
+
app_dir = File.expand_path ARGV.last
|
32
|
+
|
33
|
+
pid_file_path_regexp = /^--pid-file=(.+)$/
|
34
|
+
abort USAGE if pid_file && pid_file !~ pid_file_path_regexp
|
35
|
+
|
36
|
+
# If pid_file is not nil, let's extract the path specified.
|
37
|
+
pid_file &&= File.expand_path pid_file[pid_file_path_regexp,1]
|
38
|
+
|
39
|
+
# If there was no third argument and pid_file is still nil, let's use the default.
|
40
|
+
pid_file ||= app_dir + '/adhearsion.pid'
|
41
|
+
|
42
|
+
abort "Directory is not an Adhearsion application!" unless File.exists?(app_dir + "/.ahnrc")
|
43
|
+
|
44
|
+
def terminate(pid) `kill -s TERM #{pid} 2> /dev/null` end
|
45
|
+
def kill(pid) `kill -s KILL #{pid} 2> /dev/null` end
|
46
|
+
|
47
|
+
# Even if we're starting Adhearsion, we need to make sure to clean up after any stale
|
48
|
+
# pid files. In effect, start is the same as restart.
|
49
|
+
puts "Stopping Adhearsion app at #{app_dir}" if %w[stop restart].include? ARGV.first
|
50
|
+
|
51
|
+
if File.exists?(pid_file)
|
52
|
+
# An Adhearsion process may still be running. Let's kill the other one as cleanly as possible
|
53
|
+
pid = File.read(pid_file).to_i
|
54
|
+
|
55
|
+
# Time to spend waiting for Adhearsion to exit
|
56
|
+
waiting_timeout = Time.now + 15
|
57
|
+
|
58
|
+
terminate pid
|
59
|
+
sleep 0.25 until `ps -p #{pid} | sed -e '1d'`.strip.empty? || Time.now > waiting_timeout
|
60
|
+
kill pid
|
61
|
+
|
62
|
+
`rm -f #{pid_file}`
|
63
|
+
end
|
64
|
+
|
65
|
+
if ['start', 'restart'].include? ARGV.first
|
66
|
+
puts "Starting Adhearsion app at #{app_dir}"
|
67
|
+
`#{ahn_command} start daemon #{app_dir} --pid-file=#{pid_file}`
|
68
|
+
end
|
data/bin/jahn
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
|
3
|
+
# This "jahn" script is "ahn" for JRUBY!
|
4
|
+
|
5
|
+
# Adhearsion, open source collaboration framework
|
6
|
+
# Copyright (C) 2006,2007,2008 Jay Phillips
|
7
|
+
#
|
8
|
+
# This library is free software; you can redistribute it and/or modify it under
|
9
|
+
# the terms of the GNU Lesser General Public License as published by the Free
|
10
|
+
# Software Foundation; either version 2.1 of the License, or (at your option)
|
11
|
+
# any later version.
|
12
|
+
#
|
13
|
+
# This library is distributed in the hope that it will be useful, but WITHOUT
|
14
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
16
|
+
# details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU Lesser General Public License along
|
19
|
+
# with this library; if not, write to the Free Software Foundation, Inc.,
|
20
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
|
22
|
+
$:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
require 'bundler/setup'
|
26
|
+
require 'adhearsion'
|
27
|
+
require 'adhearsion/cli'
|
28
|
+
|
29
|
+
# jahn will soon have JRuby-specific behavior such as creating a compiled .jar
|
30
|
+
# file from an app.
|
31
|
+
# require 'adhearsion/jruby'
|
32
|
+
|
33
|
+
abort(<<-MESSAGE) unless RUBY_PLATFORM =~ /java/
|
34
|
+
You must use jahn with JRuby! Are you running this script after installing Adhearsion with non-JRuby RubyGems?
|
35
|
+
|
36
|
+
If you don't want to install Adhearsion with the JRuby version of RubyGems, try running jahn directly with an absolute path:
|
37
|
+
|
38
|
+
#{File.expand_path(__FILE__)} start your_app_name
|
39
|
+
|
40
|
+
Note: You must have the jruby executable in your $PATH and $JRUBY_HOME set.
|
41
|
+
MESSAGE
|
42
|
+
|
43
|
+
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
|
@@ -0,0 +1,296 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Adhearsion
|
4
|
+
module CLI
|
5
|
+
module AhnCommand
|
6
|
+
USAGE = <<USAGE
|
7
|
+
Usage:
|
8
|
+
ahn create /path/to/directory
|
9
|
+
ahn start [daemon] [/path/to/directory]
|
10
|
+
ahn version|-v|--v|-version|--version
|
11
|
+
ahn help|-h|--h|--help|-help
|
12
|
+
|
13
|
+
ahn enable component COMPONENT_NAME
|
14
|
+
ahn disable component COMPONENT_NAME
|
15
|
+
ahn create component COMPONENT_NAME
|
16
|
+
USAGE
|
17
|
+
class << self
|
18
|
+
|
19
|
+
def execute!
|
20
|
+
CommandHandler.send(*parse_arguments)
|
21
|
+
rescue CommandHandler::CLIException => error
|
22
|
+
fail_and_print_usage error
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Provides a small abstraction of Kernel::abort().
|
27
|
+
#
|
28
|
+
def fail_and_print_usage(error)
|
29
|
+
Kernel.abort "#{error.message}\n\n#{USAGE}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_arguments(args=ARGV.clone)
|
33
|
+
action = args.shift
|
34
|
+
case action
|
35
|
+
when /^-?-?h(elp)?$/, nil then [:help]
|
36
|
+
when /^-?-?v(ersion)?$/ then [:version]
|
37
|
+
when "create"
|
38
|
+
[:create, *args]
|
39
|
+
when 'start'
|
40
|
+
pid_file_regexp = /^--pid-file=(.+)$/
|
41
|
+
if args.size > 3
|
42
|
+
fail_and_print_usage "Too many arguments supplied!" if args.size > 3
|
43
|
+
elsif args.size == 3
|
44
|
+
fail_and_print_usage "Unrecognized final argument #{args.last}" unless args.last =~ pid_file_regexp
|
45
|
+
pid_file = args.pop[pid_file_regexp, 1]
|
46
|
+
else
|
47
|
+
pid_file = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
if args.first == 'daemon' && args.size == 2
|
51
|
+
path = args.last
|
52
|
+
daemon = true
|
53
|
+
elsif args.size == 1
|
54
|
+
path, daemon = args.first, false
|
55
|
+
else
|
56
|
+
fail_and_print_usage "Invalid format for the start CLI command!"
|
57
|
+
end
|
58
|
+
[:start, path, daemon, pid_file]
|
59
|
+
when '-'
|
60
|
+
[:start, Dir.pwd]
|
61
|
+
when "enable", "disable"
|
62
|
+
if args.size == 1
|
63
|
+
raise CommandHandler::UnknownCommand, "Must supply an argument for what you wish to #{action}"
|
64
|
+
elsif args.size == 2
|
65
|
+
[action, *args]
|
66
|
+
else
|
67
|
+
raise CommandHandler::UnknownCommand, "Too many arguments supplied!"
|
68
|
+
end
|
69
|
+
else
|
70
|
+
[action, *args]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
module CommandHandler
|
76
|
+
class << self
|
77
|
+
|
78
|
+
def create(*args)
|
79
|
+
if args.size.zero?
|
80
|
+
raise CommandHandler::UnknownCommand.new("Must specify something to create!")
|
81
|
+
elsif args.size == 1
|
82
|
+
# We're creating a project
|
83
|
+
path = args.first
|
84
|
+
require 'rubigen'
|
85
|
+
require 'rubigen/scripts/generate'
|
86
|
+
source = RubiGen::PathSource.new(:application,
|
87
|
+
File.join(File.dirname(__FILE__), "../../app_generators"))
|
88
|
+
RubiGen::Base.reset_sources
|
89
|
+
RubiGen::Base.append_sources source
|
90
|
+
RubiGen::Scripts::Generate.new.run([path], :generator => 'ahn')
|
91
|
+
elsif args.size == 2
|
92
|
+
# We're creating a feature (e.g. a component)
|
93
|
+
feature_type, component_name = args
|
94
|
+
|
95
|
+
if feature_type != "component"
|
96
|
+
# At the moment, only components can be created.
|
97
|
+
raise CommandHandler::UnknownCommand.new("Don't know how to create '#{feature_type}'")
|
98
|
+
end
|
99
|
+
|
100
|
+
if component_name !~ /^[a-z][\w_]+$/
|
101
|
+
raise CommandHandler::ComponentError.new("Component name must be lowercase alphanumeric characters " +
|
102
|
+
"and begin with a character")
|
103
|
+
end
|
104
|
+
|
105
|
+
app_path = PathString.from_application_subdirectory Dir.pwd
|
106
|
+
|
107
|
+
if app_path.nil?
|
108
|
+
new_component_dir = File.join Dir.pwd, component_name
|
109
|
+
else
|
110
|
+
puts "Adhearsion application detected. Creating new component at components/#{component_name}"
|
111
|
+
new_component_dir = File.join app_path, "components", component_name
|
112
|
+
end
|
113
|
+
|
114
|
+
raise ComponentError.new("Component #{component_name} already exists!") if File.exists?(new_component_dir)
|
115
|
+
|
116
|
+
# Everything's good. Let's create the component
|
117
|
+
Dir.mkdir new_component_dir
|
118
|
+
|
119
|
+
# Initial component code file
|
120
|
+
Dir.mkdir File.join(new_component_dir, "lib")
|
121
|
+
fn = File.join("lib", "#{component_name}.rb")
|
122
|
+
puts "- #{fn}: Initial component code file"
|
123
|
+
File.open(File.join(new_component_dir, fn),"w") do |file|
|
124
|
+
file.puts <<-RUBY
|
125
|
+
# See http://docs.adhearsion.com for more information on how to write components or
|
126
|
+
# look at the examples in newly-created projects.
|
127
|
+
RUBY
|
128
|
+
end
|
129
|
+
|
130
|
+
# Component configuration
|
131
|
+
Dir.mkdir File.join(new_component_dir, "config")
|
132
|
+
fn = File.join("config", "#{component_name}.yml")
|
133
|
+
puts "- #{fn}: Example component configuration YAML"
|
134
|
+
File.open(File.join(new_component_dir, fn),"w") do |file|
|
135
|
+
file.puts '# You can use this file for component-specific configuration.'
|
136
|
+
end
|
137
|
+
|
138
|
+
# Component example gemspec
|
139
|
+
fn = File.join("#{component_name}.gemspec")
|
140
|
+
puts "- #{fn}: Example component gemspec"
|
141
|
+
File.open(File.join(new_component_dir, fn), "w") do |file|
|
142
|
+
file.puts <<-RUBY
|
143
|
+
GEM_FILES = %w{
|
144
|
+
#{component_name}.gemspec
|
145
|
+
lib/#{component_name}.rb
|
146
|
+
config/#{component_name}.yml
|
147
|
+
}
|
148
|
+
|
149
|
+
Gem::Specification.new do |s|
|
150
|
+
s.name = "#{component_name}"
|
151
|
+
s.version = "0.0.1"
|
152
|
+
|
153
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
154
|
+
s.authors = ["Your Name Here!"]
|
155
|
+
|
156
|
+
s.date = Date.today.to_s
|
157
|
+
s.description = "This Adhearsion component gem has not yet been described."
|
158
|
+
s.email = "noreply@example.com"
|
159
|
+
|
160
|
+
s.files = GEM_FILES
|
161
|
+
|
162
|
+
s.has_rdoc = false
|
163
|
+
s.homepage = "http://adhearsion.com"
|
164
|
+
s.require_paths = ["lib"]
|
165
|
+
s.rubygems_version = "1.2.0"
|
166
|
+
s.summary = "This Adhearsion component gem has no summary."
|
167
|
+
|
168
|
+
s.specification_version = 2
|
169
|
+
end
|
170
|
+
RUBY
|
171
|
+
end
|
172
|
+
|
173
|
+
# Component example spec
|
174
|
+
Dir.mkdir File.join(new_component_dir, "spec")
|
175
|
+
fn = File.join("spec", "#{component_name}_spec.rb")
|
176
|
+
puts "- #{fn}: Example component spec"
|
177
|
+
File.open(File.join(new_component_dir, fn), "w") do |file|
|
178
|
+
file.puts <<-RUBY
|
179
|
+
require 'rubygems'
|
180
|
+
require 'bundler'
|
181
|
+
Bundler.setup
|
182
|
+
Bundler.require
|
183
|
+
|
184
|
+
require 'adhearsion/component_manager/spec_framework'
|
185
|
+
|
186
|
+
component_name.upcase = ComponentTester.new("#{component_name}", File.dirname(__FILE__) + "/../..")
|
187
|
+
RUBY
|
188
|
+
end
|
189
|
+
puts "Created blank component '#{component_name}' at #{new_component_dir}"
|
190
|
+
else
|
191
|
+
raise CommandHandler::UnknownCommand.new("Provided too many arguments to 'create'")
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def start(path, daemon=false, pid_file=nil)
|
196
|
+
raise PathInvalid, path unless File.exists? path + "/.ahnrc"
|
197
|
+
Adhearsion::Initializer.start path, :daemon => daemon, :pid_file => pid_file
|
198
|
+
end
|
199
|
+
|
200
|
+
def version
|
201
|
+
puts "Adhearsion v#{Adhearsion::VERSION::STRING}"
|
202
|
+
end
|
203
|
+
|
204
|
+
def help
|
205
|
+
puts USAGE
|
206
|
+
end
|
207
|
+
|
208
|
+
def enable(type, name)
|
209
|
+
case type
|
210
|
+
when "component"
|
211
|
+
app_path = PathString.from_application_subdirectory Dir.pwd
|
212
|
+
if app_path
|
213
|
+
disabled_component_path = File.join app_path, "components", "disabled", name
|
214
|
+
disabled_components_path = File.join app_path, "components", "disabled"
|
215
|
+
enabled_component_path = File.join app_path, "components", name
|
216
|
+
if File.directory? disabled_component_path
|
217
|
+
FileUtils.mv disabled_component_path, enabled_component_path
|
218
|
+
puts "Enabled component #{name}"
|
219
|
+
elsif File.directory? enabled_component_path
|
220
|
+
raise ComponentError.new("This component is already enabled.")
|
221
|
+
elsif !File.directory? disabled_components_path
|
222
|
+
raise ComponentError.new("There is no components/disabled directory!")
|
223
|
+
else
|
224
|
+
raise ComponentError.new("The requested component was not found.")
|
225
|
+
end
|
226
|
+
else
|
227
|
+
raise PathInvalid.new(Dir.pwd)
|
228
|
+
end
|
229
|
+
else
|
230
|
+
raise UnknownCommand.new("enable #{type}")
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def disable(type, name)
|
235
|
+
case type
|
236
|
+
when "component"
|
237
|
+
app_path = PathString.from_application_subdirectory Dir.pwd
|
238
|
+
if app_path
|
239
|
+
disabled_dir = File.join app_path, "components", "disabled"
|
240
|
+
|
241
|
+
disabled_component_path = File.join disabled_dir, name
|
242
|
+
enabled_component_path = File.join app_path, "components", name
|
243
|
+
|
244
|
+
Dir.mkdir disabled_dir unless File.directory?(disabled_dir)
|
245
|
+
|
246
|
+
if File.directory? enabled_component_path
|
247
|
+
if File.directory?(disabled_component_path)
|
248
|
+
raise ComponentError.new("There is already a disabled component at #{disabled_component_path}")
|
249
|
+
else
|
250
|
+
FileUtils.mv enabled_component_path, disabled_component_path
|
251
|
+
puts "Disabled component #{name}"
|
252
|
+
end
|
253
|
+
else
|
254
|
+
raise ComponentError.new("Could not find component #{name} at #{enabled_component_path} !")
|
255
|
+
end
|
256
|
+
else
|
257
|
+
raise PathInvalid.new(Dir.pwd)
|
258
|
+
end
|
259
|
+
else
|
260
|
+
raise UnknownCommand.new("disable #{type}")
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def method_missing(action, *args)
|
265
|
+
raise UnknownCommand, [action, *args] * " "
|
266
|
+
end
|
267
|
+
|
268
|
+
private
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
class CLIException < StandardError; end
|
273
|
+
|
274
|
+
class UnknownCommand < CLIException
|
275
|
+
def initialize(cmd)
|
276
|
+
super "Unknown command: #{cmd}"
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
class ComponentError < CLIException; end
|
281
|
+
|
282
|
+
class UnknownProject < CLIException
|
283
|
+
def initialize(project)
|
284
|
+
super "Application #{project} does not exist! Have you installed it?"
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
class PathInvalid < CLIException
|
289
|
+
def initialize(path)
|
290
|
+
super "Directory #{path} does not belong to an Adhearsion project!"
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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
|
+
metadata[:initialization_block].call if metadata && metadata[:initialization_block].kind_of?(Proc)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'adhearsion/component_manager/component_tester'
|
2
|
+
begin
|
3
|
+
require 'rspec'
|
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
|
+
module ComponentConfigurationSpecHelper
|
9
|
+
def mock_component_config_with(new_config)
|
10
|
+
Object.send(:remove_const, :COMPONENTS) rescue nil
|
11
|
+
Object.send(:const_set, :COMPONENTS, OpenStruct.new(new_config))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.mock_with :rspec
|
17
|
+
config.include ComponentConfigurationSpecHelper
|
18
|
+
end
|