github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

ahe / reverse_scaffold

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 10
    • 2
  • Source
  • Commits
  • Network (2)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

This script generates a Rails scaffold based on an existing table — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Update instructions 
ahe (author)
Tue Aug 04 07:34:53 -0700 2009
commit  fa38d9c7bd96a9e424dfd2d8a9f334be2ea22daf
tree    47916e079c10e8182e3a6f489777997f1a972fea
parent  bb8d1a3b8773e634011adc48a121eafaf019416e
reverse_scaffold / reverse_scaffold reverse_scaffold
100755 84 lines (71 sloc) 2.073 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env ruby
 
# == Synopsis
# The reverse_scaffold script executes a Rails scaffold based on an existing table.
#
#
# == Usage
# ruby script/reverse_scaffold table_name model_name
#
#
# == Examples
# ruby script/reverse_scaffold users user
#
#
# == Options
# -h, --help Displays help message
# -r, --rspec Generates rspec_scaffold
# -V, --verbose Outputs the command but doesn't execute it
# -v, --version
#
#
# == Author
# Anthony Heukmes
# http://2dconcept.com
# http://github.com/ahe
#
#
# == Copyright
# Copyright (c) 2009 Anthony Heukmes. Licensed under the MIT License
 
require 'rdoc/usage'
require 'optparse'
require File.dirname(__FILE__) + '/../config/environment'
 
def display_help
  RDoc::usage
  exit
end
 
def display_version
  puts "Rails ActiveRecord Reverse Scaffold version #{SCRIPT_VERSION}"
  exit
end
 
def configure_table_name(class_name, table_name)
  model = <<-CODE
class #{class_name} < ActiveRecord::Base
set_table_name '#{table_name}'
end
CODE
    
  File.open(File.dirname(__FILE__) + "/../app/models/#{class_name.underscore}.rb", 'w+') {|f| f.write(model) }
end
 
SCRIPT_VERSION = 1.0
command_name = 'scaffold'
options = {}
 
OptionParser.new do |opts|
  opts.on('-h', '--help') { display_help }
  opts.on('-r', '--rspec') { command_name = 'rspec_scaffold' }
  opts.on('-V', '--verbose') { options[:verbose] = true }
  opts.on('-v', '--version') { display_version }
end.parse!
 
display_help unless ARGV[0] && ARGV[1]
 
table_name = ARGV[0]
class_name = ARGV[1].camelize
 
eval "class ::#{class_name} < ActiveRecord::Base; set_table_name '#{table_name}' end"
klass = eval "::#{class_name}"
 
reverse_scaffold = "ruby #{File.dirname(__FILE__)}/generate #{command_name} #{class_name.underscore} --skip-migration "
klass.columns.each do |col|
  reverse_scaffold << col.name + ":" + col.type.to_s + " "
end
 
if options[:verbose]
  puts reverse_scaffold
else
  system reverse_scaffold
  configure_table_name(class_name, table_name) if ARGV[0].downcase != ARGV[1].underscore.pluralize
end
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server