adhearsion 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/CHANGELOG +11 -2
  2. data/EVENTS +1 -1
  3. data/Rakefile +4 -4
  4. data/adhearsion.gemspec +8 -4
  5. data/app_generators/ahn/USAGE +3 -3
  6. data/app_generators/ahn/ahn_generator.rb +11 -11
  7. data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +3 -3
  8. data/app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb +6 -6
  9. data/app_generators/ahn/templates/components/disabled/restful_rpc/restful_rpc.rb +16 -16
  10. data/app_generators/ahn/templates/components/disabled/restful_rpc/spec/restful_rpc_spec.rb +42 -42
  11. data/app_generators/ahn/templates/components/disabled/sandbox/sandbox.rb +11 -11
  12. data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +1 -1
  13. data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +6 -6
  14. data/app_generators/ahn/templates/components/simon_game/simon_game.rb +4 -4
  15. data/app_generators/ahn/templates/config/startup.rb +31 -16
  16. data/bin/ahn +3 -3
  17. data/bin/ahnctl +8 -8
  18. data/bin/jahn +3 -3
  19. data/examples/asterisk_manager_interface/standalone.rb +2 -2
  20. data/lib/adhearsion.rb +4 -2
  21. data/lib/adhearsion/cli.rb +31 -31
  22. data/lib/adhearsion/component_manager.rb +39 -39
  23. data/lib/adhearsion/component_manager/component_tester.rb +14 -14
  24. data/lib/adhearsion/component_manager/spec_framework.rb +1 -1
  25. data/lib/adhearsion/events_support.rb +12 -12
  26. data/lib/adhearsion/foundation/blank_slate.rb +1 -1
  27. data/lib/adhearsion/foundation/custom_daemonizer.rb +2 -2
  28. data/lib/adhearsion/foundation/event_socket.rb +26 -26
  29. data/lib/adhearsion/foundation/future_resource.rb +6 -6
  30. data/lib/adhearsion/foundation/metaprogramming.rb +2 -2
  31. data/lib/adhearsion/foundation/numeric.rb +3 -3
  32. data/lib/adhearsion/foundation/relationship_properties.rb +7 -7
  33. data/lib/adhearsion/foundation/string.rb +8 -8
  34. data/lib/adhearsion/foundation/synchronized_hash.rb +8 -8
  35. data/lib/adhearsion/host_definitions.rb +16 -16
  36. data/lib/adhearsion/initializer.rb +74 -65
  37. data/lib/adhearsion/initializer/asterisk.rb +15 -9
  38. data/lib/adhearsion/initializer/configuration.rb +54 -39
  39. data/lib/adhearsion/initializer/database.rb +4 -4
  40. data/lib/adhearsion/initializer/drb.rb +6 -6
  41. data/lib/adhearsion/initializer/freeswitch.rb +1 -1
  42. data/lib/adhearsion/initializer/ldap.rb +51 -0
  43. data/lib/adhearsion/initializer/rails.rb +8 -8
  44. data/lib/adhearsion/logging.rb +16 -16
  45. data/lib/adhearsion/tasks/deprecations.rb +12 -12
  46. data/lib/adhearsion/tasks/generating.rb +2 -2
  47. data/lib/adhearsion/tasks/testing.rb +7 -7
  48. data/lib/adhearsion/version.rb +1 -1
  49. data/lib/adhearsion/voip/asterisk/agi_server.rb +44 -14
  50. data/lib/adhearsion/voip/asterisk/commands.rb +281 -237
  51. data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +8 -8
  52. data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +14 -14
  53. data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +16 -16
  54. data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +39 -39
  55. data/lib/adhearsion/voip/asterisk/config_manager.rb +13 -13
  56. data/lib/adhearsion/voip/asterisk/manager_interface.rb +91 -87
  57. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +739 -739
  58. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +60 -60
  59. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +16 -16
  60. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +1 -1
  61. data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +13 -13
  62. data/lib/adhearsion/voip/asterisk/super_manager.rb +3 -3
  63. data/lib/adhearsion/voip/call.rb +101 -64
  64. data/lib/adhearsion/voip/call_routing.rb +9 -9
  65. data/lib/adhearsion/voip/constants.rb +7 -7
  66. data/lib/adhearsion/voip/conveniences.rb +1 -1
  67. data/lib/adhearsion/voip/dial_plan.rb +42 -40
  68. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +27 -27
  69. data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +1 -1
  70. data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +6 -6
  71. data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +17 -17
  72. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +7 -7
  73. data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +2 -2
  74. data/lib/adhearsion/voip/dsl/numerical_string.rb +3 -3
  75. data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +7 -7
  76. data/lib/adhearsion/voip/freeswitch/event_handler.rb +1 -1
  77. data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +20 -20
  78. data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +5 -5
  79. data/lib/adhearsion/voip/freeswitch/oes_server.rb +33 -33
  80. data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +1 -1
  81. data/lib/adhearsion/voip/menu_state_machine/matchers.rb +2 -2
  82. data/lib/adhearsion/voip/menu_state_machine/menu_class.rb +9 -9
  83. data/lib/theatre.rb +18 -18
  84. data/lib/theatre/callback_definition_loader.rb +17 -17
  85. data/lib/theatre/guid.rb +6 -6
  86. data/lib/theatre/invocation.rb +19 -19
  87. data/lib/theatre/namespace_manager.rb +28 -28
  88. metadata +55 -14
@@ -6,7 +6,7 @@ SANDBOX_VERSION = 1.0
6
6
  initialization do
7
7
  # We shouldn't start initializing until after the AGI server has initialized.
8
8
  Events.register_callback(:after_initialized) do
9
-
9
+
10
10
  config = if COMPONENTS.sandbox.has_key? "connect_to"
11
11
  {"connect_to" => COMPONENTS.sandbox["connect_to"]}
12
12
  else
@@ -21,24 +21,24 @@ initialization do
21
21
  next
22
22
  end
23
23
  end
24
-
24
+
25
25
  begin
26
26
  # The "connect_to" key is what this version supports
27
27
  if config.kind_of?(Hash) && config.has_key?("connect_to")
28
28
  config = config['connect_to']
29
-
29
+
30
30
  host, port = config.values_at "host", "port"
31
-
31
+
32
32
  username, password = COMPONENTS.sandbox["username"].to_s, COMPONENTS.sandbox["password"].to_s
33
-
33
+
34
34
  if username.blank? || password.blank? || username == "user123"
35
35
  ahn_log.sandbox.error "You must specify your username and password in this component's config file!"
36
36
  next
37
37
  end
38
-
38
+
39
39
  # Part of the AGI-superset protocol we use to log in.
40
40
  identifying_hash = MD5.md5(username + ":" + password).to_s
41
-
41
+
42
42
  if host.nil? || port.nil?
43
43
  ahn_log.sandbox.error "Invalid YAML returned from server! Skipping sandbox initialization!"
44
44
  next
@@ -55,14 +55,14 @@ initialization do
55
55
  next
56
56
  end
57
57
  response.chomp!
58
- case
59
- when "authentication accepted"
58
+ case
59
+ when "authentication accepted"
60
60
  ahn_log.sandbox "Authentication accepted"
61
-
61
+
62
62
  start_signal = socket.gets
63
63
  next unless start_signal
64
64
  start_signal.chomp!
65
-
65
+
66
66
  if start_signal
67
67
  ahn_log.sandbox "Incoming call from remote sandbox server!"
68
68
  begin
@@ -37,7 +37,7 @@ Install the pure-Ruby Stomp server by doing "gem install stompserver". This will
37
37
 
38
38
  Open the `stomp_gateway.yml` file in the stomp_gateway component folder. Comment out the four settings at the top of the file named "user", "pass", "host" and "port" by prepending a "#" to their line. This will cause the component to choose defaults for those properties. The component's defaults will match the expected credentials for the experimental stompserver you're already running on your computer.
39
39
 
40
- You also need specify a subscription name in
40
+ You also need specify a subscription name in
41
41
 
42
42
  events.stomp.start_call.each do |event|
43
43
  # The "event" variable holds a Stomp::Message object.
@@ -7,22 +7,22 @@ initialization do
7
7
  pass = COMPONENTS.stomp_gateway[:pass] || ""
8
8
  host = COMPONENTS.stomp_gateway[:host] || "localhost"
9
9
  port = COMPONENTS.stomp_gateway[:port] || 61613
10
-
10
+
11
11
  ::StompGatewayConnection = Stomp::Client.open(user, pass, host, port)
12
-
12
+
13
13
  subscriptions = COMPONENTS.stomp_gateway["subscriptions"]
14
-
14
+
15
15
  ahn_log.stomp_gateway "Connection established. Subscriptions: #{subscriptions.inspect}"
16
-
16
+
17
17
  Events.register_namespace_name "/stomp"
18
-
18
+
19
19
  subscriptions.each do |subscription|
20
20
  Events.register_namespace_name "/stomp/#{subscription}"
21
21
  ::StompGatewayConnection.subscribe subscription do |event|
22
22
  Adhearsion::Events.trigger ["stomp", subscription], event
23
23
  end
24
24
  end
25
-
25
+
26
26
  end
27
27
 
28
28
  methods_for :global do
@@ -10,7 +10,7 @@ class SimonGame
10
10
  @call = call
11
11
  reset
12
12
  end
13
-
13
+
14
14
  def start
15
15
  loop do
16
16
  say_number
@@ -37,7 +37,7 @@ class SimonGame
37
37
  end
38
38
 
39
39
  def verify_attempt
40
- if attempt_correct?
40
+ if attempt_correct?
41
41
  @call.play 'good'
42
42
  else
43
43
  @call.play %W[#{@number.length-1} times wrong-try-again-smarty]
@@ -48,9 +48,9 @@ class SimonGame
48
48
  def attempt_correct?
49
49
  @attempt == @number
50
50
  end
51
-
51
+
52
52
  def reset
53
53
  @attempt, @number = '', ''
54
54
  end
55
-
55
+
56
56
  end
@@ -3,7 +3,7 @@ unless defined? Adhearsion
3
3
  # If you wish to freeze a copy of Adhearsion to this app, simply place a copy of Adhearsion
4
4
  # into a folder named "adhearsion" within this app's main directory.
5
5
  require File.dirname(__FILE__) + "/../adhearsion/lib/adhearsion.rb"
6
- else
6
+ else
7
7
  require 'rubygems'
8
8
  gem 'adhearsion', '>= 0.8.2'
9
9
  require 'adhearsion'
@@ -11,40 +11,55 @@ unless defined? Adhearsion
11
11
  end
12
12
 
13
13
  Adhearsion::Configuration.configure do |config|
14
-
14
+
15
15
  # Supported levels (in increasing severity) -- :debug < :info < :warn < :error < :fatal
16
16
  config.logging :level => :info
17
-
17
+
18
18
  # Whether incoming calls be automatically answered. Defaults to true.
19
19
  # config.automatically_answer_incoming_calls = false
20
-
20
+
21
21
  # Whether the other end hanging up should end the call immediately. Defaults to true.
22
22
  # config.end_call_on_hangup = false
23
-
23
+
24
24
  # Whether to end the call immediately if an unrescued exception is caught. Defaults to true.
25
25
  # config.end_call_on_error = false
26
-
27
- # By default Asterisk is enabled with the default settings
28
- config.enable_asterisk
26
+
27
+ # NOTE: Pay special attention to the argument_delimiter field below:
28
+ # For Asterisk <= 1.4, use "|" (default)
29
+ # For Asterisk >= 1.6, use ","
30
+ # This setting applies to AMI and AGI
31
+ config.enable_asterisk :argument_delimiter => '|'
29
32
  # config.asterisk.enable_ami :host => "127.0.0.1", :username => "admin", :password => "password", :events => true
30
-
33
+
31
34
  # config.enable_drb
32
-
33
- # Streamlined Rails integration! The first argument should be a relative or absolute path to
34
- # the Rails app folder with which you're integrating. The second argument must be one of the
35
+
36
+ # Streamlined Rails integration! The first argument should be a relative or absolute path to
37
+ # the Rails app folder with which you're integrating. The second argument must be one of the
35
38
  # the following: :development, :production, or :test.
36
-
39
+
37
40
  # config.enable_rails :path => 'gui', :env => :development
38
-
41
+
39
42
  # Note: You CANNOT do enable_rails and enable_database at the same time. When you enable Rails,
40
43
  # it will automatically connect to same database Rails does and load the Rails app's models.
41
-
44
+
42
45
  # Configure a database to use ActiveRecord-backed models. See ActiveRecord::Base.establish_connection
43
46
  # for the appropriate settings here.
44
47
  # config.enable_database :adapter => 'mysql',
45
- # :username => 'joe',
48
+ # :username => 'joe',
46
49
  # :password => 'secret',
47
50
  # :host => 'db.example.org'
51
+
52
+ # Configure an LDAP connection using ActiveLdap. See ActiveLdap::Base.establish_connect
53
+ # for the appropriate settings here.
54
+ # config.enable_ldap :host => 'ldap.dataspill.org',
55
+ # :port => 389,
56
+ # :base => 'dc=dataspill,dc=org',
57
+ # :logger => ahn_log.ldap,
58
+ # :bind_dn => "uid=drewry,ou=People,dc=dataspill,dc=org",
59
+ # :password => 'password12345',
60
+ # :allow_anonymous => false,
61
+ # :try_sasl => false
62
+
48
63
  end
49
64
 
50
65
  Adhearsion::Initializer.start_from_init_file(__FILE__, File.dirname(__FILE__) + "/..")
data/bin/ahn CHANGED
@@ -4,17 +4,17 @@
4
4
 
5
5
  # Adhearsion, open source collaboration framework
6
6
  # Copyright (C) 2006,2007,2008 Jay Phillips
7
- #
7
+ #
8
8
  # This library is free software; you can redistribute it and/or modify it under
9
9
  # the terms of the GNU Lesser General Public License as published by the Free
10
10
  # Software Foundation; either version 2.1 of the License, or (at your option)
11
11
  # any later version.
12
- #
12
+ #
13
13
  # This library is distributed in the hope that it will be useful, but WITHOUT
14
14
  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15
15
  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16
16
  # details.
17
- #
17
+ #
18
18
  # You should have received a copy of the GNU Lesser General Public License along
19
19
  # with this library; if not, write to the Free Software Foundation, Inc.,
20
20
  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
data/bin/ahnctl CHANGED
@@ -1,25 +1,25 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+ #
3
3
  # ahnctl - Adhearsion daemon controller
4
4
  #
5
5
  # Adhearsion, open source collaboration framework
6
6
  # Copyright (C) 2006,2007,2008 Jay Phillips
7
- #
7
+ #
8
8
  # This library is free software; you can redistribute it and/or
9
9
  # modify it under the terms of the GNU Lesser General Public
10
10
  # License as published by the Free Software Foundation; either
11
11
  # version 2.1 of the License, or (at your option) any later version.
12
- #
12
+ #
13
13
  # This library is distributed in the hope that it will be useful,
14
14
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
16
  # Lesser General Public License for more details.
17
- #
17
+ #
18
18
  # You should have received a copy of the GNU Lesser General Public
19
19
  # License along with this library; if not, write to the Free Software
20
20
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
21
 
22
- USAGE = "Usage: ahnctl start|stop|restart /path/to/adhearsion/app [--pid-file=/path/to/pid_file.pid]"
22
+ USAGE = "Usage: ahnctl start|stop|restart /path/to/adhearsion/app [--pid-file=/path/to/pid_file.pid]"
23
23
 
24
24
  # Blow up if the CLI arguments are invalid
25
25
  abort USAGE unless (2..3).include?(ARGV.size) && %w[start stop restart].include?(ARGV.first)
@@ -51,14 +51,14 @@ puts "Stopping Adhearsion app at #{app_dir}" if %w[stop restart].include? ARGV.f
51
51
  if File.exists?(pid_file)
52
52
  # An Adhearsion process may still be running. Let's kill the other one as cleanly as possible
53
53
  pid = File.read(pid_file).to_i
54
-
54
+
55
55
  # Time to spend waiting for Adhearsion to exit
56
56
  waiting_timeout = Time.now + 15
57
-
57
+
58
58
  terminate pid
59
59
  sleep 0.25 until `ps -p #{pid} | sed -e '1d'`.strip.empty? || Time.now > waiting_timeout
60
60
  kill pid
61
-
61
+
62
62
  `rm -f #{pid_file}`
63
63
  end
64
64
 
data/bin/jahn CHANGED
@@ -4,17 +4,17 @@
4
4
 
5
5
  # Adhearsion, open source collaboration framework
6
6
  # Copyright (C) 2006,2007,2008 Jay Phillips
7
- #
7
+ #
8
8
  # This library is free software; you can redistribute it and/or modify it under
9
9
  # the terms of the GNU Lesser General Public License as published by the Free
10
10
  # Software Foundation; either version 2.1 of the License, or (at your option)
11
11
  # any later version.
12
- #
12
+ #
13
13
  # This library is distributed in the hope that it will be useful, but WITHOUT
14
14
  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15
15
  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16
16
  # details.
17
- #
17
+ #
18
18
  # You should have received a copy of the GNU Lesser General Public License along
19
19
  # with this library; if not, write to the Free Software Foundation, Inc.,
20
20
  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -40,10 +40,10 @@ if sip_peers.any?
40
40
  sip_peers.each do |peer|
41
41
  # Uncomment the following line to view all the headers for each peer.
42
42
  # p peer.headers
43
-
43
+
44
44
  peer_name = peer.headers["ObjectName"]
45
45
  peer_status = peer.headers["Status"]
46
-
46
+
47
47
  puts "#{peer_name}: #{peer_status}"
48
48
  end
49
49
  else
@@ -24,14 +24,16 @@ require 'adhearsion/voip/asterisk/commands'
24
24
  require 'adhearsion/voip/dsl/dialing_dsl'
25
25
  require 'adhearsion/voip/call_routing'
26
26
 
27
+ require 'active_support/core_ext'
28
+
27
29
  module Adhearsion
28
30
  # Sets up the Gem require path.
29
31
  AHN_INSTALL_DIR = File.expand_path(File.dirname(__FILE__) + "/..")
30
32
  AHN_CONFIG = Configuration.new
31
-
33
+
32
34
  ##
33
35
  # This Array holds all the Threads whose life matters. Adhearsion will not exit until all of these have died.
34
36
  #
35
37
  IMPORTANT_THREADS = []
36
-
38
+
37
39
  end
@@ -9,25 +9,25 @@ Usage:
9
9
  ahn start [daemon] [/path/to/directory]
10
10
  ahn version|-v|--v|-version|--version
11
11
  ahn help|-h|--h|--help|-help
12
-
12
+
13
13
  ahn enable component COMPONENT_NAME
14
14
  ahn disable component COMPONENT_NAME
15
15
  ahn create component COMPONENT_NAME
16
16
  USAGE
17
-
17
+
18
18
  def self.execute!
19
19
  CommandHandler.send(*parse_arguments)
20
20
  rescue CommandHandler::CLIException => error
21
21
  fail_and_print_usage error
22
22
  end
23
-
23
+
24
24
  ##
25
25
  # Provides a small abstraction of Kernel::abort().
26
26
  #
27
27
  def self.fail_and_print_usage(error)
28
28
  Kernel.abort "#{error.message}\n\n#{USAGE}"
29
29
  end
30
-
30
+
31
31
  def self.parse_arguments(args=ARGV.clone)
32
32
  action = args.shift
33
33
  case action
@@ -45,7 +45,7 @@ USAGE
45
45
  else
46
46
  pid_file = nil
47
47
  end
48
-
48
+
49
49
  if args.first == 'daemon' && args.size == 2
50
50
  path = args.last
51
51
  daemon = true
@@ -69,10 +69,10 @@ USAGE
69
69
  [action, *args]
70
70
  end
71
71
  end
72
-
72
+
73
73
  module CommandHandler
74
74
  class << self
75
-
75
+
76
76
  def create(*args)
77
77
  if args.size.zero?
78
78
  raise CommandHandler::UnknownCommand.new("Must specify something to create!")
@@ -81,7 +81,7 @@ USAGE
81
81
  path = args.first
82
82
  require 'rubigen'
83
83
  require 'rubigen/scripts/generate'
84
- source = RubiGen::PathSource.new(:application,
84
+ source = RubiGen::PathSource.new(:application,
85
85
  File.join(File.dirname(__FILE__), "../../app_generators"))
86
86
  RubiGen::Base.reset_sources
87
87
  RubiGen::Base.append_sources source
@@ -89,24 +89,24 @@ USAGE
89
89
  elsif args.size == 2
90
90
  # We're creating a feature (e.g. a component)
91
91
  feature_type, component_name = args
92
-
92
+
93
93
  if feature_type != "component"
94
94
  # At the moment, only components can be created.
95
- raise CommandHandler::UnknownCommand.new("Don't know how to create '#{feature_type}'")
95
+ raise CommandHandler::UnknownCommand.new("Don't know how to create '#{feature_type}'")
96
96
  end
97
-
97
+
98
98
  if component_name !~ /^[a-z][\w_]+$/
99
99
  raise CommandHandler::ComponentError.new("Component name must be lowercase alphanumeric characters " +
100
100
  "and begin with a character")
101
101
  end
102
-
102
+
103
103
  app_path = PathString.from_application_subdirectory Dir.pwd
104
-
104
+
105
105
  raise PathInvalid.new(Dir.pwd) if app_path.nil?
106
-
106
+
107
107
  new_component_dir = app_path + "/components/#{component_name}"
108
108
  raise ComponentError.new("Component #{component_name} already exists!") if File.exists?(new_component_dir)
109
-
109
+
110
110
  # Everything's good. Let's create the component
111
111
  Dir.mkdir new_component_dir
112
112
  File.open(new_component_dir + "/#{component_name}.rb","w") do |file|
@@ -123,20 +123,20 @@ USAGE
123
123
  raise CommandHandler::UnknownCommand.new("Provided too many arguments to 'create'")
124
124
  end
125
125
  end
126
-
126
+
127
127
  def start(path, daemon=false, pid_file=nil)
128
128
  raise PathInvalid, path unless File.exists? path + "/.ahnrc"
129
129
  Adhearsion::Initializer.start path, :daemon => daemon, :pid_file => pid_file
130
130
  end
131
-
131
+
132
132
  def version
133
133
  puts "Adhearsion v#{Adhearsion::VERSION::STRING}"
134
134
  end
135
-
135
+
136
136
  def help
137
137
  puts USAGE
138
138
  end
139
-
139
+
140
140
  def enable(type, name)
141
141
  case type
142
142
  when "component"
@@ -157,19 +157,19 @@ USAGE
157
157
  raise UnknownCommand.new("enable #{type}")
158
158
  end
159
159
  end
160
-
160
+
161
161
  def disable(type, name)
162
162
  case type
163
163
  when "component"
164
164
  app_path = PathString.from_application_subdirectory Dir.pwd
165
165
  if app_path
166
166
  disabled_dir = File.join app_path, "components", "disabled"
167
-
167
+
168
168
  disabled_component_path = File.join disabled_dir, name
169
169
  enabled_component_path = File.join app_path, "components", name
170
-
170
+
171
171
  Dir.mkdir disabled_dir unless File.directory?(disabled_dir)
172
-
172
+
173
173
  if File.directory? enabled_component_path
174
174
  if File.directory?(disabled_component_path)
175
175
  raise ComponentError.new("There is already a disabled component at #{disabled_component_path}")
@@ -187,31 +187,31 @@ USAGE
187
187
  raise UnknownCommand.new("disable #{type}")
188
188
  end
189
189
  end
190
-
190
+
191
191
  def method_missing(action, *args)
192
192
  raise UnknownCommand, [action, *args] * " "
193
193
  end
194
-
194
+
195
195
  private
196
-
196
+
197
197
  end
198
-
198
+
199
199
  class CLIException < Exception; end
200
-
200
+
201
201
  class UnknownCommand < CLIException
202
202
  def initialize(cmd)
203
203
  super "Unknown command: #{cmd}"
204
204
  end
205
205
  end
206
-
206
+
207
207
  class ComponentError < CLIException; end
208
-
208
+
209
209
  class UnknownProject < CLIException
210
210
  def initialize(project)
211
211
  super "Application #{project} does not exist! Have you installed it?"
212
212
  end
213
213
  end
214
-
214
+
215
215
  class PathInvalid < CLIException
216
216
  def initialize(path)
217
217
  super "Directory #{path} does not belong to an Adhearsion project!"