diff --git a/features/app_generator.feature b/features/app_generator.feature index 04f87fc17..4b5f05d62 100644 --- a/features/app_generator.feature +++ b/features/app_generator.feature @@ -21,6 +21,8 @@ Feature: Adhearsion App Generator | app/call_controllers/simon_game.rb | | config/adhearsion.rb | | config/environment.rb | + | config/events.rb | + | config/routes.rb | | Gemfile | | script/ahn | | spec/spec_helper.rb | @@ -31,11 +33,18 @@ Feature: Adhearsion App Generator And the file "config/adhearsion.rb" should contain each of these content parts: """ - Adhearsion.router Adhearsion.config logging.level config.punchblock """ + And the file "config/events.rb" should contain each of these content parts: + """ + Adhearsion::Events.draw do + """ + And the file "config/routes.rb" should contain each of these content parts: + """ + Adhearsion.router + """ And the file "README.md" should contain each of these content parts: """ Start your new app with @@ -67,6 +76,8 @@ Feature: Adhearsion App Generator | .rspec | | config/adhearsion.rb | | config/environment.rb | + | config/events.rb | + | config/routes.rb | | Gemfile | | script/ahn | | spec/spec_helper.rb | diff --git a/lib/adhearsion/generators/app/app_generator.rb b/lib/adhearsion/generators/app/app_generator.rb index ef8922005..ad6147476 100644 --- a/lib/adhearsion/generators/app/app_generator.rb +++ b/lib/adhearsion/generators/app/app_generator.rb @@ -16,6 +16,8 @@ def setup_project template "Gemfile.erb", "Gemfile" template "adhearsion.erb", "config/adhearsion.rb" + template "events.erb", "config/events.rb" + template "routes.erb", "config/routes.rb" copy_file "gitignore", ".gitignore" copy_file "rspec", ".rspec" copy_file "Procfile" diff --git a/lib/adhearsion/generators/app/templates/adhearsion.erb b/lib/adhearsion/generators/app/templates/adhearsion.erb index 64ec8c0b6..1521e1087 100644 --- a/lib/adhearsion/generators/app/templates/adhearsion.erb +++ b/lib/adhearsion/generators/app/templates/adhearsion.erb @@ -46,38 +46,3 @@ Adhearsion.config do |config| # config.punchblock.host = "freeswitch.local-dev.mojolingo.com" # Your IES host <% end %> end - -Adhearsion::Events.draw do -<% unless options[:empty] %> - # Register global handlers for events - # - # eg. Handling Punchblock events - # punchblock do |event| - # ... - # end - # - # eg Handling PeerStatus AMI events - # ami :name => 'PeerStatus' do |event| - # ... - # end - # -<% end %> -end - -<% unless options[:empty] %> -require 'call_controllers/simon_game' -<% end %> - -Adhearsion.router do -<% if options[:empty] %> - route 'default' do - - end -<% else %> - # - # Specify your call routes, directing calls with particular attributes to a controller - # - - route 'default', SimonGame -<% end %> -end diff --git a/lib/adhearsion/generators/app/templates/events.erb b/lib/adhearsion/generators/app/templates/events.erb new file mode 100644 index 000000000..b9ce10366 --- /dev/null +++ b/lib/adhearsion/generators/app/templates/events.erb @@ -0,0 +1,18 @@ +# encoding: utf-8 + +Adhearsion::Events.draw do +<% unless options[:empty] %> + # Register global handlers for events + # + # eg. Handling Punchblock events + # punchblock do |event| + # ... + # end + # + # eg Handling PeerStatus AMI events + # ami :name => 'PeerStatus' do |event| + # ... + # end + # +<% end %> +end diff --git a/lib/adhearsion/generators/app/templates/routes.erb b/lib/adhearsion/generators/app/templates/routes.erb new file mode 100644 index 000000000..ff43c445c --- /dev/null +++ b/lib/adhearsion/generators/app/templates/routes.erb @@ -0,0 +1,19 @@ +# encoding: utf-8 + +<% unless options[:empty] %> +require 'call_controllers/simon_game' +<% end %> + +Adhearsion.router do +<% if options[:empty] %> + route 'default' do + + end +<% else %> + # + # Specify your call routes, directing calls with particular attributes to a controller + # + + route 'default', SimonGame +<% end %> +end diff --git a/lib/adhearsion/initializer.rb b/lib/adhearsion/initializer.rb index e6526dd36..097bdb60f 100644 --- a/lib/adhearsion/initializer.rb +++ b/lib/adhearsion/initializer.rb @@ -42,6 +42,8 @@ def start resolve_pid_file_path load_lib_folder load_config_file + load_events_file + load_routes_file initialize_log_paths if should_daemonize? @@ -195,6 +197,16 @@ def load_config_file require "#{Adhearsion.config.root}/config/adhearsion.rb" end + def load_events_file + path = "#{Adhearsion.config.root}/config/events.rb" + require path if File.exists?(path) + end + + def load_routes_file + path = "#{Adhearsion.config.root}/config/routes.rb" + require path if File.exists?(path) + end + def init_get_logging_appenders @file_loggers ||= memoize_logging_appenders end