raggi (owner)

Forks

Revisions

gist: 81199 Download_button fork
public
Description:
sinatra as rails metal example - mostly unnecessary
Public Clone URL: git://gist.github.com/81199.git
app/metal/sinatra_metal.rb
1
2
3
4
5
6
7
8
9
require 'sinatra/metal'
 
class SinatraMetal < Sinatra::Base
  include Sinatra::Metal
 
  get '/sinatra' do
    'hello sinatra!'
  end
end
lib/sinatra/metal.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'sinatra'
 
module Sinatra::Metal
  module ClassMethods
    def metal(base = nil)
      base = '' unless base || @metal
      @metal = /^#{Regexp.escape base}/ if base
      @metal
    end
  end
 
  def self.included(base)
    base.extend ClassMethods
    base.disable :raise_errors
    base.app_file caller.first.split(':').first
    base.before { not_found unless request.path_info =~ self.class.metal }
    base.metal
  end
end