Browse Source

update to latest kemalyst (#2885)

Dru Jensen 8 years ago
parent
commit
ffdba340e1

+ 0 - 2
frameworks/Crystal/kemalyst/.gitignore

@@ -4,5 +4,3 @@
 /.crystal/
 /.shards/
 .env
-
-

+ 1 - 1
frameworks/Crystal/kemalyst/benchmark_config.json

@@ -21,7 +21,7 @@
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
-      "display_name": "Kemalyst (MVC, Slang, PostgreSQL)",
+      "display_name": "Kemalyst (MVC, Postgres)",
       "notes": "",
       "versus": "kemal"
     }

+ 4 - 4
frameworks/Crystal/kemalyst/config/application.cr

@@ -1,4 +1,4 @@
-require "../src/controllers/test_controller"
+require "../src/middleware/custom_headers"
 
 Kemalyst::Application.config do |config|
   # Set the binding host ip address.  Defaults to "0.0.0.0"
@@ -12,8 +12,8 @@ Kemalyst::Application.config do |config|
 
   # Disable unused middleware
   config.handlers = [] of HTTP::Handler
-  config.handlers << Crack::Handler::Error.instance
-  config.handlers << Crack::Handler::Params.instance
-  config.handlers << TestController.instance
+  config.handlers << Kemalyst::Handler::Error.instance
+  config.handlers << Kemalyst::Handler::Params.instance
+  config.handlers << Middleware::CustomHeaders.instance
   config.handlers << Kemalyst::Handler::Router.instance
 end

+ 1 - 1
frameworks/Crystal/kemalyst/setup.sh

@@ -6,7 +6,7 @@ shards install
 
 crystal build --release src/kemalyst.cr
 
-for i in $(seq 1 $(nproc --all)); do
+for i in $(seq 1 $((2 * $(nproc --all)))); do
   ./kemalyst &
 done
 

+ 66 - 0
frameworks/Crystal/kemalyst/shard.lock

@@ -0,0 +1,66 @@
+version: 1.0
+shards:
+  db:
+    github: crystal-lang/crystal-db
+    version: 0.4.2
+
+  expect:
+    github: dukex/expect.cr
+    commit: 17c31a0f42815cd914a630852bb2ee0da6a39dc0
+
+  granite_orm:
+    github: kemalyst/granite-orm
+    version: 0.6.2
+
+  kemalyst:
+    github: kemalyst/kemalyst
+    version: 0.9.0
+
+  kemalyst-spec:
+    github: kemalyst/kemalyst-spec
+    version: 0.1.1
+
+  kemalyst-validators:
+    github: kemalyst/kemalyst-validators
+    version: 0.2.0
+
+  kilt:
+    github: jeromegn/kilt
+    version: 0.3.3
+
+  mocks:
+    github: waterlink/mocks.cr
+    version: 0.9.5
+
+  pg:
+    github: will/crystal-pg
+    version: 0.13.3
+
+  pool:
+    github: ysbaddaden/pool
+    version: 0.2.3
+
+  radix:
+    github: luislavena/radix
+    version: 0.3.8
+
+  redis:
+    github: stefanwille/crystal-redis
+    version: 1.8.0
+
+  sidekiq:
+    github: kemalyst/sidekiq-cli.cr
+    commit: 199757a164daa9fd9d7fe7b334eed2af8ec8c26c
+
+  singleton:
+    github: waterlink/singleton.cr
+    version: 1.0.0
+
+  slang:
+    github: jeromegn/slang
+    commit: 3b657c48791d72c109fa55ce6431d3042efe2f9c
+
+  smtp:
+    github: raydf/smtp.cr
+    commit: 1301f244fd1e251244b0a9fb7f8bc817da9c8854
+

+ 1 - 1
frameworks/Crystal/kemalyst/shard.yml

@@ -9,7 +9,7 @@ license: MIT
 dependencies:
   kemalyst:
     github: kemalyst/kemalyst
-    version: ~> 0.8.0
+    version: ~> 0.9.0
 
   granite_orm:
     github: kemalyst/granite-orm

+ 52 - 46
frameworks/Crystal/kemalyst/src/controllers/test_controller.cr

@@ -1,69 +1,75 @@
 require "../models/*"
 
-class TestController < Kemalyst::Controller
-  def call(context)
-    context.response.headers["Server"] = "Kemalyst"
-    context.response.headers["Date"] = Time.now.to_s
-    call_next(context)
-  end
-
-  action plaintext do
-    text "Hello, World!"
+module TestController 
+  class Plaintext < Kemalyst::Controller
+    def call(context)
+      text "Hello, World!"
+    end
   end
 
-  action json do
-    results = {message: "Hello, World!"}
-    json results.to_json
+  class Json < Kemalyst::Controller
+    def call(context)
+      results = {message: "Hello, World!"}
+      json results.to_json
+    end
   end
 
-  action db do
-    results = {} of Symbol => Int32
-    if world = World.find rand(1..10_000)
-      results = {id: world.id, randomNumber: world.randomNumber}
+  class Db < Kemalyst::Controller
+    def call(context)
+      results = {} of Symbol => Int32
+      if world = World.find rand(1..10_000)
+        results = {id: world.id, randomNumber: world.randomNumber}
+      end
+      json results.to_json
     end
-    json results.to_json
   end
 
-  action queries do
-    queries = params["queries"].as(String)
-    queries = queries.to_i? || 1
-    queries = queries.clamp(1..500)
+  class Queries < Kemalyst::Controller
+    def call(context)
+      queries = context.params["queries"].as(String)
+      queries = queries.to_i? || 1
+      queries = queries.clamp(1..500)
 
-    results = (1..queries).map do
-      if world = World.find rand(1..10_000)
-        {id: world.id, randomNumber: world.randomNumber}
+      results = (1..queries).map do
+        if world = World.find rand(1..10_000)
+          {id: world.id, randomNumber: world.randomNumber}
+        end
       end
-    end
 
-    json results.to_json
+      json results.to_json
+    end
   end
 
-  action updates do
-    queries = params["queries"].as(String)
-    queries = queries.to_i? || 1
-    queries = queries.clamp(1..500)
+  class Updates < Kemalyst::Controller
+    def call(context)
+      queries = context.params["queries"].as(String)
+      queries = queries.to_i? || 1
+      queries = queries.clamp(1..500)
 
-    updated = (1..queries).map do
-      world = World.find rand(1..10_000)
-      if world
-        world.randomNumber = rand(1..10_000)
-        world.save
-        {id: world.id, randomNumber: world.randomNumber}
+      updated = (1..queries).map do
+        world = World.find rand(1..10_000)
+        if world
+          world.randomNumber = rand(1..10_000)
+          world.save
+          {id: world.id, randomNumber: world.randomNumber}
+        end
       end
-    end
 
-    json updated.to_json
+      json updated.to_json
+    end
   end
 
-  action fortunes do
-    fortune = Fortune.new
-    fortune.id = 0
-    fortune.message = "Additional fortune added at request time."
+  class Fortunes < Kemalyst::Controller
+    def call(context)
+      fortune = Fortune.new
+      fortune.id = 0
+      fortune.message = "Additional fortune added at request time."
 
-    fortunes = Fortune.all
-    fortunes << fortune
-    fortunes.sort_by! { |fortune| fortune.not_nil!.message.not_nil! }
+      fortunes = Fortune.all
+      fortunes << fortune
+      fortunes.sort_by! { |fortune| fortune.not_nil!.message.not_nil! }
 
-    html render("fortune/index.slang", "main.slang")
+      html render("fortune/index.slang", "main.slang")
+    end
   end
 end

+ 13 - 0
frameworks/Crystal/kemalyst/src/middleware/custom_headers.cr

@@ -0,0 +1,13 @@
+module Middleware 
+  class CustomHeaders < Kemalyst::Handler::Base
+    def self.instance
+      @@instance ||= new
+    end
+
+    def call(context)
+      context.response.headers["Server"] = "Kemalyst"
+      context.response.headers["Date"] = Time.now.to_s
+      call_next(context)
+    end
+  end
+end