Skip to content
Browse files

Add Rails 3 generators

  • Loading branch information...
1 parent da4958f commit bf98c52fd175bbe2fbd5269ca95b1a62fad6107e Paul Elliott committed Sep 13, 2010
View
1 Changelog.markdown
@@ -1,6 +1,7 @@
### 0.8.0 (09/12/2010) ###
* Stacking callbacks (all defined after_build and after_create callbacks will execute)
+* Rails 3 generators
### 0.7.1 (09/12/2010) ###
View
9 README.markdown
@@ -34,6 +34,15 @@ Now you can define fabricators in any of the following locations.
They are automatically loaded, so no additional requires are necessary.
+### Rails 3 Generators ###
+
+They are really easy to configure! Just add this to your `config/application.rb`:
+
+ config.generators do |g|
+ g.test_framework :rspec, :fixture => true
+ g.fixture_replacement :fabrication, :dir => "spec/fabricators"
+ end
+
### Usage ###
Define your fabricators.
View
15 lib/rails/generators/fabrication/model/model_generator.rb
@@ -0,0 +1,15 @@
+require 'rails/generators/fabrication_generator'
+
+module Fabrication
+ module Generators
+ class ModelGenerator < Base
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
+ class_option :dir, :type => :string, :default => "test/fabricators", :desc => "The directory where the fabricators should go"
+ class_option :extension, :type => :string, :default => "rb", :desc => "file extension name"
+
+ def create_fabrication_file
+ template 'fabricator.rb', File.join(options[:dir], "#{table_name}.#{options[:extension].to_s}")
+ end
+ end
+ end
+end
View
5 lib/rails/generators/fabrication/model/templates/fabricator.rb
@@ -0,0 +1,5 @@
+Fabricator :<%= singular_name %> do
+<% attributes.each do |attribute| -%>
+ <%= attribute.name %> <%= attribute.default.inspect %>
+<% end -%>
+end
View
11 lib/rails/generators/fabrication_generator.rb
@@ -0,0 +1,11 @@
+require 'rails/generators/named_base'
+
+module Fabrication
+ module Generators
+ class Base < Rails::Generators::NamedBase #:nodoc:
+ def self.source_root
+ @_fabrication_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'fabrication', generator_name, 'templates'))
+ end
+ end
+ end
+end

0 comments on commit bf98c52

Please sign in to comment.
Something went wrong with that request. Please try again.