Skip to content

Commit

Permalink
Introduce the concept of application specific config
Browse files Browse the repository at this point in the history
Similar to a plugin, an Application can specify config and an initialiser, and is the place to put such application-wide and unshareable things.
  • Loading branch information
benlangfeld committed Jun 24, 2015
1 parent 4a76353 commit 5a0a969
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
# [develop](https://github.com/adhearsion/adhearsion)
* Change: Define configuration per-environment for any environment name and without colliding with plugin names. See [#442](https://github.com/adhearsion/adhearsion/issues/442). Syntax is now `config.env(:development).foo = :bar` instead of `config.development.foo = :bar`.
* Feature: Introduce the concept of application specific config. Similar to a plugin, an Application can specify config and an initialiser, and is the place to put such application-wide and unshareable things.

# [3.0.0.beta1](https://github.com/adhearsion/adhearsion/compare/v2.6.1...v3.0.0.beta1) - [2015-06-24](https://rubygems.org/gems/adhearsion/versions/3.0.0.beta1)
* Change: Removed `Adhearsion.ahn_root=` which was deprecated in favour of `Adhearsion.root=`
Expand Down
6 changes: 6 additions & 0 deletions features/cli_create.feature
Expand Up @@ -24,6 +24,7 @@ Feature: Adhearsion Ahn CLI (Create)
| app/assets/audio/en/hello_world.wav |
| app/call_controllers/simon_game.rb |
| config/adhearsion.rb |
| config/app.rb |
| config/environment.rb |
| config/events.rb |
| config/routes.rb |
Expand All @@ -43,6 +44,10 @@ Feature: Adhearsion Ahn CLI (Create)
logging.level
config.core.username
"""
And the file "config/app.rb" should contain each of these content parts:
"""
config do
"""
And the file "config/events.rb" should contain each of these content parts:
"""
Adhearsion::Events.draw do
Expand Down Expand Up @@ -88,6 +93,7 @@ Feature: Adhearsion Ahn CLI (Create)
| .gitignore |
| .rspec |
| config/adhearsion.rb |
| config/app.rb |
| config/environment.rb |
| config/events.rb |
| config/routes.rb |
Expand Down
7 changes: 7 additions & 0 deletions lib/adhearsion/application.rb
@@ -0,0 +1,7 @@
# encoding: utf-8

require 'adhearsion/plugin'

class Adhearsion::Application < Adhearsion::Plugin
alias :name :plugin_name
end
17 changes: 17 additions & 0 deletions lib/adhearsion/generators/app/templates/config/app.rb
@@ -0,0 +1,17 @@
# encoding: utf-8

class DemoApp < Adhearsion::Application
name :demo

# Actions to perform when initialising the application
#
init do
logger.info "This is the Adhearsion Demo application as generated by `ahn create`. It should work well on FreeSWITCH, and will soon also work on Asterisk."
end

# Basic configuration for the application
#
config do
greeting "Hello. Welcome to the Simon Game. Lets play.", desc: "What to use to greet users before playing the Simon Game"
end
end
7 changes: 7 additions & 0 deletions lib/adhearsion/initializer.rb
@@ -1,5 +1,6 @@
# encoding: utf-8

require 'adhearsion/application'
require 'adhearsion/linux_proc_name'
require 'adhearsion/rayo/initializer'
require 'adhearsion/http_server'
Expand Down Expand Up @@ -28,6 +29,7 @@ def start
catch :boot_aborted do
configure_plugins
load_lib_folder
load_app_file
load_config_file
load_events_file
load_routes_file
Expand Down Expand Up @@ -138,6 +140,11 @@ def load_lib_folder
true
end

def load_app_file
path = "#{Adhearsion.config.root}/config/app.rb"
load path if File.exists?(path)
end

def load_config_file
load "#{Adhearsion.config.root}/config/adhearsion.rb"
end
Expand Down

0 comments on commit 5a0a969

Please sign in to comment.