sinatra 2.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sinatra might be problematic. Click here for more details.

data/README.ja.md CHANGED
@@ -28,7 +28,10 @@ ruby myapp.rb
28
28
 
29
29
  [http://localhost:4567](http://localhost:4567) を開きます。
30
30
 
31
- ThinがあればSinatraはこれを利用するので、`gem install thin`することをお薦めします。
31
+ コードを変更しても、サーバを再起動しないと変更が有効になりません。
32
+ コードを変更するたびにサーバを再起動するか、[sinatra/reloader](http://www.sinatrarb.com/contrib/reloader)を使ってください。
33
+
34
+ PumaがあればSinatraはこれを利用するので、`gem install puma`することをお薦めします。
32
35
 
33
36
  ## 目次
34
37
 
@@ -315,12 +318,12 @@ end
315
318
  Rackレスポンス、Rackボディオブジェクト、HTTPステータスコードのいずれかとして妥当なオブジェクトであればどのようなオブジェクトでも返すことができます。
316
319
 
317
320
  * 3つの要素を含む配列:
318
- `[ステータス(Fixnum), ヘッダ(Hash), レスポンスボディ(#eachに応答する)]`
321
+ `[ステータス(Integer), ヘッダ(Hash), レスポンスボディ(#eachに応答する)]`
319
322
  * 2つの要素を含む配列:
320
- `[ステータス(Fixnum), レスポンスボディ(#eachに応答する)]`
323
+ `[ステータス(Integer), レスポンスボディ(#eachに応答する)]`
321
324
  * `#each`に応答するオブジェクト。通常はそのまま何も返さないが、
322
325
  与えられたブロックに文字列を渡す。
323
- * ステータスコードを表現する整数(Fixnum)
326
+ * ステータスコードを表現する整数(Integer)
324
327
 
325
328
  これにより、例えばストリーミングを簡単に実装することができます。
326
329
 
@@ -386,7 +389,7 @@ end
386
389
  `:public_folder`オプションを指定することで別の場所を指定することができます。
387
390
 
388
391
  ```ruby
389
- set :public_folder, File.dirname(__FILE__) + '/static'
392
+ set :public_folder, __dir__ + '/static'
390
393
  ```
391
394
 
392
395
  ノート: この静的ファイル用のディレクトリ名はURL中に含まれません。
@@ -551,13 +554,14 @@ get('/') { markdown :index }
551
554
  <tr>
552
555
  <td>依存</td>
553
556
  <td>
554
- <a href="http://www.kuwata-lab.com/erubis/" title="erubis">erubis</a>
557
+ <a href="https://github.com/jeremyevans/erubi" title="erubi">erubi</a>
558
+ または <a href="http://www.kuwata-lab.com/erubis/" title="erubis">erubis</a>
555
559
  または erb (Rubyに同梱)
556
560
  </td>
557
561
  </tr>
558
562
  <tr>
559
563
  <td>ファイル拡張子</td>
560
- <td><tt>.erb</tt>, <tt>.rhtml</tt> or <tt>.erubis</tt> (Erubisだけ)</td>
564
+ <td><tt>.erb</tt>, <tt>.rhtml</tt> または <tt>.erubi</tt> (Erubiだけ) または<tt>.erubis</tt> (Erubisだけ)</td>
561
565
  </tr>
562
566
  <tr>
563
567
  <td>例</td>
@@ -610,7 +614,7 @@ get('/') { markdown :index }
610
614
  <table>
611
615
  <tr>
612
616
  <td>依存</td>
613
- <td><a href="http://sass-lang.com/" title="sass">sass</a></td>
617
+ <td><a href="https://sass-lang.com/" title="sass">sass</a></td>
614
618
  </tr>
615
619
  <tr>
616
620
  <td>ファイル拡張子</td>
@@ -627,7 +631,7 @@ get('/') { markdown :index }
627
631
  <table>
628
632
  <tr>
629
633
  <td>依存</td>
630
- <td><a href="http://sass-lang.com/" title="sass">sass</a></td>
634
+ <td><a href="https://sass-lang.com/" title="sass">sass</a></td>
631
635
  </tr>
632
636
  <tr>
633
637
  <td>ファイル拡張子</td>
@@ -661,7 +665,7 @@ get('/') { markdown :index }
661
665
  <table>
662
666
  <tr>
663
667
  <td>依存</td>
664
- <td><a href="http://liquidmarkup.org/" title="liquid">liquid</a></td>
668
+ <td><a href="https://shopify.github.io/liquid/" title="liquid">liquid</a></td>
665
669
  </tr>
666
670
  <tr>
667
671
  <td>ファイル拡張子</td>
@@ -684,8 +688,8 @@ LiquidテンプレートからRubyのメソッド(`yield`を除く)を呼び出
684
688
  次の何れか:
685
689
  <a href="https://github.com/davidfstr/rdiscount" title="RDiscount">RDiscount</a>,
686
690
  <a href="https://github.com/vmg/redcarpet" title="RedCarpet">RedCarpet</a>,
687
- <a href="http://deveiate.org/projects/BlueCloth" title="BlueCloth">BlueCloth</a>,
688
- <a href="http://kramdown.gettalong.org/" title="kramdown">kramdown</a>,
691
+ <a href="https://github.com/ged/bluecloth" title="bluecloth">BlueCloth</a>,
692
+ <a href="https://kramdown.gettalong.org/" title="kramdown">kramdown</a>,
689
693
  <a href="https://github.com/bhollis/maruku" title="maruku">maruku</a>
690
694
  </td>
691
695
  </tr>
@@ -746,7 +750,7 @@ erb :overview, :locals => { :text => textile(:introduction) }
746
750
  %p= textile(:greetings)
747
751
  ```
748
752
 
749
- TexttileからはRubyを呼ぶことができないので、Textileで書かれたレイアウトを使うことはできません。しかしながら、`:layout_engine`オプションを渡すことでテンプレートのものとは異なるレンダリングエンジンをレイアウトのために使うことができます。
753
+ TextileからはRubyを呼ぶことができないので、Textileで書かれたレイアウトを使うことはできません。しかしながら、`:layout_engine`オプションを渡すことでテンプレートのものとは異なるレンダリングエンジンをレイアウトのために使うことができます。
750
754
 
751
755
  #### RDoc テンプレート
752
756
 
@@ -786,7 +790,7 @@ RDocからはRubyを呼ぶことができないので、RDocで書かれたレ
786
790
  <table>
787
791
  <tr>
788
792
  <td>依存</td>
789
- <td><a href="http://asciidoctor.org/" title="Asciidoctor">Asciidoctor</a></td>
793
+ <td><a href="https://asciidoctor.org/" title="Asciidoctor">Asciidoctor</a></td>
790
794
  </tr>
791
795
  <tr>
792
796
  <td>ファイル拡張子</td>
@@ -824,7 +828,7 @@ RadiusテンプレートからRubyのメソッドを直接呼び出すことが
824
828
  <table>
825
829
  <tr>
826
830
  <td>依存</td>
827
- <td><a href="http://markaby.github.io/" title="Markaby">Markaby</a></td>
831
+ <td><a href="https://markaby.github.io/" title="Markaby">Markaby</a></td>
828
832
  </tr>
829
833
  <tr>
830
834
  <td>ファイル拡張子</td>
@@ -1456,7 +1460,7 @@ get '/foo' do
1456
1460
  status 418
1457
1461
  headers \
1458
1462
  "Allow" => "BREW, POST, GET, PROPFIND, WHEN",
1459
- "Refresh" => "Refresh: 20; http://www.ietf.org/rfc/rfc2324.txt"
1463
+ "Refresh" => "Refresh: 20; https://www.ietf.org/rfc/rfc2324.txt"
1460
1464
  body "I'm a tea pot!"
1461
1465
  end
1462
1466
  ```
@@ -1481,37 +1485,55 @@ end
1481
1485
 
1482
1486
  これはストリーミングAPI、[Server Sent Events](https://w3c.github.io/eventsource/)の実装を可能にし、[WebSockets](https://en.wikipedia.org/wiki/WebSocket)の土台に使うことができます。また、一部のコンテンツが遅いリソースに依存しているときに、スループットを上げるために使うこともできます。
1483
1487
 
1484
- ノート: ストリーミングの挙動、特に並行リクエスト(cuncurrent requests)の数は、アプリケーションを提供するのに使われるWebサーバに強く依存します。いくつかのサーバは、ストリーミングを全くサポートしません。サーバがストリーミングをサポートしない場合、ボディは`stream`に渡されたブロックの実行が終了した後、一度に全部送られることになります。ストリーミングは、Shotgunを使った場合は全く動作しません。
1488
+ ノート: ストリーミングの挙動、特に並行リクエスト(concurrent requests)の数は、アプリケーションを提供するのに使われるWebサーバに強く依存します。いくつかのサーバは、ストリーミングを全くサポートしません。サーバがストリーミングをサポートしない場合、ボディは`stream`に渡されたブロックの実行が終了した後、一度に全部送られることになります。ストリーミングは、Shotgunを使った場合は全く動作しません。
1485
1489
 
1486
- オプション引数が`keep_open`にセットされている場合、ストリームオブジェクト上で`close`は呼ばれず、実行フローの任意の遅れたタイミングでユーザがこれを閉じることを可能にします。これはThinやRainbowsのようなイベント型サーバ上でしか機能しません。他のサーバでは依然ストリームは閉じられます。
1490
+ オプション引数が`keep_open`にセットされている場合、ストリームオブジェクト上で`close`は呼ばれず、実行フローの任意の遅れたタイミングでユーザがこれを閉じることを可能にします。これはRainbowsのようなイベント型サーバ上でしか機能しません。他のサーバでは依然ストリームは閉じられます。
1487
1491
 
1488
1492
  ```ruby
1489
- # ロングポーリング
1490
-
1491
- set :server, :thin
1492
- connections = []
1493
+ # config.ru
1494
+ require 'sinatra/base'
1493
1495
 
1494
- get '/subscribe' do
1495
- # サーバイベントにおけるクライアントの関心を登録
1496
- stream(:keep_open) do |out|
1497
- connections << out
1498
- # 死んでいるコネクションを排除
1499
- connections.reject!(&:closed?)
1496
+ class App < Sinatra::Base
1497
+ connections = []
1498
+
1499
+ get '/subscribe' do
1500
+ # register a client's interest in server events
1501
+ # サーバイベントにおけるクライアントの関心を登録
1502
+ stream(:keep_open) do |out|
1503
+ connections << out
1504
+ # 死んでいるコネクションを排除
1505
+ connections.reject!(&:closed?)
1506
+ end
1500
1507
  end
1501
- end
1502
1508
 
1503
- post '/message' do
1504
- connections.each do |out|
1505
- # クライアントへ新規メッセージ到着の通知
1506
- out << params['message'] << "\n"
1509
+ post '/:message' do
1510
+ connections.each do |out|
1511
+ # クライアントへ新規メッセージ到着の通知
1512
+ out << params['message'] << "\n"
1507
1513
 
1508
- # クライアントへの再接続の指示
1509
- out.close
1514
+ # クライアントへの再接続の指示
1515
+ out.close
1516
+ end
1517
+
1518
+ # 肯定応答
1519
+ "message received"
1510
1520
  end
1521
+ end
1522
+
1523
+ run App
1524
+ ```
1511
1525
 
1512
- # 肯定応答
1513
- "message received"
1526
+ ```ruby
1527
+ # rainbows.conf
1528
+ Rainbows! do
1529
+ use :EventMachine
1514
1530
  end
1531
+ ````
1532
+
1533
+ 次のように起動します。
1534
+
1535
+ ```shell
1536
+ rainbows -c rainbows.conf
1515
1537
  ```
1516
1538
 
1517
1539
  クライアントはソケットに書き込もうとしている接続を閉じることも可能です。そのため、記述しようとする前に`out.closed?`をチェックすることを勧めます。
@@ -1586,7 +1608,7 @@ end
1586
1608
 
1587
1609
  ```ruby
1588
1610
  redirect to('/bar'), 303
1589
- redirect 'http://www.google.com/', 'wrong place, buddy'
1611
+ redirect 'https://www.google.com/', 'wrong place, buddy'
1590
1612
  ```
1591
1613
 
1592
1614
  また、`redirect back`を使えば、簡単にユーザが来たページへ戻るリダイレクトを作れます。
@@ -1951,7 +1973,7 @@ end
1951
1973
 
1952
1974
  ### 攻撃防御に対する設定
1953
1975
 
1954
- Sinatraは[Rack::Protection](https://github.com/sinatra/rack-protection#readme)を使用することで、アプリケーションを一般的な日和見的攻撃から守っています。これは簡単に無効化できます(が、アプリケーションに大量の一般的な脆弱性を埋め込むことになってしまいます)。
1976
+ Sinatraは[Rack::Protection](https://github.com/sinatra/sinatra/tree/master/rack-protection#readme)を使用することで、アプリケーションを一般的な日和見的攻撃から守っています。これは簡単に無効化できます(が、アプリケーションに大量の一般的な脆弱性を埋め込むことになってしまいます)。
1955
1977
 
1956
1978
  ```ruby
1957
1979
  disable :protection
@@ -2106,7 +2128,7 @@ set :protection, :session => true
2106
2128
 
2107
2129
  <dt>threaded</dt>
2108
2130
  <dd>
2109
- <tt>true</tt>に設定されているときは、Thinにリクエストを処理するために<tt>EventMachine.defer</tt>を使うことを通知する。
2131
+ <tt>true</tt>に設定されているときは、サーバにリクエストを処理するために<tt>EventMachine.defer</tt>を使うことを通知する。
2110
2132
  </dd>
2111
2133
 
2112
2134
  <dt>views</dt>
@@ -2219,7 +2241,7 @@ Sinatraを開発環境の下で実行している場合は、特別な`not_found
2219
2241
 
2220
2242
  ## Rackミドルウェア(Rack Middleware)
2221
2243
 
2222
- SinatraはRuby製Webフレームワークのミニマルな標準的インタフェースである[Rack](http://rack.github.io/)上に構築されています。アプリケーションデベロッパーにとってRackにおける最も興味深い機能は、「ミドルウェア(middleware)」をサポートしていることであり、これは、サーバとアプリケーションとの間に置かれ、HTTPリクエスト/レスポンスを監視および/または操作することで、各種の汎用的機能を提供するコンポーネントです。
2244
+ SinatraはRuby製Webフレームワークのミニマルな標準的インタフェースである[Rack](https://rack.github.io/)上に構築されています。アプリケーションデベロッパーにとってRackにおける最も興味深い機能は、「ミドルウェア(middleware)」をサポートしていることであり、これは、サーバとアプリケーションとの間に置かれ、HTTPリクエスト/レスポンスを監視および/または操作することで、各種の汎用的機能を提供するコンポーネントです。
2223
2245
 
2224
2246
  Sinatraはトップレベルの`use`メソッドを通して、Rackミドルウェアパイプラインの構築を楽にします。
2225
2247
 
@@ -2630,21 +2652,22 @@ ruby myapp.rb [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-o HOST] [-s HANDLER]
2630
2652
  -p # ポート指定(デフォルトは4567)
2631
2653
  -o # ホスト指定(デフォルトは0.0.0.0)
2632
2654
  -e # 環境を指定 (デフォルトはdevelopment)
2633
- -s # rackserver/handlerを指定 (デフォルトはthin)
2655
+ -s # rackserver/handlerを指定 (デフォルトはpuma)
2634
2656
  -x # mutex lockを付ける (デフォルトはoff)
2635
2657
  ```
2636
2658
 
2637
2659
  ### マルチスレッド
2638
2660
 
2639
- _この[StackOverflow][so-answer]でのKonstantinによる回答を言い換えています。_
2661
+ _この[StackOverflow](https://stackoverflow.com/a/6282999/5245129)
2662
+ のKonstantinによる回答を言い換えています。_
2640
2663
 
2641
- Sinatraでは同時実行モデルを負わせることはできませんが、根本的な部分であるThinやPuma、WebrickのようなRackハンドラ(サーバー)部分に委ねることができます。
2664
+ Sinatraでは同時実行モデルを負わせることはできませんが、根本的な部分であるやPuma、WEBrickのようなRackハンドラ(サーバー)部分に委ねることができます。
2642
2665
  Sinatra自身はスレッドセーフであり、もしRackハンドラが同時実行モデルのスレッドを使用していても問題はありません。
2643
2666
  つまり、これはサーバーを起動させる時、特定のRackハンドラに対して正しい起動処理を特定することが出来ます。
2644
- この例はThinサーバーをマルチスレッドで起動する方法のデモです。
2667
+ この例はRainbowsサーバーをマルチスレッドで起動する方法のデモです。
2645
2668
 
2646
2669
  ```ruby
2647
- # app.rb
2670
+ # config.ru
2648
2671
 
2649
2672
  require 'sinatra/base'
2650
2673
 
@@ -2654,16 +2677,23 @@ class App < Sinatra::Base
2654
2677
  end
2655
2678
  end
2656
2679
 
2657
- App.run!
2680
+ run App
2658
2681
  ```
2659
2682
 
2660
- サーバーを開始するコマンドです。
2683
+ ```ruby
2684
+ # rainbows.conf
2661
2685
 
2686
+ # RainbowsのコンフィギュレータはUnicornのものをベースにしています。
2687
+ Rainbows! do
2688
+ use :ThreadSpawn
2689
+ end
2662
2690
  ```
2663
- thin --threaded start
2664
- ```
2665
2691
 
2666
- [so-answer]: http://stackoverflow.com/questions/6278817/is-sinatra-multi-threaded/6282999#6282999)
2692
+ 次のようなコマンドでサーバを起動します。
2693
+
2694
+ ```
2695
+ rainbows -c rainbows.conf
2696
+ ```
2667
2697
 
2668
2698
  ## 必要環境
2669
2699
 
@@ -2734,7 +2764,7 @@ gem install sinatra --pre
2734
2764
 
2735
2765
  ### Bundlerを使う場合
2736
2766
 
2737
- 最新のSinatraでアプリケーションを動作させたい場合には、[Bundler](http://bundler.io)を使うのがお薦めのやり方です。
2767
+ 最新のSinatraでアプリケーションを動作させたい場合には、[Bundler](https://bundler.io)を使うのがお薦めのやり方です。
2738
2768
 
2739
2769
  まず、Bundlerがなければそれをインストールします。
2740
2770
 
@@ -2797,7 +2827,7 @@ sudo rake install
2797
2827
 
2798
2828
  ## バージョニング(Versioning)
2799
2829
 
2800
- Sinatraは、[Semantic Versioning](http://semver.org/)におけるSemVerおよびSemVerTagの両方に準拠しています。
2830
+ Sinatraは、[Semantic Versioning](https://semver.org/)におけるSemVerおよびSemVerTagの両方に準拠しています。
2801
2831
 
2802
2832
  ## 参考文献
2803
2833
 
@@ -2805,7 +2835,7 @@ Sinatraは、[Semantic Versioning](http://semver.org/)におけるSemVerおよ
2805
2835
  * [プロジェクトに参加(貢献)する](http://www.sinatrarb.com/contributing.html) - バグレポート パッチの送信、サポートなど
2806
2836
  * [Issue tracker](https://github.com/sinatra/sinatra/issues)
2807
2837
  * [Twitter](https://twitter.com/sinatra)
2808
- * [メーリングリスト](http://groups.google.com/group/sinatrarb/topics)
2838
+ * [メーリングリスト](https://groups.google.com/group/sinatrarb/topics)
2809
2839
  * http://freenode.net上のIRC: [#sinatra](irc://chat.freenode.net/#sinatra)
2810
2840
  * [Sinatra Book](https://github.com/sinatra/sinatra-book/) クックブック、チュートリアル
2811
2841
  * [Sinatra Recipes](http://recipes.sinatrarb.com/) コミュニティによるレシピ集
data/README.ko.md CHANGED
@@ -315,10 +315,10 @@ end
315
315
 
316
316
  유효한 Rack 응답, Rack 본문 객체 또는 HTTP 상태 코드가 되는 어떠한 객체라도 반환할 수 있습니다.
317
317
 
318
- * 세 요소를 가진 배열: `[상태 (Fixnum), 헤더 (Hash), 응답 본문 (#each에 반응)]`
319
- * 두 요소를 가진 배열: `[상태 (Fixnum), 응답 본문 (#each에 반응)]`
318
+ * 세 요소를 가진 배열: `[상태 (Integer), 헤더 (Hash), 응답 본문 (#each에 반응)]`
319
+ * 두 요소를 가진 배열: `[상태 (Integer), 응답 본문 (#each에 반응)]`
320
320
  * `#each`에 반응하고 주어진 블록으로 문자열만을 전달하는 객체
321
- * 상태 코드를 의미하는 Fixnum
321
+ * 상태 코드를 의미하는 Integer
322
322
 
323
323
  이것을 이용한 예를 들자면, 스트리밍(streaming) 예제를 쉽게 구현할 수 있습니다.
324
324
 
@@ -385,7 +385,7 @@ end
385
385
  변경하려면 `:public_folder` 옵션을 지정하면 됩니다.
386
386
 
387
387
  ```ruby
388
- set :public_folder, File.dirname(__FILE__) + '/static'
388
+ set :public_folder, __dir__ + '/static'
389
389
  ```
390
390
 
391
391
  public 디렉터리명은 URL에 포함되지 않는다는 점에 주의하세요.
@@ -653,7 +653,7 @@ get('/') { markdown :index }
653
653
  <table>
654
654
  <tr>
655
655
  <td>의존성</td>
656
- <td><a href="http://liquidmarkup.org/">liquid</a></td>
656
+ <td><a href="https://shopify.github.io/liquid/">liquid</a></td>
657
657
  </tr>
658
658
  <tr>
659
659
  <td>파일 확장자</td>
@@ -676,7 +676,7 @@ Liquid 템플릿에서는 루비 메서드(`yield` 제외)를 호출할 수 없
676
676
  <td>
677
677
  <a href="https://github.com/davidfstr/rdiscount" title="RDiscount">RDiscount</a>,
678
678
  <a href="https://github.com/vmg/redcarpet" title="RedCarpet">RedCarpet</a>,
679
- <a href="http://deveiate.org/projects/BlueCloth" title="BlueCloth">BlueCloth</a>,
679
+ <a href="https://github.com/ged/bluecloth" title="bluecloth">BlueCloth</a>,
680
680
  <a href="http://kramdown.gettalong.org/" title="kramdown">kramdown</a>,
681
681
  <a href="https://github.com/bhollis/maruku" title="maruku">maruku</a>
682
682
  중 아무거나
@@ -2023,7 +2023,7 @@ end
2023
2023
 
2024
2024
  ### 공격 방어 설정하기(Configuring attack protection)
2025
2025
 
2026
- Sinatra는 [Rack::Protection](https://github.com/sinatra/rack-protection#readme)을 사용하여
2026
+ Sinatra는 [Rack::Protection](https://github.com/sinatra/sinatra/tree/master/rack-protection#readme)을 사용하여
2027
2027
  일반적이고 일어날 수 있는 공격에 대비합니다. 이 모듈은 간단하게 비활성시킬 수 있습니다.
2028
2028
  (하지만 애플리케이션에 엄청나게 많은 취약성을 야기합니다.)
2029
2029