Skip to content

Commit

Permalink
[CS] Split events and routes out of config file
Browse files Browse the repository at this point in the history
Separates responsibilities and clutter. Backward compatibility is ensured. See #429
  • Loading branch information
benlangfeld committed Jan 22, 2014
1 parent 3d0afb2 commit 2054808
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 36 deletions.
13 changes: 12 additions & 1 deletion features/app_generator.feature
Expand Up @@ -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 |
Expand All @@ -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
Expand Down Expand Up @@ -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 |
Expand Down
2 changes: 2 additions & 0 deletions lib/adhearsion/generators/app/app_generator.rb
Expand Up @@ -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"
Expand Down
35 changes: 0 additions & 35 deletions lib/adhearsion/generators/app/templates/adhearsion.erb
Expand Up @@ -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
18 changes: 18 additions & 0 deletions 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
19 changes: 19 additions & 0 deletions 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
12 changes: 12 additions & 0 deletions lib/adhearsion/initializer.rb
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2054808

Please sign in to comment.