ro r trilogy-part-1

39
Amir Barylko RoR Trilogy Part I: A New Dev Hope AMIR BARYLKO THE ROR TRILOGY A NEW DEV HOPE

Upload: sdeconf

Post on 31-Oct-2014

476 views

Category:

Technology


0 download

DESCRIPTION

The Ruby on Rails Trilogy - a new Dev hope

TRANSCRIPT

Page 1: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

AMIR BARYLKO

THE ROR TRILOGYA NEW DEV HOPE

Page 2: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

WHO AM I?

• Software quality expert

• Architect

•Developer

•Mentor

• Great cook

• The one who’s entertaining you for the next hour!

Page 3: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

RESOURCES

• Email & Twitter : [email protected], @abarylko

• Slides: http://www.orthocoders.com/presentations

• Company Site: http://www.maventhought.com

• Try Ruby online: http://tryruby.org/

• Learn RoR online: http://railsforzombies.org/

Page 4: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

RUBY INTRODynamic languages

FeaturesSupportClassesMixins

Page 5: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

DYNAMIC LANGUAGES

• High level

•Dynamically typed

• Runtime over compile time

• Closures

• Reflection

• Platform independent

Page 6: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

WELCOME TO RUBY

• Created in mid-90s by “Matz” Matsumoto in Japan

• Smalltalk, Perl influences

•Dynamic typing

•Object Oriented

• Automatic memory management

• Several implementations: MRI, YARB, JRuby

• Totally free!!

Page 7: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

RUBY FEATURES

• Everything is an expression

•Metaprogramming

• Closures

• Garbage collection

• Exceptions

•Operator overloading, flexible syntax

Page 8: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

RUBY SUPPORT

• Hundreds of books

• User conferences all over the world

• Active community (you can create a conference in your own city and top Ruby coders will go there to teach others, invite them and see)

• Lots of great web sites: basecamp, twitter, 43 things, hulu, scribd, slideshare, Justin.tv

Page 9: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

CLASSES & OBJECTS

• Initializer and instance variablesclass Movie def initialize(name) @name = name end

def play puts %Q{Playing “#{@name}”. Enjoy!} endend

m = Movie.new(“Pulp fiction”)m.play

=> Playing “Pulp fiction”. Enjoy!

Page 10: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

CLASSES & OBJECTS II

• Attributesclass Movie # attr reader and writer attr_accesor :name

def initialize(name) @name = name endend

m = Movie.new('Brazil')m.name = “Pulp fiction”

Page 11: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

MIXINS

•One of the greatest Ruby features!

• You can define functions in Modules, and get them added to your classes.

• Great code reuse,

•Multiple inheritance alternative.

• Code organization

Page 12: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

ENUMERABLE MIXIN

•Quote from the standard library documentation:

...The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort.

The class must provide a method each, which yields successive members of the collection...

Page 13: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

ENUMERABLE II

• It provides useful methods such as:

•map

• to_a

• take_while

• count

• inject

Page 14: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

MIXIN EXAMPLE

class MovieLibrary include Enumerable

def each(&block) contents.each(&block) endend

Page 15: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

RORWhat is it?

Convention over configurationModel View Controller

Code generationDependency Management

HTML 5 & UJS

Page 16: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

WHAT IS ROR?

•Web application development framework

• Created by David Heinemeier Hansson

•With Rails, you would be done by now!

•Open Source & Multi platform

• Very easy to learn

• Comes with everything out of the box!

Page 17: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

CONVENTION OVER CONFIGURATION

• All applications share the same structure

• The application is generated by the rails command

• All the config files are ruby code

Page 18: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

MODEL VIEW CONTROLLER

•Model: represents the data

• Controllers: Manipulate the data and prepare it to be shown

• View: Shows the data with a particular view engine

Page 19: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

CODE GENERATION

• Using rails command:

•Bootstrap: Generates basic structure

•Models: Generated models and tests

•Controllers: Generates controllers, views and tests

• Scaffolds: Generates models, controllers, views, routes, etc...

Page 20: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

DEPENDENCY MANAGEMENT

• Gems are Ruby libraries

•Dependencies are managed with tool gem

• To install a gem just run: gem install xxxxxx

• Bundler is a gem to manage dependencies

• Just create a Gemfile and bundler will install all of them

Page 21: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

HTML 5 & UNOBTRUSIVE JS

• Supports HTML 5 standards

• data-remote, data-method, data-config, etc...

• Supports many JS frameworks

• JS code associated to models to handle events, animations, etc

• Coffeescript!

Page 22: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

ROR GOODNESSCommon Structure

Automation Migrations

ActiveRecordTesting

Scaffolding

Page 23: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

COMMON STRUCTURE

• app• assets: Stylesheets, javascript, images• controllers: Prepare the data for the views• helpers: Helper methods to render views• models: Represent our domain• views: Templates to be rendered• each controller has a folder with one template per method

• layouts:Base templates to surround the views

Page 24: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

AUTOMATION

• Rake is a build tool (similar to ant, msbuild, maven)

• Has tasks that can be configured

•Out of the box has common tasks for database, testing, etc..

• List all the tasks: rake -T

• Very useful to automate tasks and to use in CI servers

Page 25: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

MIGRATIONS

• Track the database changes using code

•No need to use SQL

• Upgrades are easy

• Versioning is kept in the database

• Generated automatically when creating models

Page 26: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

ACTIVE RECORD

• Relations (ActiveModel)

• Supports multiple databases

• Each table is a class

• All attributes are created dynamically

• Associations are declared by convention

• Each class has CRUD and query operations by default

Page 27: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

TESTING OUT OF THE BOX

•Many testing frameworks available

•No additional effort to generate them

• Running them is part of the Rakefile (automation)

• Keep high quality all the way

Page 28: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

SCAFFOLDING

• Generated automatically for CRUD operations

• Controllers

• Views

• Tests

• The template used can be replaced of modified

Page 29: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

MOVIE LIBRARYDemo

Page 30: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

TOPICS

• Rails application structure

•Database Migrations

• Using scaffolds

•Model - View - Controllers

• Routing

• Ajax

Page 31: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

MORE GOODNESS!HelpersPartials

Sass Routing

Page 32: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

HELPERS

•Methods to assist in the view generation

• Reusable

• Associated to each controller

• Testable

Page 33: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

PARTIALS

• Templates that can be shared

• Start with underscore “_”

• Can be rendered from views or controllers

Page 34: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

SASS

•Quote from sass-lang.com:

Sass is an extension of CSS3, adding n e s t e d r u l e s , v a r i a b l e s , mixins,selector inheritance, and more. It’s translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.

Page 35: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

ROUTING

• Easy to configure using routes.rb

• Supports REST out of the box

• Easy to restrict actions

• Easy to alias routes

• Allows optional parameters in the routes

Page 36: Ro r trilogy-part-1

QUESTIONS?

Page 37: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

RESOURCES

• Email & Twitter : [email protected], @abarylko

• Slides: http://www.orthocoders.com/presentations

• Company Site: http://www.maventhought.com

• Try Ruby online: http://tryruby.org/

• Learn RoR online: http://railsforzombies.org/

Page 38: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

RESOURCES II

Page 39: Ro r trilogy-part-1

Amir Barylko RoR Trilogy Part I: A New Dev Hope

CLOJURE TRAINING

•When: Nov 6, 7 & 8

•More info: http://www.maventhought.com

• Goal: Learn Clojure and functional programming with real hands on examples