Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…d logging examples
  • Loading branch information...
commit 3caabab578a4fc7d397cc257e9ada7873729edef 1 parent 7c79757
@gnarmis authored
View
2  Gemfile
@@ -1,9 +1,11 @@
source :rubygems
+gem 'rack'
gem 'sinatra'
group :development do
gem 'pry'
+ gem 'logger'
end
group :test do
View
4 config.ru
@@ -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
2  config/boot.rb
@@ -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 }
View
13 lib/bar.rb → lib/bar/bar.rb
@@ -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
View
15 lib/foo.rb → lib/foo/foo.rb
@@ -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
4 lib/project.rb
@@ -0,0 +1,4 @@
+module Project
+ # each class defined in this module is a
+ # completely separate Sinatra app
+end
View
4 spec/bar_spec.rb
@@ -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
4 spec/foo_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.