SlideShare una empresa de Scribd logo
1 de 47
Descargar para leer sin conexión
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
     /

Más contenido relacionado

La actualidad más candente

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...Arc & Codementor
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkVance Lucas
 
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)andrewnacin
 
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 2017Ryan Weaver
 
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 RubyLaunchAny
 
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 othersYusuke Wada
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutVic Metcalfe
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientAdam Wiggins
 
Plugin jQuery, Design Patterns
Plugin jQuery, Design PatternsPlugin jQuery, Design Patterns
Plugin jQuery, Design PatternsRobert Casanova
 
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 FinishYehuda Katz
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Kris Wallsmith
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hopeMarcus Ramberg
 

La actualidad más candente (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
 

Destacado

Mind Control - DevNation Atlanta
Mind Control - DevNation AtlantaMind Control - DevNation Atlanta
Mind Control - DevNation AtlantaBen Scofield
 
Understanding Mastery
Understanding MasteryUnderstanding Mastery
Understanding MasteryBen Scofield
 
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
 
The Future of Data
The Future of DataThe Future of Data
The Future of DataBen Scofield
 
Charlotte.rb - "Comics" Is Hard
Charlotte.rb - "Comics" Is HardCharlotte.rb - "Comics" Is Hard
Charlotte.rb - "Comics" Is HardBen Scofield
 
Marketer Bun Sau Extraordinar
Marketer Bun Sau ExtraordinarMarketer Bun Sau Extraordinar
Marketer Bun Sau ExtraordinarMarius Sescu
 
Open Source: A Call to Arms
Open Source: A Call to ArmsOpen Source: A Call to Arms
Open Source: A Call to ArmsBen Scofield
 
Mastery or Mediocrity
Mastery or MediocrityMastery or Mediocrity
Mastery or MediocrityBen Scofield
 
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 explicatiiMarius Sescu
 
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 StepsBen Scofield
 
Intentionality: Choice and Mastery
Intentionality: Choice and MasteryIntentionality: Choice and Mastery
Intentionality: Choice and MasteryBen Scofield
 

Destacado (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
 

Similar a With a Mighty Hammer

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 CloudHiro Asari
 
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-IIIprinceirfancivil
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails AppsRabble .
 
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 Railstielefeld
 
Crafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in RubyCrafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in RubyNikhil Mungel
 
前瞻性Web性能优化pwpo
前瞻性Web性能优化pwpo前瞻性Web性能优化pwpo
前瞻性Web性能优化pwpoMichael Zhang
 
Writing your Third Plugin
Writing your Third PluginWriting your Third Plugin
Writing your Third PluginJustin Ryan
 
Kubernetes walkthrough
Kubernetes walkthroughKubernetes walkthrough
Kubernetes walkthroughSangwon Lee
 
Tdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema RubyTdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema RubyFabio Akita
 
What's new in Rails 4
What's new in Rails 4What's new in Rails 4
What's new in Rails 4Fabio Akita
 
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...Shift Conference
 

Similar a 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...
 

Más de Ben Scofield

Mind Control: Psychology for the Web
Mind Control: Psychology for the WebMind Control: Psychology for the Web
Mind Control: Psychology for the WebBen Scofield
 
The State of NoSQL
The State of NoSQLThe State of NoSQL
The State of NoSQLBen Scofield
 
NoSQL @ CodeMash 2010
NoSQL @ CodeMash 2010NoSQL @ CodeMash 2010
NoSQL @ CodeMash 2010Ben Scofield
 
NoSQL: Death to Relational Databases(?)
NoSQL: Death to Relational Databases(?)NoSQL: Death to Relational Databases(?)
NoSQL: Death to Relational Databases(?)Ben Scofield
 
WindyCityRails - "Comics" Is Hard
WindyCityRails - "Comics" Is HardWindyCityRails - "Comics" Is Hard
WindyCityRails - "Comics" Is HardBen Scofield
 
"Comics" Is Hard: Alternative Databases
"Comics" Is Hard: Alternative Databases"Comics" Is Hard: Alternative Databases
"Comics" Is Hard: Alternative DatabasesBen Scofield
 
Mind Control on the Web
Mind Control on the WebMind Control on the Web
Mind Control on the WebBen Scofield
 
How the Geeks Inherited the Earth
How the Geeks Inherited the EarthHow the Geeks Inherited the Earth
How the Geeks Inherited the EarthBen Scofield
 
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 ... SpaceBen Scofield
 
"Comics" Is Hard: Domain Modeling Challenges
"Comics" Is Hard: Domain Modeling Challenges"Comics" Is Hard: Domain Modeling Challenges
"Comics" Is Hard: Domain Modeling ChallengesBen Scofield
 
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 SupportBen Scofield
 
Page Caching Resurrected
Page Caching ResurrectedPage Caching Resurrected
Page Caching ResurrectedBen Scofield
 
Page Caching Resurrected: A Fairy Tale
Page Caching Resurrected: A Fairy TalePage Caching Resurrected: A Fairy Tale
Page Caching Resurrected: A Fairy TaleBen Scofield
 
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 FrameworkBen Scofield
 
Advanced Restful Rails - Europe
Advanced Restful Rails - EuropeAdvanced Restful Rails - Europe
Advanced Restful Rails - EuropeBen Scofield
 
Resourceful Plugins
Resourceful PluginsResourceful Plugins
Resourceful PluginsBen Scofield
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful RailsBen Scofield
 

Más 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
 

Último

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Último (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

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 /