Ruby & Ruby on Rails for arkitekter. Kim Harding Christensen khc@kimharding.com

Similar documents
Building and Deploying Web Scale Social Networking Applications Using Ruby on Rails and Oracle. Kuassi Mensah Group Product Manager

1. Was ist das? II. Wie funktioniert das? III. Wo funktioniert das nicht?

How To Create A Model In Ruby (Orm)

Building Dynamic Web 2.0 Websites with Ruby on Rails

Outline. Lecture 18: Ruby on Rails MVC. Introduction to Rails

Ruby on Rails is a web application framework written in Ruby, a dynamically typed programming language The amazing productivity claims of Rails is

OIO Dekstop applikation

Ruby On Rails. CSCI 5449 Submitted by: Bhaskar Vaish

Designing RESTful Web Applications

The Learn-Verified Full Stack Web Development Program

Content Management System (Dokument- og Sagsstyringssystem)

RESTful Rails Development. translated by Florian Görsdorf and Ed Ruder

Deep in the CRUD LEVEL 1

Oracle Application Express

Rake Task Management Essentials

Agile Development with Groovy and Grails. Christopher M. Judd. President/Consultant Judd Solutions, LLC

Lecture 3 ActiveRecord Rails persistence layer

CS169.1x Lecture 5: SaaS Architecture and Introduction to Rails " Fall 2012"

2 halvleg. 1 halvleg. Opvarmning. 2 halvleg. 3 halvleg. Advanced & Powerful. Basic PC-based Automation. Diagnose. Online Tools & Add-on s

Accessing Data with ADOBE FLEX 4.6

Intruduction to Groovy & Grails programming languages beyond Java

Ruby on Rails. a high-productivity web application framework. blog.curthibbs.us/ Curt Hibbs <curt@hibbs.com>

Ruby on Rails. Object Oriented Analysis & Design CSCI-5448 University of Colorado, Boulder. -Dheeraj Potlapally

SPDE. Lagring af større datamængder. make connections share ideas be inspired. Henrik Dorf Chefkonsulent SAS Institute A/S

XQuery Web Apps. for Java Developers

Polyglot Multi-Paradigm. Modeling. MDA in the Real World. Stefan Tilkov

This tutorial has been designed for beginners who would like to use the Ruby framework for developing database-backed web applications.

Stefan Tilkov. Stefan Tilkov, innoq Deutschland GmbH REST Introduction

What s really under the hood? How I learned to stop worrying and love Magento

Rhomobile cross-platfrom

Join af tabeller med SAS skal det være hurtigt?

Ruby On Rails. James Reynolds

Intro to Web Programming. using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000

Evaluation. Chapter 1: An Overview Of Ruby Rails. Copy. 6) Static Pages Within a Rails Application

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

Slides from INF3331 lectures - web programming in Python

Ruby on Rails Tutorial - Bounded Verification of Data Models

Web-Based Hazus-MH. A Conceptual Approach. Mourad Bouhafs, AVP ATKINS Atlanta mourad.bouhafs@atkinsglobal.com

Teaching Tools Research Group: Course Management Software

DRb Distributed Ruby. Johan Sørensen

Comparing Dynamic and Static Language Approaches to Web Frameworks

Enterprise Recipes with Ruby and Rails

ASP.NET MVC. in Action JEFFREY PALERMO JIMMY BOGARD BEN SCHEIRMAN MANNING. (74 w. long.) WITH MVCCONTRIB, N HIBERNATE, AND MORE.

SRX. SRX Firewalls. Rasmus Elmholt V1.0

A Tour of Silex and Symfony Components. Robert

02267: Software Development of Web Services

Avaya Inventory Management System

Cloud Powered Mobile Apps with Microsoft Azure

Specify the location of an HTML control stored in the application repository. See Using the XPath search method, page 2.

RoR to RubyMotion Writing Your First ios App With RubyMotion. Michael Denomy BostonMotion User Group June 25, 2013

BDD with Cucumber and RSpec. Marcus Ahnve Valtech

Ruby on Rails. Computerlabor

A Model of the Operation of The Model-View- Controller Pattern in a Rails-Based Web Server

Web Framework Performance Examples from Django and Rails

A Comparison of Service-oriented, Resource-oriented, and Object-oriented Architecture Styles

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Application layer Web 2.0

RESTful web applications with Apache Sling

Agile Web Development with Rails 4

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

Policy Guide Access Manager 3.1 SP5 January 2013

Cross-domain Identity Management System for Cloud Environment

THE ROAD TO CODE. ANDROID DEVELOPMENT IMMERSIVE May 31. WEB DEVELOPMENT IMMERSIVE May 31 GENERAL ASSEMBLY

Clustering a Grails Application for Scalability and Availability

Distribution and Integration Technologies

Customer Bank Account Management System Technical Specification Document

Web-services for sensor-based and location-aware products

Web Frameworks. web development done right. Course of Web Technologies A.A. 2010/2011 Valerio Maggio, PhD Student Prof.

Certified PHP/MySQL Web Developer Course

Integration the Web 2.0 way. Florian Daniel April 28, 2009

Ruby on Rails Web Mashup Projects

Bachelor Project System (BEPsys)

Security Testing For RESTful Applications

Integrating Complementary Tools with PopMedNet TM

How to Build Successful DSL s. Jos Warmer Leendert Versluijs

How to Build a Model Layout Using Rails

Rails 4 Quickly. Bala Paranj.

Brakeman and Jenkins: The Duo Detects Defects in Ruby on Rails Code

From RPC to Web Apps: Trends in Client-Server Systems

Transcription:

Ruby & Ruby on Rails for arkitekter Kim Harding Christensen khc@kimharding.com

Aga Intro & problemstilling Introduktion til Ruby DSL er Introduktion til Ruby on Rails Begreber (MVC & REST) Demo

Intro

Kim er ikke glad!

Software udvikling er for svært og tager al for lang tid

Problemområde [Distribuerede informationssystemer].net 3.0

Infosets + Objects + Tuples = #&$?!

hvilket fører til

When I work in Java, I wouldn't say I feel joy. I don't feel like I'm riding a fast stallion through beautiful wooded hills, the wind in my long, flowing hair. I feel more like I'm struggling to convince a workhorse to pull a plow. Bill Venners

Java is the blunt scissors of programming. It s what we give to children to program Dave Thomas

Problemområde Sprog Platform

Introduktion til Ruby (på 10 slides) I have a lot of trouble writing about Ruby, because I find there's nothing to say. It's why I almost never post to the O'Reilly Ruby blog. Ruby seems so self-explanatory to me. It makes it almost boring; you try to focus on Ruby and you wind up talking about some problem domain instead of the language. I think that's the goal of all programming languages, but so far Ruby's one of the few to succeed at it so well. Steve Yegge

Ruby Pure Object-Oriented Language Dynamisk type system Simpel nedarvning + mixins Block, closures, continuations Read-eval-print Meta-programmering, metaklasser, introspection, eval Simpel & konsistent syntaks Regulære udtryk Cross-platform

class MyClass @instance_var @@class_var def instance_method(arg)... def self.class_method(arg)... def foo() # getter @foo def foo=(value) # setter @foo = value def state_changing_method!()... def query_method?...

class LinkedList class Node def initialize(element) @element = element def element() @element def next() @next def next=(node) @next = node def add(element)...

class LinkedList class Node def initialize(element) @element = element def element() @element class Node attr_reader :element attr_accessor :next def initialize(element) @element = element def next() @next def next=(node) @next = node def add(element)...

class LinkedList class Node... def add(element) node = Node.new(element) if (@first == nil) @first = node if (@last!= nil) @last.next = node @last = node

class LinkedList class Node... def add(element) node = Node.new(element) if (@first == nil) @first = node if (@last!= nil) @last.next = node @last = node class LinkedList class Node... def add(element) node = Node.new(element) @first = node unless @first @last.next = node if @last @last = node

Block & Closures a = 7 [1,2,3].each { element puts(element + a)}

Block & Closures a = 7 [1,2,3].each { element puts(element + a)} def twice() yield yield twice() { puts Hello }

class LinkedList def add(element)... def each() if block_given? node = @first while node do yield node.element node = node.next self > l = LinkedList.new > [1,2,3,4,5].each { e l.add e} > l.each { e puts e} 1 2 3 4 5 >

Nedarvning class Collection def size() count = 0 self.each { e count += 1} count class LinkedList < Collection def add(element)... def each()...

Moduler & Mixins module Enumeration def select() result = Array.new this.each { e result << yield(e)} result def detect()... def reject()... def collect()......

class Collection include Enumeration def size() count = 0 self.each { e count += 1} count class LinkedList < Collection def add(element)... alias :<< :add def each()...

Metode lookup class Object include Kernel class A include M module Kernel module M class B < A b = B.new b.foo

Domain Specific Languages

DSL Ekstern DSL Intern DSL http://martinfowler.com/articles/languageworkbench.html

Rake - Ruby Make Rakefiler er skrevet i standard Ruby - ingen behov for XML filer Tasks med afhængigheder Rule patterns Rake består af en fil: 400-500 linier Ruby kode http://rake.rubyforge.org http://www.martinfowler.com/articles/rake.html

file 'main.o' => ["main.c", "greet.h"] do sh "cc -c -o main.o main.c" file 'greet.o' => ['greet.c'] do sh "cc -c -o greet.o greet.c" file "hello" => ["main.o", "greet.o"] do sh "cc -o hello main.o greet.o" > rake hello

require 'rake/clean' CLEAN.include('*.o') CLOBBER.include('hello') task :default => ["hello"] SRC = FileList['*.c'] OBJ = SRC.ext('o') rule '.o' => '.c' do t sh "cc -c -o #{t.name} #{t.source}" file "hello" => OBJ do sh "cc -o hello #{OBJ}" # File depencies go here... file 'main.o' => ['main.c', 'greet.h'] file 'greet.o' => ['greet.c']

Ruby On Rails

Rails Full stack web framework MVC baseret Opinionated Convention over configuration Open Source

Model - View - Controller 1 Controller 3 2 4 View Model DB

Rails MVC Routing Controller View Model DB

Rails MVC http://kimharding.com/kursus/index.html Routing Controller View Model DB

Rails MVC http://kimharding.com/kursus/index.html Routing KursusController.index() Controller View Model DB

Rails MVC http://kimharding.com/kursus/index.html Routing KursusController.index() Controller @kurser = Kursus.find(:all) View Model DB

Rails MVC http://kimharding.com/kursus/index.html Routing KursusController.index() Controller index.rhtml @kurser = Kursus.find(:all) View Model DB

Rails MVC http://kimharding.com/kursus/index.html Routing KursusController.index() Controller index.rhtml @kurser = Kursus.find(:all) View <h1>kurser</h1> <% @kurser.each do kursus %> <h2><%= @kursus.titel() %></h2> <%= @kursus.beskrivelse() %> <% %> Model DB

ActiveRecord The essence of an Active Record is a Domain Model in which the classes match very closely the record structure of an underlying database. Each Active Record is responsible for saving and loading to the database and also for any domain logic that acts on the data... The data structure of the Active Record should exactly match that of the database: one field in the class for each column in the table... Patterns of Enterprise Application Architecture Martin Fowler

Analyse model Brand title description logo_url 1 * ProductType title description image_url * Product title price * * Category title children parent

DB Design BRANDS id title description logo_url int varchar(80) varchar(512) varchar(256) PRODUCT_TYPES id title description image_url brand_id int varchar(80) varchar(512) varchar(256) int PRODUCTS id title price product_type_id int varchar(80) number(8,2) int CATEGORIES_PRODUCT_TYPES product_types_id category_id int int CATEGORIES id title parent_id int varchar(80) int

BRANDS id title description logo_url int varchar(80) varchar(512) varchar(256) PRODUCT_TYPES id title description image_url brand_id int varchar(80) varchar(512) varchar(256) int PRODUCTS id title price product_type_id int varchar(80) number(8,2) int class CreateBrands < ActiveRecord::Migration def self.up create_table CATEGORIES_PRODUCT_TYPES :brands do t t.column :title, product_types_id :string, int :null => false t.column :description, category_id int :text t.column :logo_url, :string def self.down drop_table :brands CATEGORIES id title parent_id int varchar(80) int

Brand title description logo_url 1 * ProductType title description image_url class Brand < ActiveRecord::Base has_many :product_types class ProductType < ActiveRecord::Base belongs_to :brand * Product title price * * Category title children parent

Brand title description logo_url 1 class ProductType < ActiveRecord::Base belongs_to :brand has_many :products, :depent => true * ProductType title description image_url * Product title price * * Category title children class Product < ActiveRecord::Base belongs_to :product_type parent

Brand title description logo_url 1 class ProductType < ActiveRecord::Base belongs_to :brand has_many :products has_and_belongs_to_many :categories * ProductType title description image_url * Product title price * * Category title children class Category < ActiveRecord::Base has_and_belongs_to_many :product_types parent

Brand title description logo_url 1 * ProductType title description image_url * Product title price * * Category title parent children class Category < ActiveRecord::Base has_and_belongs_to_many :product_types acts_as_tree :order => "title"

REST

Hvad er REST? Representational State Transfer is inted to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rered for their use. Dr. Roy Fielding Architectural Styles and the Design of Network-based Software Architectures

Principper Applikationstilstand og funktionalitet realiseres vha. ressourcer Enhver ressource kan adresseres vha. en URI Alle ressourcer benytter samme uniforme interface til at flytte tilstand mellem klient og ressource Veldefineret sæt af operationer Veldefineret sæt af content-typer En protokol som er Client/Server, Stateless & Cacheable

REST & HTTP HTTP benyttes ofte som fundament for REST Client/Server, Stateless & Cacheable Ressourcer identificeres af URLs Operationer er GET, PUT, POST, DELETE (TRACE, OPTIONS, HEAD) GET: hent ressource repræsentation PUT: opdater ressource POST: opret ny ressource DELETE: slet ressource

Eksempel Customer Order OrderLine Product

Eksempel Customer Order OrderLine Product /customers GET: list all customers POST: add new customers /customers/{id} GET: get customer details PUT: update customer DELETE: delete customer

Eksempel Customer Order /customers GET: list all customers POST: add new customers OrderLine Product /customers/{id} GET: get customer details PUT: update customer DELETE: delete customer /orders GET: list all orders POST: add new order /customers/{id}/orders GET: get order list /orders/{id} GET: get order details PUT: update order DELETE: cancel order

Rails Demo Blog app Baseret på REST RSS feed AJAX til kommentarer

Rails Demo Posting * Comment

Rails Demo Posting * Comment /postings GET: list all postings {HTML & RSS} POST: add new posting

Rails Demo Posting * Comment /postings GET: list all postings {HTML & RSS} POST: add new posting /postings/{id} GET: get post details PUT: update posting DELETE: remove posting

Rails Demo Posting * Comment /postings GET: list all postings {HTML & RSS} POST: add new posting /postings/{id}/comments GET: list all comments POST: add new comment /postings/{id} GET: get post details PUT: update posting DELETE: remove posting

Rails Demo Posting * Comment /postings GET: list all postings {HTML & RSS} POST: add new posting /postings/{id}/comments GET: list all comments POST: add new comment /postings/{id} GET: get post details PUT: update posting DELETE: remove posting /postings/{id}/comments/{id} GET: get comment details PUT: update comment DELETE: remove comment

From what I have seen so far, Rails is a hyper-productive agile environment that EVERYONE should be taking very seriously. It seems to me that a Rails team could leave a Java or.net team in the dust by a factor of five or so. I know the rebuttal to that will be the dreaded "E" word. My response to that is: "It's OK with me if you want to go slow, just get out of the way while the rest of us get stuff done." Bob Martin

Ruby & RoR

Kim Harding Design Aps Kurser i.net, Java, Ruby, Modellering, Arkitektur Mentoring & Reviews Kontakt: khc@kimharding.com Tlf: 20929761