Sha256: b10b284fe934310184a6679c71cfb8198f2068fd844f3af8884e0c570ab0278e

Contents?: true

Size: 781 Bytes

Versions: 1

Compression:

Stored size: 781 Bytes

Contents

#!/usr/bin/env ruby
#
# This dev helper script converts any migration file into a Rails scaffold command

output = STDOUT
ARGV.each do |file_name|
  if File.exist? file_name
    File.open(file_name) do |file|
      puts "\nProcessing: #{file.inspect}"

      model_name = nil
      file.each do |line|
        if line =~ /create_table.*:ib_(.*)s.* do \|t\|/
          model_name = Regexp.last_match(1)
          output.print "\nrails generate scaffold #{model_name} "
        end

        if line =~ /t\.(\w*) :(\w*)/
          field, type = Regexp.last_match(2), Regexp.last_match(1)
          if type == 'references'
          	field, type = field + '_id', 'integer'
          end
          output.print "#{field}:#{type} "
        end
      end
    end
    output.puts
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ib-ruby-0.9.2 bin/scaffold.rb