domain specific languages in ruby - medellin.rb

17
Medellín.rb @RubyMedellin http://medellinrb.org

Upload: oscar-rendon

Post on 14-Aug-2015

94 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Domain Specific Languages in Ruby - Medellin.rb

Medellín.rb

@RubyMedellinhttp://medellinrb.org

Page 2: Domain Specific Languages in Ruby - Medellin.rb

Schedule

- Say Hi- Domain-Specific Language’s in Ruby- Yummy yummy- Code Kata

@RubyMedellinhttp://medellinrb.org

Page 3: Domain Specific Languages in Ruby - Medellin.rb

Domain-Specific LanguageA domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains, and lacks specialized features for a particular domain.

http://en.wikipedia.org/wiki/Domain-specific_language

Page 4: Domain Specific Languages in Ruby - Medellin.rb

Domain-Specific LanguageA domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains, and lacks specialized features for a particular domain.

http://en.wikipedia.org/wiki/Domain-specific_language

Page 5: Domain Specific Languages in Ruby - Medellin.rb

Mini-Language’s

Page 6: Domain Specific Languages in Ruby - Medellin.rb

Mini-Language’s

Page 7: Domain Specific Languages in Ruby - Medellin.rb

RSpecdescribe 'dashboard statistics panel' do

context 'when logged in' do it { is_expected.to respond_with 200 } end context 'when logged out' do it { is_expected.to respond_with 401 } end

end

Page 8: Domain Specific Languages in Ruby - Medellin.rb

CucumberScenario: eat 5 out of 12

Given there are 12 cucumbers

When I eat 5 cucumbers

Then I should have 7 cucumbers

Scenario: eat 5 out of 20

Given there are 20 cucumbers

When I eat 5 cucumbers

Then I should have 15 cucumbers

Page 9: Domain Specific Languages in Ruby - Medellin.rb

Factory GirlFactoryGirl.define do

factory :user do

first_name "John"

last_name "Doe"

admin false

end

factory :admin, class: User do

first_name "Admin"

last_name "User"

admin true

end

end

Page 10: Domain Specific Languages in Ruby - Medellin.rb

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

Page 11: Domain Specific Languages in Ruby - Medellin.rb

ActionDispatch::RoutingRails.application.routes.draw do resources :productsend

Prefix Verb URI Pattern Controller#Action products GET /products(.:format) products#index

POST /products(.:format) products#create

new_product GET /products/new(.:format) products#new

edit_product GET /products/:id/edit(.:format) products#edit

product GET /products/:id(.:format) products#show

PATCH /products/:id(.:format) products#update

PUT /products/:id(.:format) products#update

DELETE /products/:id(.:format) products#destroy

Page 12: Domain Specific Languages in Ruby - Medellin.rb

DEMO

Code will be uploaded to: https://github.com/medellinrb/ruby_dsl

Page 13: Domain Specific Languages in Ruby - Medellin.rb

Yummy yummy

Page 14: Domain Specific Languages in Ruby - Medellin.rb

Code Kata

Page 15: Domain Specific Languages in Ruby - Medellin.rb

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

Page 16: Domain Specific Languages in Ruby - Medellin.rb

Today’s Katamarkup = FancyMarkup.new

markup.document do

body do

div id: ‘container’, class: ‘kool’ do

list class: ‘pretty’ do

item “item 1”

item “item 2”

end

end

end

end

markup.to_html

“<html>

<body>

<div id=”container”>

<ul class=”pretty”>

<li>item 1</li>

<li>item 2</li>

</ul>

</div>

</body>

</html>”

Fork https://github.com/medellinrb/ruby_dsl and submit your solutions

Page 17: Domain Specific Languages in Ruby - Medellin.rb

Thanks <3

Medellín.rb

@RubyMedellinhttp://medellinrb.org