SlideShare une entreprise Scribd logo
1  sur  47
Télécharger pour lire hors ligne
With	
  a	
  Mighty	
  Hammer
bensco'ield	
  –	
  viget	
  labs
red	
  dirt	
  rubyconf
6	
  may	
  2010
Changes
Model
[rails2] > ./script/generate model Viking name:string
      exists app/models/
      exists test/unit/
      exists test/fixtures/
      create app/models/viking.rb
      create test/unit/viking_test.rb
      create test/fixtures/vikings.yml
      exists db/migrate
      create db/migrate/20100505095300_create_vikings.rb
[rails3] > rails g model Viking name:string
      invoke active_record
      create    db/migrate/20100505095405_create_vikings.rb
      create    app/models/viking.rb
      invoke    test_unit
      create      test/unit/viking_test.rb
      create      test/fixtures/vikings.yml
[rails3] > rails g model Viking name:string
      invoke active_record
      create    db/migrate/20100505095405_create_vikings.rb
      create    app/models/viking.rb
      invoke    test_unit
      create      test/unit/viking_test.rb
      create      test/fixtures/vikings.yml
Controller
[rails2] > ./script/generate controller Vikings new create
      exists app/controllers/
      exists app/helpers/
      create app/views/vikings
      exists test/functional/
      exists test/unit/helpers/
      create app/controllers/vikings_controller.rb
      create test/functional/vikings_controller_test.rb
      create app/helpers/vikings_helper.rb
      create test/unit/helpers/vikings_helper_test.rb
      create app/views/vikings/new.html.erb
      create app/views/vikings/create.html.erb
[rails3] > rails g controller Vikings new create
      create app/controllers/vikings_controller.rb
       route get "vikings/create"
       route get "vikings/new"
      invoke erb
      create    app/views/vikings
      create    app/views/vikings/new.html.erb
      create    app/views/vikings/create.html.erb
      invoke test_unit
      create    test/functional/vikings_controller_test.rb
      invoke helper
      create    app/helpers/vikings_helper.rb
      invoke    test_unit
      create      test/unit/helpers/vikings_helper_test.rb
[rails3] > rails g controller Vikings new create
      create app/controllers/vikings_controller.rb
       route get "vikings/create"
       route get "vikings/new"
      invoke erb
      create    app/views/vikings
      create    app/views/vikings/new.html.erb
      create    app/views/vikings/create.html.erb
      invoke test_unit
      create    test/functional/vikings_controller_test.rb
      invoke helper
      create    app/helpers/vikings_helper.rb
      invoke    test_unit
      create      test/unit/helpers/vikings_helper_test.rb
Resource
[rails2] > ./script/generate resource Viking name:string
      exists app/models/
      exists app/controllers/
      exists app/helpers/
      create app/views/vikings
      exists test/functional/
      exists test/unit/
      exists test/unit/helpers/
  dependency model
      exists    app/models/
      exists    test/unit/
      exists    test/fixtures/
      create    app/models/viking.rb
      create    test/unit/viking_test.rb
      create    test/fixtures/vikings.yml
      exists    db/migrate
      create    db/migrate/20100505095850_create_vikings.rb
      create app/controllers/vikings_controller.rb
      create test/functional/vikings_controller_test.rb
      create app/helpers/vikings_helper.rb
      create test/unit/helpers/vikings_helper_test.rb
       route map.resources :vikings
[rails3] > rails g resource Viking name:string
      invoke active_record
      create    db/migrate/20100505095729_create_vikings.rb
      create    app/models/viking.rb
      invoke    test_unit
      create      test/unit/viking_test.rb
      create      test/fixtures/vikings.yml
      invoke controller
      create    app/controllers/vikings_controller.rb
      invoke    erb
      create      app/views/vikings
      invoke    test_unit
      create      test/functional/vikings_controller_test.rb
      invoke    helper
      create      app/helpers/vikings_helper.rb
      invoke      test_unit
      create        test/unit/helpers/vikings_helper_test.rb
       route resources :vikings
[rails3] > rails g resource Viking name:string
      invoke active_record
      create    db/migrate/20100505095729_create_vikings.rb
      create    app/models/viking.rb
      invoke    test_unit
      create      test/unit/viking_test.rb
      create      test/fixtures/vikings.yml
      invoke controller
      create    app/controllers/vikings_controller.rb
      invoke    erb
      create      app/views/vikings
      invoke    test_unit
      create      test/functional/vikings_controller_test.rb
      invoke    helper
      create      app/helpers/vikings_helper.rb
      invoke      test_unit
      create        test/unit/helpers/vikings_helper_test.rb
       route resources :vikings
Options
[rails2] > ./script/generate model
Options:
         --skip-timestamps
         --skip-migration
         --skip-fixture

Rails Info:
    -v, --version
    -h, --help

General   Options:
    -p,   --pretend
    -f,   --force
    -s,   --skip
    -q,   --quiet
    -t,   --backtrace
    -c,   --svn
    -g,   --git
[rails3] > rails g model
Options:
  -o, --orm=NAME

Runtime options:
  -q, [--quiet]
  -p, [--pretend]
  -f, [--force]
  -s, [--skip]

TestUnit options:
      [--fixture]
  -r, [--fixture-replacement=NAME]

ActiveRecord options:
      [--migration]
      [--parent=PARENT]
      [--timestamps]
  -t, [--test-framework=NAME]
Additions
[rails3] > rails g model
Options:
  -o, --orm=NAME

Runtime options:
  -q, [--quiet]
  -p, [--pretend]
  -f, [--force]
  -s, [--skip]

TestUnit options:
      [--fixture]
  -r, [--fixture-replacement=NAME]

ActiveRecord options:
      [--migration]
      [--parent=PARENT]
      [--timestamps]
  -t, [--test-framework=NAME]
[rails3] > rails g resource
Options:
      [--singleton]
  -c, --resource-controller=NAME
  -o, --orm=NAME
  -a, [--actions=ACTION ACTION]
      [--force-plural]

Runtime options:
  ...

TestUnit options:
  ...

ActiveRecord options:
  ...

Controller options:
  -e, [--template-engine=NAME]
      [--helper]
  -t, [--test-framework=NAME]
Hooks
[rails3] > rails g model
Options:
  -o, --orm=NAME

Runtime options:
  ...

TestUnit options:
      [--fixture]
  -r, [--fixture-replacement=NAME]

ActiveRecord options:
      [--migration]
      [--parent=PARENT]
      [--timestamps]
  -t, [--test-framework=NAME]
[rails3] > rails g resource
Options:
      [--singleton]
  -c, --resource-controller=NAME
  -o, --orm=NAME
  -a, [--actions=ACTION ACTION]
      [--force-plural]

Runtime options:
  ...

TestUnit options:
  ...

ActiveRecord options:
  ...

Controller options:
  -e, [--template-engine=NAME]
      [--helper]
  -t, [--test-framework=NAME]
Replacements
On	
  the	
  Fly
[rails3] > rails g model Ninja name:string -o mongo_mapper

[rails3] > rails g model Ninja name:string -t shoulda

[rails3] > rails g model Ninja name:string -r factory_girl
[rails3] > rails g model Ninja name:string -o mongo_mapper
       error mongo_mapper [not found]

[rails3] > rails g model Ninja name:string -t shoulda
      invoke active_record
      create    db/migrate/20100505102902_create_ninjas.rb
      create    app/models/ninja.rb
       error    shoulda [not found]

[rails3] > rails g model Ninja name:string -r factory_girl
      invoke active_record
      create    db/migrate/20100505102902_create_ninjas.rb
      create    app/models/ninja.rb
      invoke    test_unit
      create      test/unit/ninja_test.rb
       error      factory_girl [not found]
[rails3] > rails g generator FactoryGirl
    create lib/generators/factory_girl
    create lib/generators/factory_girl/factory_girl_generator.rb
    create lib/generators/factory_girl/USAGE




                           O
    create lib/generators/factory_girl/templates




                         N
module FactoryGirl
  class ModelGenerator < Rails::Generators::NamedBase
    argument :attributes, :type => :array, :default => [],
             :banner => "field:type field:type"

    def create_fixture_file
      template 'factory.rb',
        File.join('test', 'factories', "#{singular_name}.rb")
    end

    def self.source_root
      @source_root ||= File.expand_path('../templates', __FILE__)
    end
  end
end
Factory.define :<%= singular_name %> do |f|
<% attributes.each do |attribute| -%>
<% if attribute.type == :references -%>
  f.association :<%= attribute.name %>
<% else -%>
  f.<%= attribute.name %> <%= attribute.default.inspect %>
<% end -%>
<% end -%>
end
[rails3] > rails g model Ninja name:string clan:references
           -r factory_girl
      invoke active_record
      create    db/migrate/20100505102902_create_ninjas.rb
      create    app/models/ninja.rb
      invoke    test_unit
      create      test/unit/ninja_test.rb
      invoke      factory_girl
      create        test/factories/ninja.rb
Factory.define :ninja do |f|
  f.name "MyString"
  f.association :clan
end
Changing	
  the	
  Default
module TestApp
  class Application < Rails::Application
    config.generators do |g|
      g.test_framework :test_unit,
                        :fixture_replacement => :factory_girl
    end
  end
end
[rails3] > rails g model Ninja name:string clan:references
      invoke active_record
      create    db/migrate/20100505102902_create_ninjas.rb
      create    app/models/ninja.rb
      invoke    test_unit
      create      test/unit/ninja_test.rb
      invoke      factory_girl
      create        test/factories/ninja.rb
Hooking
Typus
[rails3] > rails g resource Cowboy name:string
      invoke active_record
      create    db/migrate/20100506031815_create_cowboys.rb
      create    app/models/cowboy.rb
      invoke    test_unit
      create      test/unit/cowboy_test.rb
      invoke      factory_girl
      create        test/factories/cowboy.rb
      invoke controller
      create    app/controllers/cowboys_controller.rb
      invoke    erb
      create      app/views/cowboys
      invoke    test_unit
      create      test/functional/cowboys_controller_test.rb
      invoke    helper
      create      app/helpers/cowboys_helper.rb
      invoke      test_unit
      create        test/unit/helpers/cowboys_helper_test.rb
       route resources :cowboys
[rails3] > rails g resource Cowboy name:string
      invoke active_record
      create    db/migrate/20100506031815_create_cowboys.rb
      create    app/models/cowboy.rb
      invoke    test_unit
      create      test/unit/cowboy_test.rb
      invoke      factory_girl
      create        test/factories/cowboy.rb
      invoke controller
      create    app/controllers/cowboys_controller.rb
      invoke    erb
      create      app/views/cowboys
      invoke    test_unit
      create      test/functional/cowboys_controller_test.rb
      invoke    helper
      create      app/helpers/cowboys_helper.rb
      invoke      test_unit
      create        test/unit/helpers/cowboys_helper_test.rb
       route resources :cowboys
module Typus
  class ResourceGenerator < Rails::Generators::NamedBase
    def initialize(args, *options) #:nodoc:
      args[0] = args[0].dup if args[0].is_a?(String) &&
                               args[0].frozen?
      args[0] = "Admin::#{args[0]}"

     super
   end

   def create_controller
     template 'typus_controller.rb',
              File.join('app', 'controllers', class_path,
                        "#{file_name}_controller.rb")
   end

    hook_for :template_engine, :as => :controller
    hook_for :test_framework, :as => :controller

   # continued ...
# continued ...

    hook_for(:controller,
             :as => :controller,
             :in => :rails) do |instance, controller|
      instance.instance_eval do
        @_invocations.delete(Erb::Generators::ControllerGener...)
        @_invocations.delete(TestUnit::Generators::Controller...)
      end

      instance.invoke controller, [instance.name.demodulize]
    end

    def self.source_root
      @source_root ||= File.expand_path('../templates', __FILE__)
    end
  end
end
module TestApp
  class Application < Rails::Application
    config.generators do |g|
      g.resource_controller :typus, :controller => :controller
    end
  end
end
[rails3] > rails g resource Cowboy name:string
      invoke active_record
      create    db/migrate/20100505231238_create_cowboys.rb
      create    app/models/cowboy.rb
      invoke    test_unit
      create      test/unit/cowboy_test.rb
      invoke      factory_girl
      create        test/factories/cowboy.rb
      invoke typus
      create    app/controllers/admin/cowboys_controller.rb
      invoke    erb
      create      app/views/admin/cowboys
      invoke    test_unit
      create      test/functional/admin/cowboys_controller_test.rb
      invoke    controller
      create      app/controllers/cowboys_controller.rb
      invoke      erb
      create        app/views/cowboys
      invoke      test_unit
      create        test/functional/cowboys_controller_test.rb
      invoke      helper
      create        app/helpers/cowboys_helper.rb
      invoke        test_unit
      create          test/unit/helpers/cowboys_helper_test.rb
       route resources :cowboys
bensco'ield
@bsco'ield
ben.sco'ield@viget.com
http:/    /spkr8.com/bsco'ield
http:/    /viget.com/extend
http:	
   /bensco'ield.com
     /

Contenu connexe

Tendances

Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-Framework
Vance Lucas
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみた
memememomo
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
Kris Wallsmith
 

Tendances (20)

Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 
Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-Framework
 
Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Elegant APIs
Elegant APIsElegant APIs
Elegant APIs
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
Plugin jQuery, Design Patterns
Plugin jQuery, Design PatternsPlugin jQuery, Design Patterns
Plugin jQuery, Design Patterns
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみた
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 

En vedette

D E V E L O P M E N T A L P S Y C H O L O G Y A N D L E A R N I N G I B...
D E V E L O P M E N T A L  P S Y C H O L O G Y  A N D  L E A R N I N G   I  B...D E V E L O P M E N T A L  P S Y C H O L O G Y  A N D  L E A R N I N G   I  B...
D E V E L O P M E N T A L P S Y C H O L O G Y A N D L E A R N I N G I B...
Universidad Técnica Particular de Loja
 
Social media pentru companii - mituri si explicatii
Social media pentru companii - mituri si explicatiiSocial media pentru companii - mituri si explicatii
Social media pentru companii - mituri si explicatii
Marius Sescu
 

En vedette (13)

Mind Control - DevNation Atlanta
Mind Control - DevNation AtlantaMind Control - DevNation Atlanta
Mind Control - DevNation Atlanta
 
Understanding Mastery
Understanding MasteryUnderstanding Mastery
Understanding Mastery
 
D E V E L O P M E N T A L P S Y C H O L O G Y A N D L E A R N I N G I B...
D E V E L O P M E N T A L  P S Y C H O L O G Y  A N D  L E A R N I N G   I  B...D E V E L O P M E N T A L  P S Y C H O L O G Y  A N D  L E A R N I N G   I  B...
D E V E L O P M E N T A L P S Y C H O L O G Y A N D L E A R N I N G I B...
 
The Future of Data
The Future of DataThe Future of Data
The Future of Data
 
Charlotte.rb - "Comics" Is Hard
Charlotte.rb - "Comics" Is HardCharlotte.rb - "Comics" Is Hard
Charlotte.rb - "Comics" Is Hard
 
Marketer Bun Sau Extraordinar
Marketer Bun Sau ExtraordinarMarketer Bun Sau Extraordinar
Marketer Bun Sau Extraordinar
 
Open Source: A Call to Arms
Open Source: A Call to ArmsOpen Source: A Call to Arms
Open Source: A Call to Arms
 
Mastery or Mediocrity
Mastery or MediocrityMastery or Mediocrity
Mastery or Mediocrity
 
Social media pentru companii - mituri si explicatii
Social media pentru companii - mituri si explicatiiSocial media pentru companii - mituri si explicatii
Social media pentru companii - mituri si explicatii
 
Thinking Small
Thinking SmallThinking Small
Thinking Small
 
Ship It
Ship ItShip It
Ship It
 
How to Be Awesome in 2.5 Steps
How to Be Awesome in 2.5 StepsHow to Be Awesome in 2.5 Steps
How to Be Awesome in 2.5 Steps
 
Intentionality: Choice and Mastery
Intentionality: Choice and MasteryIntentionality: Choice and Mastery
Intentionality: Choice and Mastery
 

Similaire à With a Mighty Hammer

Innovation and Security in Ruby on Rails
Innovation and Security in Ruby on RailsInnovation and Security in Ruby on Rails
Innovation and Security in Ruby on Rails
tielefeld
 
前瞻性Web性能优化pwpo
前瞻性Web性能优化pwpo前瞻性Web性能优化pwpo
前瞻性Web性能优化pwpo
Michael Zhang
 

Similaire à With a Mighty Hammer (20)

Generators
GeneratorsGenerators
Generators
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the Cloud
 
Maven part 3
Maven part 3Maven part 3
Maven part 3
 
Building and managing java projects with maven part-III
Building and managing java projects with maven part-IIIBuilding and managing java projects with maven part-III
Building and managing java projects with maven part-III
 
Maven iii
Maven iiiMaven iii
Maven iii
 
Maven iii
Maven iiiMaven iii
Maven iii
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
 
Innovation and Security in Ruby on Rails
Innovation and Security in Ruby on RailsInnovation and Security in Ruby on Rails
Innovation and Security in Ruby on Rails
 
Redmine Betabeers SVQ
Redmine Betabeers SVQRedmine Betabeers SVQ
Redmine Betabeers SVQ
 
What's new in Django 1.2?
What's new in Django 1.2?What's new in Django 1.2?
What's new in Django 1.2?
 
Crafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in RubyCrafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in Ruby
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
前瞻性Web性能优化pwpo
前瞻性Web性能优化pwpo前瞻性Web性能优化pwpo
前瞻性Web性能优化pwpo
 
Writing your Third Plugin
Writing your Third PluginWriting your Third Plugin
Writing your Third Plugin
 
Kubernetes walkthrough
Kubernetes walkthroughKubernetes walkthrough
Kubernetes walkthrough
 
Django tricks (2)
Django tricks (2)Django tricks (2)
Django tricks (2)
 
Tdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema RubyTdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema Ruby
 
What's new in Rails 4
What's new in Rails 4What's new in Rails 4
What's new in Rails 4
 
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
 

Plus de Ben Scofield

"Comics" Is Hard: Domain Modeling Challenges
"Comics" Is Hard: Domain Modeling Challenges"Comics" Is Hard: Domain Modeling Challenges
"Comics" Is Hard: Domain Modeling Challenges
Ben Scofield
 

Plus de Ben Scofield (17)

Mind Control: Psychology for the Web
Mind Control: Psychology for the WebMind Control: Psychology for the Web
Mind Control: Psychology for the Web
 
The State of NoSQL
The State of NoSQLThe State of NoSQL
The State of NoSQL
 
NoSQL @ CodeMash 2010
NoSQL @ CodeMash 2010NoSQL @ CodeMash 2010
NoSQL @ CodeMash 2010
 
NoSQL: Death to Relational Databases(?)
NoSQL: Death to Relational Databases(?)NoSQL: Death to Relational Databases(?)
NoSQL: Death to Relational Databases(?)
 
WindyCityRails - "Comics" Is Hard
WindyCityRails - "Comics" Is HardWindyCityRails - "Comics" Is Hard
WindyCityRails - "Comics" Is Hard
 
"Comics" Is Hard: Alternative Databases
"Comics" Is Hard: Alternative Databases"Comics" Is Hard: Alternative Databases
"Comics" Is Hard: Alternative Databases
 
Mind Control on the Web
Mind Control on the WebMind Control on the Web
Mind Control on the Web
 
How the Geeks Inherited the Earth
How the Geeks Inherited the EarthHow the Geeks Inherited the Earth
How the Geeks Inherited the Earth
 
And the Greatest of These Is ... Space
And the Greatest of These Is ... SpaceAnd the Greatest of These Is ... Space
And the Greatest of These Is ... Space
 
"Comics" Is Hard: Domain Modeling Challenges
"Comics" Is Hard: Domain Modeling Challenges"Comics" Is Hard: Domain Modeling Challenges
"Comics" Is Hard: Domain Modeling Challenges
 
And the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack SupportAnd the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack Support
 
Page Caching Resurrected
Page Caching ResurrectedPage Caching Resurrected
Page Caching Resurrected
 
Page Caching Resurrected: A Fairy Tale
Page Caching Resurrected: A Fairy TalePage Caching Resurrected: A Fairy Tale
Page Caching Resurrected: A Fairy Tale
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web Framework
 
Advanced Restful Rails - Europe
Advanced Restful Rails - EuropeAdvanced Restful Rails - Europe
Advanced Restful Rails - Europe
 
Resourceful Plugins
Resourceful PluginsResourceful Plugins
Resourceful Plugins
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

With a Mighty Hammer

  • 1. With  a  Mighty  Hammer bensco'ield  –  viget  labs red  dirt  rubyconf 6  may  2010
  • 4. [rails2] > ./script/generate model Viking name:string exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/viking.rb create test/unit/viking_test.rb create test/fixtures/vikings.yml exists db/migrate create db/migrate/20100505095300_create_vikings.rb
  • 5. [rails3] > rails g model Viking name:string invoke active_record create db/migrate/20100505095405_create_vikings.rb create app/models/viking.rb invoke test_unit create test/unit/viking_test.rb create test/fixtures/vikings.yml
  • 6. [rails3] > rails g model Viking name:string invoke active_record create db/migrate/20100505095405_create_vikings.rb create app/models/viking.rb invoke test_unit create test/unit/viking_test.rb create test/fixtures/vikings.yml
  • 8. [rails2] > ./script/generate controller Vikings new create exists app/controllers/ exists app/helpers/ create app/views/vikings exists test/functional/ exists test/unit/helpers/ create app/controllers/vikings_controller.rb create test/functional/vikings_controller_test.rb create app/helpers/vikings_helper.rb create test/unit/helpers/vikings_helper_test.rb create app/views/vikings/new.html.erb create app/views/vikings/create.html.erb
  • 9. [rails3] > rails g controller Vikings new create create app/controllers/vikings_controller.rb route get "vikings/create" route get "vikings/new" invoke erb create app/views/vikings create app/views/vikings/new.html.erb create app/views/vikings/create.html.erb invoke test_unit create test/functional/vikings_controller_test.rb invoke helper create app/helpers/vikings_helper.rb invoke test_unit create test/unit/helpers/vikings_helper_test.rb
  • 10. [rails3] > rails g controller Vikings new create create app/controllers/vikings_controller.rb route get "vikings/create" route get "vikings/new" invoke erb create app/views/vikings create app/views/vikings/new.html.erb create app/views/vikings/create.html.erb invoke test_unit create test/functional/vikings_controller_test.rb invoke helper create app/helpers/vikings_helper.rb invoke test_unit create test/unit/helpers/vikings_helper_test.rb
  • 12. [rails2] > ./script/generate resource Viking name:string exists app/models/ exists app/controllers/ exists app/helpers/ create app/views/vikings exists test/functional/ exists test/unit/ exists test/unit/helpers/ dependency model exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/viking.rb create test/unit/viking_test.rb create test/fixtures/vikings.yml exists db/migrate create db/migrate/20100505095850_create_vikings.rb create app/controllers/vikings_controller.rb create test/functional/vikings_controller_test.rb create app/helpers/vikings_helper.rb create test/unit/helpers/vikings_helper_test.rb route map.resources :vikings
  • 13. [rails3] > rails g resource Viking name:string invoke active_record create db/migrate/20100505095729_create_vikings.rb create app/models/viking.rb invoke test_unit create test/unit/viking_test.rb create test/fixtures/vikings.yml invoke controller create app/controllers/vikings_controller.rb invoke erb create app/views/vikings invoke test_unit create test/functional/vikings_controller_test.rb invoke helper create app/helpers/vikings_helper.rb invoke test_unit create test/unit/helpers/vikings_helper_test.rb route resources :vikings
  • 14. [rails3] > rails g resource Viking name:string invoke active_record create db/migrate/20100505095729_create_vikings.rb create app/models/viking.rb invoke test_unit create test/unit/viking_test.rb create test/fixtures/vikings.yml invoke controller create app/controllers/vikings_controller.rb invoke erb create app/views/vikings invoke test_unit create test/functional/vikings_controller_test.rb invoke helper create app/helpers/vikings_helper.rb invoke test_unit create test/unit/helpers/vikings_helper_test.rb route resources :vikings
  • 16. [rails2] > ./script/generate model Options: --skip-timestamps --skip-migration --skip-fixture Rails Info: -v, --version -h, --help General Options: -p, --pretend -f, --force -s, --skip -q, --quiet -t, --backtrace -c, --svn -g, --git
  • 17. [rails3] > rails g model Options: -o, --orm=NAME Runtime options: -q, [--quiet] -p, [--pretend] -f, [--force] -s, [--skip] TestUnit options: [--fixture] -r, [--fixture-replacement=NAME] ActiveRecord options: [--migration] [--parent=PARENT] [--timestamps] -t, [--test-framework=NAME]
  • 19. [rails3] > rails g model Options: -o, --orm=NAME Runtime options: -q, [--quiet] -p, [--pretend] -f, [--force] -s, [--skip] TestUnit options: [--fixture] -r, [--fixture-replacement=NAME] ActiveRecord options: [--migration] [--parent=PARENT] [--timestamps] -t, [--test-framework=NAME]
  • 20. [rails3] > rails g resource Options: [--singleton] -c, --resource-controller=NAME -o, --orm=NAME -a, [--actions=ACTION ACTION] [--force-plural] Runtime options: ... TestUnit options: ... ActiveRecord options: ... Controller options: -e, [--template-engine=NAME] [--helper] -t, [--test-framework=NAME]
  • 21. Hooks
  • 22. [rails3] > rails g model Options: -o, --orm=NAME Runtime options: ... TestUnit options: [--fixture] -r, [--fixture-replacement=NAME] ActiveRecord options: [--migration] [--parent=PARENT] [--timestamps] -t, [--test-framework=NAME]
  • 23. [rails3] > rails g resource Options: [--singleton] -c, --resource-controller=NAME -o, --orm=NAME -a, [--actions=ACTION ACTION] [--force-plural] Runtime options: ... TestUnit options: ... ActiveRecord options: ... Controller options: -e, [--template-engine=NAME] [--helper] -t, [--test-framework=NAME]
  • 26. [rails3] > rails g model Ninja name:string -o mongo_mapper [rails3] > rails g model Ninja name:string -t shoulda [rails3] > rails g model Ninja name:string -r factory_girl
  • 27. [rails3] > rails g model Ninja name:string -o mongo_mapper error mongo_mapper [not found] [rails3] > rails g model Ninja name:string -t shoulda invoke active_record create db/migrate/20100505102902_create_ninjas.rb create app/models/ninja.rb error shoulda [not found] [rails3] > rails g model Ninja name:string -r factory_girl invoke active_record create db/migrate/20100505102902_create_ninjas.rb create app/models/ninja.rb invoke test_unit create test/unit/ninja_test.rb error factory_girl [not found]
  • 28. [rails3] > rails g generator FactoryGirl create lib/generators/factory_girl create lib/generators/factory_girl/factory_girl_generator.rb create lib/generators/factory_girl/USAGE O create lib/generators/factory_girl/templates N
  • 29.
  • 30. module FactoryGirl class ModelGenerator < Rails::Generators::NamedBase argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" def create_fixture_file template 'factory.rb', File.join('test', 'factories', "#{singular_name}.rb") end def self.source_root @source_root ||= File.expand_path('../templates', __FILE__) end end end
  • 31. Factory.define :<%= singular_name %> do |f| <% attributes.each do |attribute| -%> <% if attribute.type == :references -%> f.association :<%= attribute.name %> <% else -%> f.<%= attribute.name %> <%= attribute.default.inspect %> <% end -%> <% end -%> end
  • 32. [rails3] > rails g model Ninja name:string clan:references -r factory_girl invoke active_record create db/migrate/20100505102902_create_ninjas.rb create app/models/ninja.rb invoke test_unit create test/unit/ninja_test.rb invoke factory_girl create test/factories/ninja.rb
  • 33. Factory.define :ninja do |f| f.name "MyString" f.association :clan end
  • 35. module TestApp class Application < Rails::Application config.generators do |g| g.test_framework :test_unit, :fixture_replacement => :factory_girl end end end
  • 36. [rails3] > rails g model Ninja name:string clan:references invoke active_record create db/migrate/20100505102902_create_ninjas.rb create app/models/ninja.rb invoke test_unit create test/unit/ninja_test.rb invoke factory_girl create test/factories/ninja.rb
  • 38. Typus
  • 39.
  • 40. [rails3] > rails g resource Cowboy name:string invoke active_record create db/migrate/20100506031815_create_cowboys.rb create app/models/cowboy.rb invoke test_unit create test/unit/cowboy_test.rb invoke factory_girl create test/factories/cowboy.rb invoke controller create app/controllers/cowboys_controller.rb invoke erb create app/views/cowboys invoke test_unit create test/functional/cowboys_controller_test.rb invoke helper create app/helpers/cowboys_helper.rb invoke test_unit create test/unit/helpers/cowboys_helper_test.rb route resources :cowboys
  • 41. [rails3] > rails g resource Cowboy name:string invoke active_record create db/migrate/20100506031815_create_cowboys.rb create app/models/cowboy.rb invoke test_unit create test/unit/cowboy_test.rb invoke factory_girl create test/factories/cowboy.rb invoke controller create app/controllers/cowboys_controller.rb invoke erb create app/views/cowboys invoke test_unit create test/functional/cowboys_controller_test.rb invoke helper create app/helpers/cowboys_helper.rb invoke test_unit create test/unit/helpers/cowboys_helper_test.rb route resources :cowboys
  • 42. module Typus class ResourceGenerator < Rails::Generators::NamedBase def initialize(args, *options) #:nodoc: args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen? args[0] = "Admin::#{args[0]}" super end def create_controller template 'typus_controller.rb', File.join('app', 'controllers', class_path, "#{file_name}_controller.rb") end hook_for :template_engine, :as => :controller hook_for :test_framework, :as => :controller # continued ...
  • 43. # continued ... hook_for(:controller, :as => :controller, :in => :rails) do |instance, controller| instance.instance_eval do @_invocations.delete(Erb::Generators::ControllerGener...) @_invocations.delete(TestUnit::Generators::Controller...) end instance.invoke controller, [instance.name.demodulize] end def self.source_root @source_root ||= File.expand_path('../templates', __FILE__) end end end
  • 44. module TestApp class Application < Rails::Application config.generators do |g| g.resource_controller :typus, :controller => :controller end end end
  • 45. [rails3] > rails g resource Cowboy name:string invoke active_record create db/migrate/20100505231238_create_cowboys.rb create app/models/cowboy.rb invoke test_unit create test/unit/cowboy_test.rb invoke factory_girl create test/factories/cowboy.rb invoke typus create app/controllers/admin/cowboys_controller.rb invoke erb create app/views/admin/cowboys invoke test_unit create test/functional/admin/cowboys_controller_test.rb invoke controller create app/controllers/cowboys_controller.rb invoke erb create app/views/cowboys invoke test_unit create test/functional/cowboys_controller_test.rb invoke helper create app/helpers/cowboys_helper.rb invoke test_unit create test/unit/helpers/cowboys_helper_test.rb route resources :cowboys
  • 46.
  • 47. bensco'ield @bsco'ield ben.sco'ield@viget.com http:/ /spkr8.com/bsco'ield http:/ /viget.com/extend http:   /bensco'ield.com /