Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added example that uses rack-cache

  • Loading branch information...
commit 2a704955677cc6fbc4c4d9135e8b6016dc0faaa6 1 parent 1d1484f
@nakajima authored
View
30 example/app-with-cache.rb
@@ -0,0 +1,30 @@
+require File.dirname(__FILE__) + '/lib/common.rb'
+require 'rack/cache'
+
+class MountedApp < Sinatra::Base
+ set :app_file, __FILE__
+ set :logging, true
+
+ use Rack::Cache do
+ set :verbose, true
+ set :metastore, 'heap:/'
+ set :entitystore, 'heap:/'
+ end
+
+ get '/' do
+ redirect '/posts'
+ end
+
+ mount(Post) do
+ finder { |model, params| model.all }
+ record { |model, params| model.first(:id => params[:id]) }
+
+ # Mount children as a nested resource
+ mount(Comment) do
+ finder { |model, params| model.all }
+ record { |model, params| model.first(:id => params[:id]) }
+ end
+ end
+end
+
+MountedApp.run!
View
3  example/lib/post.rb
@@ -1,5 +1,6 @@
require 'dm-core'
require 'dm-serializer'
+require 'dm-timestamps'
class Post
include DataMapper::Resource
@@ -8,6 +9,8 @@ class Post
property :id, Serial, :key => true
property :name, String
property :body, Text
+ property :created_at, DateTime
+ property :updated_at, DateTime
has n, :comments
end
View
4 lib/sinatras-hat/extendor.rb
@@ -6,7 +6,9 @@ module Hat
# instance's parent.
module Extendor
def mount(klass, options={}, &block)
- use Rack::MethodOverride unless kind_of?(Sinatra::Hat::Maker)
+ unless kind_of?(Sinatra::Hat::Maker)
+ use Rack::MethodOverride
+ end
Maker.new(klass, options).tap do |maker|
maker.parent = self if kind_of?(Sinatra::Hat::Maker)

0 comments on commit 2a70495

Please sign in to comment.
Something went wrong with that request. Please try again.