Skip to content

Instantly share code, notes, and snippets.

@pedromg
Forked from igrigorik/webapp.rb
Created November 17, 2010 12:53
Show Gist options
  • Select an option

  • Save pedromg/703359 to your computer and use it in GitHub Desktop.

Select an option

Save pedromg/703359 to your computer and use it in GitHub Desktop.

Revisions

  1. @igrigorik igrigorik revised this gist Nov 16, 2010. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion webapp.rb
    Original file line number Diff line number Diff line change
    @@ -32,4 +32,7 @@ class << self
    # Implementations in other languages (thanks guys!):
    # Node.js: https://gist.github.com/700995
    # Groovy: https://gist.github.com/702337
    # Python: https://gist.github.com/702001
    # Python: https://gist.github.com/702001

    # Great explanation of how this works in Ruby on Stackoverflow:
    # http://stackoverflow.com/questions/4198883/exposing-any-ruby-object-over-the-web
  2. @igrigorik igrigorik revised this gist Nov 16, 2010. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions webapp.rb
    Original file line number Diff line number Diff line change
    @@ -28,3 +28,8 @@ class << self

    # http://localhost:9292/pop -> 3
    # http://localhost:9292/shift -> 1

    # Implementations in other languages (thanks guys!):
    # Node.js: https://gist.github.com/700995
    # Groovy: https://gist.github.com/702337
    # Python: https://gist.github.com/702001
  3. @igrigorik igrigorik revised this gist Nov 16, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion webapp.rb
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ class Object
    def webapp
    class << self
    define_method :call do |env|
    func, *attrs = env['REQUEST_PATH'].split('/').reject(&:empty?)
    func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
    [200, {}, send(func, *attrs)]
    end
    end
  4. @igrigorik igrigorik revised this gist Nov 15, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion webapp.rb
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ class << self

    # http://localhost:9292/push/1 -> 1
    # http://localhost:9292/push/2 -> 12
    # http://localhost:9292/push/2 -> 123
    # http://localhost:9292/push/3 -> 123

    # http://localhost:9292/to_a -> 123

  5. @igrigorik igrigorik created this gist Nov 13, 2010.
    30 changes: 30 additions & 0 deletions webapp.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    require 'rubygems'
    require 'rack'

    class Object
    def webapp
    class << self
    define_method :call do |env|
    func, *attrs = env['REQUEST_PATH'].split('/').reject(&:empty?)
    [200, {}, send(func, *attrs)]
    end
    end
    self
    end
    end

    Rack::Handler::Mongrel.run [].webapp, :Port => 9292
    # ^^^^^^^^^^^
    # | (x)
    # ROFLSCALE DB ---/
    #


    # http://localhost:9292/push/1 -> 1
    # http://localhost:9292/push/2 -> 12
    # http://localhost:9292/push/2 -> 123

    # http://localhost:9292/to_a -> 123

    # http://localhost:9292/pop -> 3
    # http://localhost:9292/shift -> 1