active record internals - medellin.rb

15
Medellín.rb ActiveRecord Internals @RubyMedellin http://medellinrb.org

Upload: oscar-rendon

Post on 07-Aug-2015

84 views

Category:

Software


1 download

TRANSCRIPT

Medellín.rbActiveRecord Internals

@RubyMedellinhttp://medellinrb.org

Schedule

- Say Hi- Active Record Pattern- ActiveRecord (Rails)- Yummy yummy- Code Kata

@RubyMedellinhttp://medellinrb.org

PEAA

http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420

GoF

http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/

Ruby Patterns

http://www.amazon.com/Design-Patterns-Ruby-Russ-Olsen/dp/0321490452/

Active Record Pattern

An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data.

http://www.martinfowler.com/eaaCatalog/activeRecord.html

ActiveRecord (Rails)Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database. It is an implementation of the Active Record pattern which itself is a description of an Object Relational Mapping system.

http://guides.rubyonrails.org/active_record_basics.html

ActiveRecord (Rails)- ActiveModel- Migrations- Adapters- Validations- Callbacks- etc

http://guides.rubyonrails.org/active_record_basics.html

ActiveRecord (Rails)class Product < ActiveRecord::Base

# ...

end

Product.first

Product.where(name: ‘LCD TV’)

http://guides.rubyonrails.org

class CreateProducts < ActiveRecord::Migration def change create_table :products do |t| t.string :name t.text :description t.timestamps null: false end endend

DEMO

Code will be uploaded to: https://github.com/medellinrb/activerecord-internals

Yummy yummy

Code Kata

Code KataKata (型 or 形 literally: "form"?), a Japanese word, are the detailed choreographed patterns of movements practised either solo or in pairs.

A code kata is an exercise in programming which helps a programmer hone their skills through practice and repetition.

http://en.wikipedia.org/wiki/Kata_(programming) - http://en.wikipedia.org/wiki/Kata

Today’s KataImplement:

SomeModel.firstSomeModel.allSomeModel.countSomeModel.find_by_name(‘given name’)SomeModel.find_by_whateverattribute(‘xxx’)SomeModel.where(attr: ‘value’)Improve multiple DB adaptersImprove setup/teardown on tests

Thanks <3

Medellín.rb

@RubyMedellinhttp://medellinrb.org