Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env ruby
- require 'pp'
- require 'rubygems'
- require 'fabrication'
- require 'optparse'
- @class_generator_method = 'poc'
- @fabricator_with = 'faker'
- @attributes_for = false
- def main
- args.parse( ARGV )
- generate_class
- generate_fabricator
- pp (1..10).map {
- if ( @attributes_for )
- Fabricate.attributes_for( :company )
- else
- Fabricate( :company )
- end
- }
- end
- def generate_class
- require File.dirname( __FILE__ ) + "/class_by_#{@class_generator_method}"
- end
- def generate_fabricator
- require File.dirname( __FILE__ ) + "/fabricator_with_#{@fabricator_with}"
- end
- def class_generator_methods
- Dir.glob( 'class_by_*.rb' ).map { |e| e.sub( /class_by_(.+)\.rb/, '\1' ) }
- end
- def fabricator_generator_methods
- Dir.glob( 'fab_with_*.rb' ).map { |e| e.sub( /fab_with_(.+)\.rb/, '\1' ) }
- end
- def args
- OptionParser.new { |opt|
- opt.on( '-g', '--generator-method <poc|struct>' ) { |val|
- if ( class_generator_methods.include?( val ) )
- @class_generator_method = val
- else
- raise ArgumentError
- end
- }
- opt.on( '-a', '--attributes' ) {
- @attributes_for = true
- }
- opt.on( '-f', '--fabricator-with <faker|forgery>' ) { |val|
- @fabricator_with = val
- }
- }
- end
- main()
Add Comment
Please, Sign In to add comment