Class: Metry::Psycho
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Metry::Psycho
- Defined in:
- lib/metry/psycho.rb
Defined Under Namespace
Instance Method Summary collapse
-
#initialize(app, options = {}) ⇒ Psycho
constructor
A new instance of Psycho.
Constructor Details
#initialize(app, options = {}) ⇒ Psycho
Returns a new instance of Psycho.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/metry/psycho.rb', line 5 def initialize(app, ={}) super(app) = path = [:path] || "/psycho" auth = [:authorize] || proc{true} on_deny = [:on_deny] || proc{[403, {"Content-Type" => "text/plain"}, "You must log in."]} self.class.class_eval do set :views, File.dirname(__FILE__) + '/psycho' before do if unescape(@request.path_info) =~ /^#{path}/ @env["metry.event"]["ignore"] = "true" if !auth.call(env) reply = on_deny.call(env) status reply.first response.header.merge!(reply[1]) halt reply.last end end end get "#{path}/?" do @visitors = Visitor.all @goals = Goal.all erb :dashboard end get "#{path}/visitors/:id" do @visitor = Visitor.find(params["id"]) erb :visitor end post "#{path}/goals" do goal = Goal.create!(params[:name], params[:path]) redirect url("/goals/#{goal.id}") end get "#{path}/goals/new" do erb :new_goal end get "#{path}/goals/:id" do @goal = Goal.find(params[:id]) erb :goal end get "#{path}/goals/:id/edit" do @goal = Goal.find(params[:id]) erb :edit_goal end post "#{path}/goals/:id" do goal = Goal.find(params[:id]) goal.name = params[:name] goal.path = params[:path] goal.save redirect url("/goals/#{goal.id}") end helpers do define_method(:url) do |url| "#{path}#{url}" end include ::Rack::Utils alias_method :h, :escape_html end end end |