Adventurous Merb

Preview:

DESCRIPTION

My talk at MerbCamp in San Diego. I'll apologize up front. ;)

Citation preview

hi

ExpandingOur Vision With

MERB

Advanced

MERB

Advanced

MERB

Adventurous

MERB

INTRODUCTION

Matt Todd

mtoddhttp://github.com/mtodd/

Halcyon

Highgroove Studios

Developer & OSS Architecthttp://highgroove.com

SWEETNECTAROF THEGODS

EXPECTATIONS

I AM NOTAN EXPERT

WARNING

code for:PROBLEMS& examples

lack of imagination

TheForeground

“forefront, prominent or important position”

meh

not as interestingas the background

:o

TheBackground

DBsCachesBackground ProcessesWeb ServicesEmbedded ComponentsDistributed Grid/Mesh AppsAJAXRack

DBs xCaches xBackground Processes √Web Services √Embedded Components √Distributed Grid/Mesh Apps √AJAX xRack √

BackgroundProcesses

rake tasks

namespace(:nodes) do desc "Purge inactive nodes." task :purge => [:merb_env] do Node.inactive.purge end desc "Scan for nodes" task :scan => [:merb_env] do

Node.detach_and_scan(Node.first) end end

render_then_callrun_later

render_then_call do Node.inactive.purgeend

### OR

run_later do Node.scan(Node.first)endrender

we’ll talk later

WebServices

“software system designed to support interoperable

machine-to-machine interaction over a network”

a serviceover the webjust for apps

JSON isREALLYAwesome

JSON isFUCKINGAwesome

{“foo”:“bar”}

RESTful

/objects.json/objects.json/objects/1.json/objects/1.json/objects/1.json

GETPUTGETDELETEPOST

indexcreateshowdeleteupdate

Merb’s Way

providesrenderdisplay

provides

class Posts < Application provides :json def show @post = Post.get(params[:id]) display @post endend

1.

GIMME XML!

NO BITCH!

GET /posts/1.xml

406 Not Acceptable

display

class Posts < Application provides :json def show @post = Post.get(params[:id]) display @post endend

1.

2.

respond_to do |format| format.html { render } format.json { @post.to_json }end

case content_typewhen :html renderwhen :json display @postend

RailsMerbvs

even better:

provides :json, :xml@post = Post.get(params[:id])display @post

renders XML, JSON, and HTML

AUTOMATICALLYfuck yeah!

EmbeddedComponents

<script type=“text/javascript”src=“/comments.js”></script>

document.write( ‘<div id=“comments”></div>’);

$(function(){ <% @comments.each do |c| c = $(“<p><%=c.body%></p>”); c.attr(‘id’,“comment-<%=c.id%>”); c.appendTo(‘#comments’); <% end %>});

glorified JS& AJAX

DistributedGrid/Mesh

Apps

M

S

S

SS

S

Centralized

N

N

NN

N

Distributed

M

S

N

slave

master

node

{

`

N

Foreground

Background

/sites

[{id:1,url:“http://github.com/”,created_at:...},...]/sites.json

[{id:1,rating:1,created_at:...},...]/sites/n/reports.json

Rack

AWESOME

Framework’sFramework

Mongrel

Merb

Rack

Middleware

Request

Response

mongrelthinebbwebricketc

class YourApp def call(env) [ 200, {‘Content-Type’=>‘text/plain’}, “OK” ] endend

Middleware

mini appsmodifies envavoid passing through

class RackMiddlewareExample def initialize(app) @app = app end def call(env) # voodoo @app.call(env) endend

Fin.

HAHA