1. 自己紹介 2.Sinatra の概要 3.Rails との比較 4.workshop メニュー

Similar documents
Sinatra と MongoDB 今回は Sinatra で MongoDB の操作を体験してみます 進捗に合わせて ドライバから Ruby で使える便利な ORM の紹介をします

Sequel のすすめ 私が SQL を嫌いな理由 とみたまさひろ RubyHiroba Sequel のすすめ - 私が SQL を嫌いな理由 Powered by Rabbit 2.0.7

Dolteng Scaffoldに対する機能追加とマスタ-ディテールScaffoldの紹介

文字列操作と正規表現

1.SqlCtl クラスリファレンス SqlCtl クラスのリファレンスを以下に示します メソッドの実行中にエラーが発生した場合は標準エラー出力にメッセージを出力します (1)Connect() メソッド データベースへ connect 要求を行います boolean Connect(String

ガイダンス

6 (1) app.html.eex 28 lib/nano_planner_web/templates/layout/app.html.eex 27 <footer> Oiax Inc <%= this_year() %> Oiax Inc. 29 </footer>

利用者

PowerPoint Presentation

ruby novice ruby novice ruby novice.

Java言語 第1回

プログラミング基礎I(再)

2

IronPython による柔軟なゲーム開発 筑波大学 AmusementCreators

WPF アプリケーションの 多言語切替

C#の基本

メール全文検索アプリケーション Sylph-Searcher のご紹介 SRA OSS, Inc. 日本支社技術部チーフエンジニア Sylpheed 開発者 山本博之 Copyright 2007 SRA OSS, Inc. Japan All right

( 目次 ) 1. はじめに 開発環境の準備 仮想ディレクトリーの作成 ASP.NET のWeb アプリケーション開発環境準備 データベースの作成 データベースの追加 テーブルの作成

2

Exam : 1z1-809-JPN Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z1-809-JPN Exam's Question and Answers 1 from Ac

Rmenuフレームワーク

コンピュータ中級B ~Javaプログラミング~ 第3回 コンピュータと情報をやりとりするには?

Microsoft PowerPoint - chap10_OOP.ppt

新・明解Java入門

2

WEBシステムのセキュリティ技術

Java講座

メソッドのまとめ

MVP for VB が語る C# 入門

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

PowerPoint プレゼンテーション

PowerPoint Presentation

JavaプログラミングⅠ

データを TreeView コントロールで表示 VisualStudio2017 の Web サイトプロジェクトで bootstrap, 及び script フォルダの js ファイルが使用できるマスターページを親とする TestTreeView.aspx ページを作成します 下記の html コー

Java updated

TestDesign for Web

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");


使える! IBM Systems Director Navigator for i の新機能

: : : TSTank 2

10 (1) s 10.2 rails c Rails 7 > item = PlanItem.new => #<PlanItem id nil, name nil,...> > item.name = "" => "" > item.valid? => true valid? true false

Ruby 2.3 のてざわり新機能と使いどころ Kunihiko Ito ESM 富山合同勉強会


プログラミング入門1

Javaの作成の前に


Seasar.NET入門

スライド 1

はじめに コースの概要と目的 Oracle をより効率的に使用するための SQL のチューニング方法について説明します また 索引の有無 SQL の 記述方法がパフォーマンスにどのように影響するのかを実習を通して理解します 受講対象者 アプリケーション開発者 / データベース管理者の方 前提条件 S

Microsoft Word - keisankigairon.ch doc

QualysGuard(R) Release Notes

データベースアクセス

Transcription:

Sinatra( と Rails) たきぐち (atakig)@minami.rb

1. 自己紹介 2.Sinatra の概要 3.Rails との比較 4.workshop メニュー

自己紹介 システム開発の仕事 Emacs, Mac, CLI 好き Ruby を知ったのはたぶん 2000 年 これまで書いた Ruby のコード数はたかが知れている rails は 0.9 で少し触った sinatra は 1 画面のサイト作ったのみ Ruby Association Certified Ruby Programmer Silver twitter:atakig

sinatra とは sinatra は ruby で下記のような最小労力で手早くウェブアプリケーションを作成するための DSL です (http://www.sinatrarb.com/intro-jp.html ) # myapp.rb require 'rubygems' require 'sinatra' get '/' do 'Hello world!' End >ruby myapp.rb

sinatra とは Java の Hello World と比べると public class HelloWorld { public static void main (String[] args) { System.out.println("Hello World!!"); } }

sinatra とは DSL: 特定のタスク向けに設計されたプログラミング言語を意味する 汎用プログラミング言語の対義語 例 :SQL, 正規表現

Sinatra と Rails(0.9) の比較 1 結合度 2 構成ファイル 3 学習コスト sinatra 疎結合データベース連携や テンプレートエンジンに好きなものを選べる 少ない 少し rails 密結合事前に組み込まれた ActiveXXX 等が前提となっている 多い たくさん ( コマンド多し!)

Sinatra と Rails 比較その 2 sinatra 1 大人数での開発 フリーダム過ぎて向 いていない Rails ファイル構成 命名規約等がしっかりしているため 適用可能 2 実績??? たくさんあり 3 大規模サイトを作るとしたら ファイル構成がカオスになり 収集がつかなくなりそう 上の上と同じ 4 情報量 あまりないし あって も英語の場合が多 い 上の上の上と同じ

Sinatra と Rails 比較 O/R マッパー O/R マッパーを題材に少し比較してみます Active Record と Sequel の比較になるという突っこみは不用です Sequel のいいなと思う点 テーブル定義用のクラスが不用 プライマリキーは何でも OK

Sinatra と Rails 比較 O/R マッパー 操作種別コード PK での検索 Where での検索 AR Seq AR Seq Model.find(1) DB[:table].filter(:id=>1) Model.find( id = :id AND name = :name, {:id=>1, :name => yalab }) DB[:table].filter(:id=>1, :name=>'yalab') 表結合 AR Model.find(:all, :include=>[:other]) Seq DB[:table].left_outer_join(:other, :id=>:outer_key) UPDATE AR Model.update(1, :name=>'who???') Seq DB[:table].filter(:id=>1).update(:name=>'Who???') INSERT AR Model.new(:id=>2, :name='atakig') Seq delete AR Model.delete(2) Seq DB[:table].insert(:id=>2, :name=>'atakig') DB[:table].filter(:id=>2).delete 種別の AR は Active Record, Seq は Sequel を指します

実習 : Hello World # app.rb require 'rubygems' require 'sinatra' require 'sinatra/reloader' get '/' do 'Hello world!'

実習 : Routing # app.rb require 'rubygems' require 'sinatra' require 'sinatra/reloader' get '/' do 'Hello world!' get '/name/:name' do "Hello #{params[:name]}!"

実習 : テンプレート #app.rb get '/haml' do @hello=' はろう ' @world=' わーるど ' haml :index #views/index.haml %table %tr %td=@hello %tr %td=@world Haml の基本 % + タグ名でタグが生成 % タグ名の後に =ruby コードで ruby コードの評価値がタグの内容となる % タグ名 +ruby ハッシュで属性を指定可能例 : %div{:class=>'code', :id='message'} % タグ名が指定されない場合は <div> タグが自動的に設定. と文字列で文字列がクラス名になる # と文字列で文字列が id になる 例 :.item{:id => "item#{item.id}"}= item.body <div class='item' id='item<%= item.id %>'> <%= item.body %> </div> 参考 URL : http://haml-lang.com/tutorial.html

実習 : テストツール リファクタリング :Ruby エディションの p.30 に コードを書きながら Test::Unit か RSpec を使ってテストをしていないプログラマは Ruby ディベロッパとしてまともに扱われなくなるだろう というセリフがありますが テストツールの使い方を実習します sinatra でテストツールを使う場合は rack/test とテストツールを組み合わせて行う test/unit rspec bacon test/spec

test::unit require 'app' require 'test/unit' require 'rack/test' class MyAppTest < Test::Unit::TestCase include Rack::Test::Methods def app Sinatra::Application def test_root get '/' assert_equal 'Hello world!', last_response.body def test_haml get '/haml' assert last_response.ok? assert last_response.successful? assert last_response.match /<td> はろう!<\/td>/ assert last_response=~/<td> わーるど <\/td>/

rspec require 'app' require 'spec' require 'rack/test' describe 'sinatra_rspec_test' do include Rack::Test::Methods def app Sinatra::Application it "test_my_default" do get '/' last_response.body.should == 'Hello world!' last_response.should be_ok it "test_haml do get '/haml' last_response.headers["content-type"].should == "text/html" last_response.should be_successful last_response.status.should == 200 (last_response.body =~ /<td> はろう!<\/td>/).should be_true last_response.body.match(/<td> わーるど <\/td>/).should be_true

中規模開発にあたり ファイルの分割は可能 public/myapp.rb public/my_view/index.haml public/yourapp.rb public/your_view/index.haml config.ru

config.ru require 'rubygems' require 'sinatra/base' require 'public/myapp' require 'public/yourapp' use MyApp use YourApp run Sinatra::Base

public/myapp.rb class MyApp < Sinatra::Base require 'haml' set :views, File.dirname( FILE ) + '/my_view' get '/myapp' do haml :index

my_view/index.haml %table %tr %td my_index # rackup config.ru

Rails との中間地点を埋める Padrino<http://www.padrinorb.com/> Padrino は ruby のフレームワークで Sinatra というすばらしいマイクロフレームワークの上に構築されました Sinatra は素早くシンプルな web アプリケーションを ruby で作るための DSL です Padrino は Sinatra を素晴しくしようとし続けている間 Sinatra で構築するのを楽しく そしてより発展した web アプリケーションを簡単に作成できます Padrino was created to make it fun and easy to code more advanced web applications while still adhering to the spirit that makes Sinatra great!