Skip to content

Commit

Permalink
Added Halcyon.environment configurable attribute, including tests. De…
Browse files Browse the repository at this point in the history
…faults to the development environment. Also updated app init templates to include configuration and initialization, along with documentation. [#35 state:resolved]
  • Loading branch information
mtodd committed May 12, 2008
1 parent 43b73ce commit 08cf865
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/halcyon/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ def initialize
Halcyon.logger = Halcyon::Logger.setup(Halcyon.config[:logging])

# Run initializers
Dir.glob(Halcyon.paths[:init]/'{requires.rb,hooks.rb,routes.rb,*}').each do |initializer|
Dir.glob(Halcyon.paths[:init]/'{requires,hooks,routes,environment,*}.rb').each do |initializer|
self.logger.debug "Init: #{File.basename(initializer).chomp('.rb').camel_case}" if
require initializer.chomp('.rb')
end

# Setup autoloads for Controllers found in Halcyon.root/'app'
Dir.glob(Halcyon.paths[:controller]/'{application.rb,*}').each do |controller|
Dir.glob(Halcyon.paths[:controller]/'{application,*}.rb').each do |controller|
self.logger.debug "Load: #{File.basename(controller).chomp('.rb').camel_case} Controller" if
require controller.chomp('.rb')
end
Expand Down
5 changes: 5 additions & 0 deletions spec/halcyon/halcyon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
Halcyon.config.is_a?(Hash).should.be.true?
end

it "should provide environment label" do
Halcyon.environment.should == :development
Halcyon.environment.should == Halcyon.config[:environment]
end

it "should provide universal access to a logger" do
# We assume Logger here because, you know, we're gods of the test
Halcyon.logger.is_a?(Logger).should.be.true?
Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

$config = {
:allow_from => :all,
:environment => :development,
:logger => nil,
:logging => {
:level => 'debug'
Expand Down Expand Up @@ -64,6 +65,10 @@ class Model
attr_accessor :id
end

# Environment

Halcyon.configurable_attr(:environment)

# Testing routes

Halcyon::Application.route do |r|
Expand Down
7 changes: 7 additions & 0 deletions support/generators/halcyon/templates/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
# * <tt>halcyon_clients</tt>: only Halcyon clients (tests the User-Agent only)
allow_from: all

# = Environment
#
# Uncomment to manually specify the environment to run the application in.
# Defaults to <tt>:development</tt>.
#
# environment: production

# = Logging
#
# Configures the logging client in the framework, including destination,
Expand Down
11 changes: 11 additions & 0 deletions support/generators/halcyon/templates/config/init/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# = Environment
#
# Sets the environment unless already set.
#
# Creates the <tt>Halcyon.environment</tt> configurable attribute. Since this
# is mapped to <tt>Halcyon.config[:environment]</tt>, environment can be set
# by setting the <tt>environment:</tt> configuration value in the
# <tt>config/config.yml</tt> file.

Halcyon.configurable_attr(:environment)
Halcyon.environment = :development unless Halcyon.environment
6 changes: 6 additions & 0 deletions support/generators/halcyon_flat/templates/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
}
}.to_mash

# = Environment
# Set the environment if not set above; create the <tt>Halcyon.environment</tt>
# configurable attribute. Maps to <tt>Halcyon.config[:environment]</tt>.
Halcyon.configurable_attr(:environment)
Halcyon.environment = :development unless Halcyon.environment

# = Routes
Halcyon::Application.route do |r|
r.match('/time').to(:controller => 'application', :action => 'time')
Expand Down

0 comments on commit 08cf865

Please sign in to comment.