adhearsion 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rspec +3 -0
- data/CHANGELOG +12 -0
- data/README.markdown +1 -10
- data/Rakefile +6 -28
- data/adhearsion.gemspec +21 -38
- data/app_generators/ahn/ahn_generator.rb +3 -4
- data/app_generators/ahn/templates/config/environment.rb +4 -0
- data/app_generators/ahn/templates/config/startup.rb +11 -5
- data/app_generators/ahn/templates/script/ahn +8 -0
- data/lib/adhearsion/cli.rb +5 -298
- data/lib/adhearsion/commands.rb +308 -0
- data/lib/adhearsion/events_support.rb +0 -20
- data/lib/adhearsion/initializer/asterisk.rb +0 -1
- data/lib/adhearsion/initializer/configuration.rb +4 -1
- data/lib/adhearsion/logging.rb +18 -3
- data/lib/adhearsion/script_ahn_loader.rb +30 -0
- data/lib/adhearsion/tasks/testing.rb +39 -8
- data/lib/adhearsion/version.rb +2 -2
- data/lib/adhearsion/voip/asterisk/agi_server.rb +15 -8
- data/lib/adhearsion/voip/asterisk/commands.rb +340 -86
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +0 -2
- data/lib/adhearsion/voip/call.rb +11 -3
- data/lib/adhearsion/voip/commands.rb +5 -1
- data/lib/adhearsion/voip/dial_plan.rb +4 -0
- data/lib/theatre/invocation.rb +3 -0
- data/spec/{ahn_command_spec.rb → adhearsion/cli_spec.rb} +11 -0
- data/spec/{component_manager_spec.rb → adhearsion/component_manager_spec.rb} +0 -0
- data/spec/{constants_spec.rb → adhearsion/constants_spec.rb} +0 -0
- data/spec/{drb_spec.rb → adhearsion/drb_spec.rb} +0 -0
- data/spec/{fixtures → adhearsion/fixtures}/dialplan.rb +0 -0
- data/spec/{foundation → adhearsion/foundation}/event_socket_spec.rb +0 -0
- data/spec/{host_definitions_spec.rb → adhearsion/host_definitions_spec.rb} +0 -0
- data/spec/{initializer → adhearsion/initializer}/configuration_spec.rb +21 -0
- data/spec/{initializer → adhearsion/initializer}/loading_spec.rb +0 -0
- data/spec/{initializer → adhearsion/initializer}/paths_spec.rb +0 -0
- data/spec/{initialization_spec.rb → adhearsion/initializer_spec.rb} +0 -0
- data/spec/{logging_spec.rb → adhearsion/logging_spec.rb} +6 -0
- data/spec/{relationship_properties_spec.rb → adhearsion/relationship_properties_spec.rb} +0 -0
- data/spec/{voip → adhearsion/voip}/asterisk/agi_server_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/asterisk/ami/ami_spec.rb +1 -0
- data/spec/{voip → adhearsion/voip}/asterisk/ami/lexer/ami_fixtures.yml +0 -0
- data/spec/{voip → adhearsion/voip}/asterisk/ami/lexer/lexer_story +0 -0
- data/spec/{voip → adhearsion/voip}/asterisk/ami/lexer/lexer_story.rb +0 -0
- data/spec/{voip → adhearsion/voip}/asterisk/ami/lexer/story_helper.rb +0 -0
- data/spec/{voip → adhearsion/voip}/asterisk/commands_spec.rb +549 -47
- data/spec/{voip → adhearsion/voip}/asterisk/config_file_generators/agents_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/asterisk/config_file_generators/queues_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/asterisk/config_file_generators/voicemail_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/asterisk/config_manager_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/asterisk/menu_command/calculated_match_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/asterisk/menu_command/matchers_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/call_routing_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/dialplan_manager_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/dsl/dialing_dsl_spec.rb +1 -1
- data/spec/{voip → adhearsion/voip}/dsl/dispatcher_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/dsl/dispatcher_spec_helper.rb +0 -0
- data/spec/{voip → adhearsion/voip}/dsl/parser_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/freeswitch/basic_connection_manager_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/freeswitch/inbound_connection_manager_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/freeswitch/oes_server_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/numerical_string_spec.rb +0 -0
- data/spec/{voip → adhearsion/voip}/phone_number_spec.rb +0 -0
- data/spec/spec_helper.rb +36 -89
- data/spec/support/initializer_stubs.rb +47 -0
- data/spec/support/the_following_code.rb +3 -0
- data/{theatre-spec → spec/theatre}/dsl_examples/simple_before_call.rb +0 -0
- data/{theatre-spec → spec/theatre}/dsl_spec.rb +26 -0
- data/{theatre-spec → spec/theatre}/invocation_spec.rb +6 -10
- data/{theatre-spec → spec/theatre}/namespace_spec.rb +0 -0
- data/{theatre-spec → spec/theatre}/spec_helper_spec.rb +0 -0
- data/{theatre-spec → spec/theatre}/theatre_class_spec.rb +2 -5
- metadata +254 -271
- data/app_generators/ahn/templates/components/disabled/sandbox/sandbox.rb +0 -104
- data/app_generators/ahn/templates/components/disabled/sandbox/sandbox.yml +0 -2
- data/lib/adhearsion/voip/asterisk/super_manager.rb +0 -19
- data/spec/silence.rb +0 -10
- data/spec/voip/asterisk/ami/old_tests.rb +0 -204
- data/spec/voip/asterisk/ami/super_manager/super_manager_story +0 -25
- data/spec/voip/asterisk/ami/super_manager/super_manager_story.rb +0 -15
- data/spec/voip/asterisk/ami/super_manager/super_manager_story_helper.rb +0 -5
- data/theatre-spec/dsl_examples/dynamic_stomp.rb +0 -7
- data/theatre-spec/spec_helper.rb +0 -37
data/.gitignore
CHANGED
data/.rspec
ADDED
data/CHANGELOG
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
1.2.0
|
2
|
+
- New method: #play_or_speak allows playback of an audio file with TTS fallback
|
3
|
+
- #input now takes :speak as a hash for TTS prompt or fallback
|
4
|
+
- New method: #speak provides abstracted TTS rendering for UniMRCP and Cepstral
|
5
|
+
- Allow leading "+" in Caller ID (E.164 format)
|
6
|
+
- Allow using --pid-file without "daemon" for JRuby
|
7
|
+
- Allow passing a block to #input to enable caller to detect when enough digits are collected.
|
8
|
+
- Fix some issues with starting apps outside of their directory, generally related to Bundler/gem environments
|
9
|
+
- Allow configuration of logging outputters/formatters
|
10
|
+
- Using ahn_log in a dialplan context or on a call object logs to the call's context, named after its unique identifier
|
11
|
+
- New method: #record_to_file with more useful return values
|
12
|
+
|
1
13
|
1.1.1
|
2
14
|
- Command#play now returns false if audio failed to play
|
3
15
|
- Added new commands (#play!, #interruptible_play!, #input!) which raise PlaybackError if audio fails to play
|
data/README.markdown
CHANGED
@@ -16,18 +16,9 @@ Adhearsion has...
|
|
16
16
|
* Easy interactive communication via XMPP instant messages using the Blather library
|
17
17
|
* Good regression test coverage
|
18
18
|
|
19
|
-
Use the public Adhearsion sandbox!
|
20
|
-
==================================
|
21
|
-
|
22
|
-
Don't want to screw with setting up a telephony system? You can test your Adhearsion applications using our public sandbox!
|
23
|
-
|
24
|
-
Visit [http://adhearsion.com/getting_started](http://adhearsion.com/getting_started) for more information!
|
25
|
-
|
26
|
-
Yes, in minutes you can be controlling your cell phone for free! :)
|
27
|
-
|
28
19
|
Documentation
|
29
20
|
=============
|
30
21
|
|
31
22
|
Visit [Adhearsion's website](http://adhearsion.com) for code examples and more information about the project. Also checkout the [Adhearsion wiki on Github](http://github.com/adhearsion/adhearsion/wiki) for community documentation.
|
32
23
|
|
33
|
-
If you're having trouble, you may want to try asking your question on the IRC channel (#adhearsion on irc.freenode.net), [mailing list](http://groups.google.com/group/adhearsion) or, if you've found a bug, report it on the [bug tracker](
|
24
|
+
If you're having trouble, you may want to try asking your question on the IRC channel (#adhearsion on irc.freenode.net), [mailing list](http://groups.google.com/group/adhearsion) or, if you've found a bug, report it on the [bug tracker](https://github.com/adhearsion/adhearsion/issues).
|
data/Rakefile
CHANGED
@@ -2,41 +2,19 @@
|
|
2
2
|
ENV['RUBY_FLAGS'] = "-I#{%w(lib ext bin spec).join(File::PATH_SEPARATOR)}"
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
|
-
require 'bundler'
|
6
|
-
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
require 'bundler/setup'
|
7
7
|
require 'date'
|
8
8
|
require 'adhearsion/version'
|
9
9
|
|
10
10
|
task :default => :spec
|
11
11
|
task :gem => :build
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
require 'rspec/core/rake_task'
|
16
|
-
rescue LoadError
|
17
|
-
abort "You must install RSpec: sudo gem install rspec"
|
18
|
-
end
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
RSpec::Core::RakeTask.new
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
desc "Run all RSpecs for Theatre"
|
24
|
-
RSpec::Core::RakeTask.new(:theatre_specs) do |t|
|
25
|
-
t.pattern = 'theatre-spec/**/*_spec.rb'
|
26
|
-
end
|
27
|
-
|
28
|
-
begin
|
29
|
-
require 'rcov/rcovtask'
|
30
|
-
Rcov::RcovTask.new do |t|
|
31
|
-
t.libs << "spec"
|
32
|
-
t.test_files = Dir['spec/**/*_spec.rb']
|
33
|
-
t.output_dir = 'coverage'
|
34
|
-
t.verbose = true
|
35
|
-
t.rcov_opts.concat %w[--sort coverage --sort-reverse -x gems -x /var]
|
36
|
-
end
|
37
|
-
rescue LoadError
|
38
|
-
STDERR.puts "Could not load rcov tasks -- rcov does not appear to be installed. Continuing anyway."
|
39
|
-
end
|
16
|
+
require 'ci/reporter/rake/rspec'
|
17
|
+
task :ci => ['ci:setup:rspec', :spec]
|
40
18
|
|
41
19
|
begin
|
42
20
|
require 'yard'
|
data/adhearsion.gemspec
CHANGED
@@ -13,48 +13,31 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = "Adhearsion is an open-source telephony development framework"
|
14
14
|
s.date = Date.today.to_s
|
15
15
|
|
16
|
-
s.rubyforge_project = "adhearsion"
|
17
|
-
s.rubygems_version = "1.2.0"
|
18
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
19
|
-
|
20
16
|
s.files = `git ls-files`.split("\n")
|
21
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
19
|
s.require_paths = ["lib"]
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
s.add_runtime_dependency("i18n")
|
38
|
-
s.add_runtime_dependency("rubigen", [">= 1.5.6"])
|
39
|
-
s.add_runtime_dependency("rake")
|
40
|
-
s.add_runtime_dependency("pry")
|
21
|
+
# Runtime dependencies
|
22
|
+
s.add_runtime_dependency "bundler", [">= 1.0.10"]
|
23
|
+
s.add_runtime_dependency "log4r", [">= 1.0.5"]
|
24
|
+
s.add_runtime_dependency "activesupport", [">= 2.1.0"]
|
25
|
+
# i18n is only strictly a dependency for ActiveSupport >= 3.0.0
|
26
|
+
# Since it doesn't conflict with <3.0.0 we'll require it to be
|
27
|
+
# on the safe side.
|
28
|
+
s.add_runtime_dependency "i18n"
|
29
|
+
s.add_runtime_dependency "json"
|
30
|
+
s.add_runtime_dependency "rubigen", [">= 1.5.6"]
|
31
|
+
s.add_runtime_dependency "rake"
|
32
|
+
s.add_runtime_dependency "pry"
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
s.add_dependency("activesupport", [">= 2.1.0"])
|
52
|
-
s.add_dependency("rake")
|
53
|
-
end
|
54
|
-
else
|
55
|
-
s.add_dependency("bundler", [">= 1.0.10"])
|
56
|
-
s.add_dependency("log4r", [">= 1.0.5"])
|
57
|
-
s.add_dependency("activesupport", [">= 2.1.0"])
|
58
|
-
s.add_dependency("rake")
|
59
|
-
end
|
34
|
+
# Development dependencies
|
35
|
+
s.add_development_dependency 'rubigen', [">= 1.5.6"]
|
36
|
+
s.add_development_dependency 'rspec', [">= 2.4.0"]
|
37
|
+
s.add_development_dependency 'flexmock'
|
38
|
+
s.add_development_dependency 'activerecord', [">= 2.1.0"]
|
39
|
+
s.add_development_dependency 'rake'
|
40
|
+
s.add_development_dependency 'simplecov'
|
41
|
+
s.add_development_dependency 'simplecov-rcov'
|
42
|
+
s.add_development_dependency 'ci_reporter'
|
60
43
|
end
|
@@ -41,15 +41,14 @@ class AhnGenerator < RubiGen::Base
|
|
41
41
|
m.file *["components/disabled/restful_rpc/example-client.rb"]*2
|
42
42
|
m.file *["components/disabled/restful_rpc/spec/restful_rpc_spec.rb"]*2
|
43
43
|
|
44
|
-
m.file *["
|
45
|
-
m.file *["components/disabled/sandbox/sandbox.rb"]*2
|
46
|
-
|
44
|
+
m.file *["config/environment.rb"]*2
|
47
45
|
m.file *["config/startup.rb"]*2
|
48
46
|
m.file *["dialplan.rb"]*2
|
49
47
|
m.file *["events.rb"]*2
|
50
48
|
m.file *["README"]*2
|
51
49
|
m.file *["Rakefile"]*2
|
52
50
|
m.file *["Gemfile"]*2
|
51
|
+
m.file *["script/ahn"]*2
|
53
52
|
|
54
53
|
# m.dependency "install_rubigen_scripts", [destination_root, 'ahn', 'adhearsion', 'test_spec'],
|
55
54
|
# :shebang => options[:shebang], :collision => :force
|
@@ -89,9 +88,9 @@ EOS
|
|
89
88
|
components/simon_game
|
90
89
|
components/disabled/stomp_gateway
|
91
90
|
components/disabled/xmpp_gateway
|
92
|
-
components/disabled/sandbox
|
93
91
|
components/ami_remote
|
94
92
|
components/disabled/restful_rpc/spec
|
95
93
|
config
|
94
|
+
script
|
96
95
|
)
|
97
96
|
end
|
@@ -1,7 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'bundler'
|
3
|
-
Bundler.setup
|
4
|
-
Bundler.require
|
1
|
+
require File.join(File.dirname(__FILE__), 'environment')
|
5
2
|
|
6
3
|
Adhearsion::Configuration.configure do |config|
|
7
4
|
|
@@ -12,7 +9,11 @@ Adhearsion::Configuration.configure do |config|
|
|
12
9
|
# List the gem names here:
|
13
10
|
# config.add_component "ahn_test_component"
|
14
11
|
|
15
|
-
#
|
12
|
+
# Log configuration
|
13
|
+
# :level : Supported levels (in increasing severity) -- :debug < :info < :warn < :error < :fatal
|
14
|
+
# :outputters : An array of log outputters to use. The default is to log to stdout and log/adhearsion.log
|
15
|
+
# :formatters : An array of log formatters to apply to the outputters in use
|
16
|
+
# :formatter : A log formatter to apply to all active outputters
|
16
17
|
config.logging :level => :info
|
17
18
|
|
18
19
|
# Whether incoming calls be automatically answered. Defaults to true.
|
@@ -32,6 +33,11 @@ Adhearsion::Configuration.configure do |config|
|
|
32
33
|
config.enable_asterisk :argument_delimiter => '|'
|
33
34
|
# config.asterisk.enable_ami :host => "127.0.0.1", :username => "admin", :password => "password", :events => true
|
34
35
|
|
36
|
+
# Adhearsion supports two possible speech engines with Asterisk: UniMRCP and Cepstral.
|
37
|
+
# Uncomment one of the below if you have it available.
|
38
|
+
# config.asterisk.speech_engine = :cepstral
|
39
|
+
# config.asterisk.speech_engine = :unimrcp
|
40
|
+
|
35
41
|
# config.enable_drb
|
36
42
|
|
37
43
|
# Streamlined Rails integration! The first argument should be a relative or absolute path to
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# This command will automatically be run when you run "ahn" with the Adhearsion gem installed from the root of your application.
|
2
|
+
|
3
|
+
require File.expand_path('../../config/environment', __FILE__)
|
4
|
+
|
5
|
+
require 'adhearsion'
|
6
|
+
require 'adhearsion/commands'
|
7
|
+
|
8
|
+
Adhearsion::CLI::AhnCommand.execute!
|
data/lib/adhearsion/cli.rb
CHANGED
@@ -1,300 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'adhearsion/script_ahn_loader'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
USAGE = <<USAGE
|
7
|
-
Usage:
|
8
|
-
ahn create /path/to/directory
|
9
|
-
ahn start [console|daemon] [/path/to/directory]
|
10
|
-
ahn version|-v|--v|-version|--version
|
11
|
-
ahn help|-h|--h|--help|-help
|
3
|
+
# If we are inside an Adhearsion application this method performs an exec and thus
|
4
|
+
# the rest of this script is not run.
|
5
|
+
Adhearsion::ScriptAhnLoader.exec_script_ahn!
|
12
6
|
|
13
|
-
|
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
|
-
raise CommandHandler::CLIException, "Too many arguments supplied!" if args.size > 3
|
43
|
-
elsif args.size == 3
|
44
|
-
raise CommandHandler::CLIException, "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.size == 2
|
51
|
-
path = args.last
|
52
|
-
if args.first =~ /daemon|console/
|
53
|
-
mode = args.first.to_sym
|
54
|
-
else
|
55
|
-
raise CommandHandler::CLIException, "Invalid start mode requested: #{args.first}"
|
56
|
-
end
|
57
|
-
elsif args.size == 1
|
58
|
-
path, mode = args.first, :foreground
|
59
|
-
else
|
60
|
-
raise CommandHandler::CLIException, "Invalid format for the start CLI command!"
|
61
|
-
end
|
62
|
-
[:start, path, mode, pid_file]
|
63
|
-
when '-'
|
64
|
-
[:start, Dir.pwd]
|
65
|
-
when "enable", "disable"
|
66
|
-
if args.size == 1
|
67
|
-
raise CommandHandler::UnknownCommand, "Must supply an argument for what you wish to #{action}"
|
68
|
-
elsif args.size == 2
|
69
|
-
[action, *args]
|
70
|
-
else
|
71
|
-
raise CommandHandler::UnknownCommand, "Too many arguments supplied!"
|
72
|
-
end
|
73
|
-
else
|
74
|
-
[action, *args]
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
module CommandHandler
|
80
|
-
class << self
|
81
|
-
|
82
|
-
def create(*args)
|
83
|
-
if args.size.zero?
|
84
|
-
raise CommandHandler::UnknownCommand.new("Must specify something to create!")
|
85
|
-
elsif args.size == 1
|
86
|
-
# We're creating a project
|
87
|
-
path = args.first
|
88
|
-
require 'rubigen'
|
89
|
-
require 'rubigen/scripts/generate'
|
90
|
-
source = RubiGen::PathSource.new(:application,
|
91
|
-
File.join(File.dirname(__FILE__), "../../app_generators"))
|
92
|
-
RubiGen::Base.reset_sources
|
93
|
-
RubiGen::Base.append_sources source
|
94
|
-
RubiGen::Scripts::Generate.new.run([path], :generator => 'ahn')
|
95
|
-
elsif args.size == 2
|
96
|
-
# We're creating a feature (e.g. a component)
|
97
|
-
feature_type, component_name = args
|
98
|
-
|
99
|
-
if feature_type != "component"
|
100
|
-
# At the moment, only components can be created.
|
101
|
-
raise CommandHandler::UnknownCommand.new("Don't know how to create '#{feature_type}'")
|
102
|
-
end
|
103
|
-
|
104
|
-
if component_name !~ /^[a-z][\w_]+$/
|
105
|
-
raise CommandHandler::ComponentError.new("Component name must be lowercase alphanumeric characters " +
|
106
|
-
"and begin with a character")
|
107
|
-
end
|
108
|
-
|
109
|
-
app_path = PathString.from_application_subdirectory Dir.pwd
|
110
|
-
|
111
|
-
if app_path.nil?
|
112
|
-
new_component_dir = File.join Dir.pwd, component_name
|
113
|
-
else
|
114
|
-
puts "Adhearsion application detected. Creating new component at components/#{component_name}"
|
115
|
-
new_component_dir = File.join app_path, "components", component_name
|
116
|
-
end
|
117
|
-
|
118
|
-
raise ComponentError.new("Component #{component_name} already exists!") if File.exists?(new_component_dir)
|
119
|
-
|
120
|
-
# Everything's good. Let's create the component
|
121
|
-
Dir.mkdir new_component_dir
|
122
|
-
|
123
|
-
# Initial component code file
|
124
|
-
Dir.mkdir File.join(new_component_dir, "lib")
|
125
|
-
fn = File.join("lib", "#{component_name}.rb")
|
126
|
-
puts "- #{fn}: Initial component code file"
|
127
|
-
File.open(File.join(new_component_dir, fn),"w") do |file|
|
128
|
-
file.puts <<-RUBY
|
129
|
-
# See http://docs.adhearsion.com for more information on how to write components or
|
130
|
-
# look at the examples in newly-created projects.
|
131
|
-
RUBY
|
132
|
-
end
|
133
|
-
|
134
|
-
# Component configuration
|
135
|
-
Dir.mkdir File.join(new_component_dir, "config")
|
136
|
-
fn = File.join("config", "#{component_name}.yml")
|
137
|
-
puts "- #{fn}: Example component configuration YAML"
|
138
|
-
File.open(File.join(new_component_dir, fn),"w") do |file|
|
139
|
-
file.puts '# You can use this file for component-specific configuration.'
|
140
|
-
end
|
141
|
-
|
142
|
-
# Component example gemspec
|
143
|
-
fn = File.join("#{component_name}.gemspec")
|
144
|
-
puts "- #{fn}: Example component gemspec"
|
145
|
-
File.open(File.join(new_component_dir, fn), "w") do |file|
|
146
|
-
file.puts <<-RUBY
|
147
|
-
GEM_FILES = %w{
|
148
|
-
#{component_name}.gemspec
|
149
|
-
lib/#{component_name}.rb
|
150
|
-
config/#{component_name}.yml
|
151
|
-
}
|
152
|
-
|
153
|
-
Gem::Specification.new do |s|
|
154
|
-
s.name = "#{component_name}"
|
155
|
-
s.version = "0.0.1"
|
156
|
-
|
157
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
158
|
-
s.authors = ["Your Name Here!"]
|
159
|
-
|
160
|
-
s.date = Date.today.to_s
|
161
|
-
s.description = "This Adhearsion component gem has not yet been described."
|
162
|
-
s.email = "noreply@example.com"
|
163
|
-
|
164
|
-
s.files = GEM_FILES
|
165
|
-
|
166
|
-
s.has_rdoc = false
|
167
|
-
s.homepage = "http://adhearsion.com"
|
168
|
-
s.require_paths = ["lib"]
|
169
|
-
s.rubygems_version = "1.2.0"
|
170
|
-
s.summary = "This Adhearsion component gem has no summary."
|
171
|
-
|
172
|
-
s.specification_version = 2
|
173
|
-
end
|
174
|
-
RUBY
|
175
|
-
end
|
176
|
-
|
177
|
-
# Component example spec
|
178
|
-
Dir.mkdir File.join(new_component_dir, "spec")
|
179
|
-
fn = File.join("spec", "#{component_name}_spec.rb")
|
180
|
-
puts "- #{fn}: Example component spec"
|
181
|
-
File.open(File.join(new_component_dir, fn), "w") do |file|
|
182
|
-
file.puts <<-RUBY
|
183
|
-
require 'rubygems'
|
184
|
-
require 'bundler'
|
185
|
-
Bundler.setup
|
186
|
-
Bundler.require
|
187
|
-
|
188
|
-
require 'adhearsion/component_manager/spec_framework'
|
189
|
-
|
190
|
-
component_name.upcase = ComponentTester.new("#{component_name}", File.dirname(__FILE__) + "/../..")
|
191
|
-
RUBY
|
192
|
-
end
|
193
|
-
puts "Created blank component '#{component_name}' at #{new_component_dir}"
|
194
|
-
else
|
195
|
-
raise CommandHandler::UnknownCommand.new("Provided too many arguments to 'create'")
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
def start(path, mode=:foreground, pid_file=nil)
|
200
|
-
raise PathInvalid, path unless File.exists? path + "/.ahnrc"
|
201
|
-
Adhearsion::Initializer.start path, :mode => mode, :pid_file => pid_file
|
202
|
-
end
|
203
|
-
|
204
|
-
def version
|
205
|
-
puts "Adhearsion v#{Adhearsion::VERSION::STRING}"
|
206
|
-
end
|
207
|
-
|
208
|
-
def help
|
209
|
-
puts USAGE
|
210
|
-
end
|
211
|
-
|
212
|
-
def enable(type, name)
|
213
|
-
case type
|
214
|
-
when "component"
|
215
|
-
app_path = PathString.from_application_subdirectory Dir.pwd
|
216
|
-
if app_path
|
217
|
-
disabled_component_path = File.join app_path, "components", "disabled", name
|
218
|
-
disabled_components_path = File.join app_path, "components", "disabled"
|
219
|
-
enabled_component_path = File.join app_path, "components", name
|
220
|
-
if File.directory? disabled_component_path
|
221
|
-
FileUtils.mv disabled_component_path, enabled_component_path
|
222
|
-
puts "Enabled component #{name}"
|
223
|
-
elsif File.directory? enabled_component_path
|
224
|
-
raise ComponentError.new("This component is already enabled.")
|
225
|
-
elsif !File.directory? disabled_components_path
|
226
|
-
raise ComponentError.new("There is no components/disabled directory!")
|
227
|
-
else
|
228
|
-
raise ComponentError.new("The requested component was not found.")
|
229
|
-
end
|
230
|
-
else
|
231
|
-
raise PathInvalid.new(Dir.pwd)
|
232
|
-
end
|
233
|
-
else
|
234
|
-
raise UnknownCommand.new("enable #{type}")
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
def disable(type, name)
|
239
|
-
case type
|
240
|
-
when "component"
|
241
|
-
app_path = PathString.from_application_subdirectory Dir.pwd
|
242
|
-
if app_path
|
243
|
-
disabled_dir = File.join app_path, "components", "disabled"
|
244
|
-
|
245
|
-
disabled_component_path = File.join disabled_dir, name
|
246
|
-
enabled_component_path = File.join app_path, "components", name
|
247
|
-
|
248
|
-
Dir.mkdir disabled_dir unless File.directory?(disabled_dir)
|
249
|
-
|
250
|
-
if File.directory? enabled_component_path
|
251
|
-
if File.directory?(disabled_component_path)
|
252
|
-
raise ComponentError.new("There is already a disabled component at #{disabled_component_path}")
|
253
|
-
else
|
254
|
-
FileUtils.mv enabled_component_path, disabled_component_path
|
255
|
-
puts "Disabled component #{name}"
|
256
|
-
end
|
257
|
-
else
|
258
|
-
raise ComponentError.new("Could not find component #{name} at #{enabled_component_path} !")
|
259
|
-
end
|
260
|
-
else
|
261
|
-
raise PathInvalid.new(Dir.pwd)
|
262
|
-
end
|
263
|
-
else
|
264
|
-
raise UnknownCommand.new("disable #{type}")
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
def method_missing(action, *args)
|
269
|
-
raise UnknownCommand, [action, *args] * " "
|
270
|
-
end
|
271
|
-
|
272
|
-
private
|
273
|
-
|
274
|
-
end
|
275
|
-
|
276
|
-
class CLIException < StandardError; end
|
277
|
-
|
278
|
-
class UnknownCommand < CLIException
|
279
|
-
def initialize(cmd)
|
280
|
-
super "Unknown command: #{cmd}"
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
class ComponentError < CLIException; end
|
285
|
-
|
286
|
-
class UnknownProject < CLIException
|
287
|
-
def initialize(project)
|
288
|
-
super "Application #{project} does not exist! Have you installed it?"
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
class PathInvalid < CLIException
|
293
|
-
def initialize(path)
|
294
|
-
super "Directory #{path} does not belong to an Adhearsion project!"
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
|
-
end
|
299
|
-
end
|
300
|
-
end
|
7
|
+
require 'adhearsion/commands'
|