Permalink
Browse files

restructured lib/ to allow better organization of separate apps; adde…

…d logging examples
  • Loading branch information...
gnarmis committed Mar 11, 2012
1 parent 7c79757 commit 3caabab578a4fc7d397cc257e9ada7873729edef
Showing with 28 additions and 20 deletions.
  1. +2 −0 Gemfile
  2. +2 −2 config.ru
  3. +1 −1 config/boot.rb
  4. +7 −6 lib/{ → bar}/bar.rb
  5. +8 −7 lib/{ → foo}/foo.rb
  6. +4 −0 lib/project.rb
  7. +2 −2 spec/bar_spec.rb
  8. +2 −2 spec/foo_spec.rb
View
@@ -1,9 +1,11 @@
source :rubygems
+gem 'rack'
gem 'sinatra'
group :development do
gem 'pry'
+ gem 'logger'
end
group :test do
View
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/config/boot.rb'
run Rack::URLMap.new({
- "/" => Foobar::Foo,
- "/bar" => Foobar::Bar
+ "/" => Project::Foo,
+ "/bar" => Project::Bar
})
View
@@ -5,5 +5,5 @@
Bundler.require(:default, ENV["RACK_ENV"].to_sym)
-Dir["./lib/**/*.rb"].each { |f| require f }
+Dir[File.dirname(__FILE__) + '/../lib/**/*.rb'].each { |f| require f }
@@ -1,12 +1,13 @@
-module Foobar
+module Project
class Bar < Sinatra::Base
-
- #configure do
- # set app specific settings
- # for example different view folders
- #end
+ # set configuration for this app
+ configure :production, :development do
+ enable :logging
+ logger = Logger.new(STDOUT)
+ end
get '/' do
+ logger.info "loading index page in bar"
"Hello from bar"
end
@@ -1,12 +1,13 @@
-module Foobar
+module Project
class Foo < Sinatra::Base
-
- #configure do
- # set app specific settings
- # for example different view folders
- #end
-
+ # set configuration for this app
+ configure :production, :development do
+ enable :logging
+ logger = Logger.new(STDOUT)
+ end
+
get '/' do
+ logger.info "loading index page in foo"
"Hello from foo"
end
View
@@ -0,0 +1,4 @@
+module Project
+ # each class defined in this module is a
+ # completely separate Sinatra app
+end
View
@@ -1,9 +1,9 @@
require 'spec_helper'
-describe Foobar::Bar do
+describe Project::Bar do
def app
- @app ||= Foobar::Bar
+ @app ||= Project::Bar
end
describe "GET '/'" do
View
@@ -1,9 +1,9 @@
require 'spec_helper'
-describe Foobar::Foo do
+describe Project::Foo do
def app
- @app ||= Foobar::Foo
+ @app ||= Project::Foo
end
describe "GET '/'" do

0 comments on commit 3caabab

Please sign in to comment.