Module: SchemaToScaffold

Extended by:
SchemaToScaffold
Included in:
SchemaToScaffold
Defined in:
lib/schema_to_scaffold.rb,
lib/schema_to_scaffold/path.rb,
lib/schema_to_scaffold/table.rb,
lib/schema_to_scaffold/schema.rb,
lib/schema_to_scaffold/version.rb,
lib/schema_to_scaffold/attribute.rb

Defined Under Namespace

Classes: Attribute, Path, Schema, Table

Constant Summary collapse

GENERIC_HELP =

Usage help text to print in all platforms

"  \nUsage: scaffold [options] \nGenerate a rails scaffold script for a given schema.rb\n -h             Displays help.\n -p <path>      It specifies a path to a folder or to a file\n\n"
WINDOWS_HELP =

Windows specific usage help text

"Examples:\nscaffold \nscaffold -p C:\\\\Users\\\\JohnDoe\nscaffold -p C:\\\\Users\\\\JohnDoe\\\\Documents\\\\schema.rb\n"
LINUX_HELP =

Linux specific usage help text

"     -c             Works only on linux. Will copy the script copied to your clipboard. You will need to have xclip installed(see below).\nExamples:\nscaffold\nscaffold -c -p ~/work/rails/my_app\nscaffold -c -p ~/work/rails/my_app/db/schema.rb\n"
MAJOR =
0
MINOR =
4
REVISION =
2
VERSION =
[MAJOR, MINOR, REVISION].join('.')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate_script(schema, table = nil, target) ⇒ Object

Generates the rails scaffold script



76
77
78
79
80
# File 'lib/schema_to_scaffold.rb', line 76

def self.generate_script(schema, table=nil,target)
  schema = Schema.new(schema) unless schema.is_a? Schema
  return schema.to_script if table.nil?
  schema.table(table).to_script target
end

Instance Method Details

#help_msgObject



41
42
43
44
45
46
47
48
# File 'lib/schema_to_scaffold.rb', line 41

def help_msg
  return GENERIC_HELP +
  case RUBY_PLATFORM
  when /win/i   then WINDOWS_HELP
  when /mingw/i then WINDOWS_HELP
  when /linux/i then LINUX_HELP
  end
end

#parse_arguments(argv) ⇒ Object

Parses ARGV and returns a hash of options.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/schema_to_scaffold.rb', line 53

def parse_arguments(argv)
  if argv_index = argv.index("-p")
    path = argv.delete_at(argv_index+1)
    argv.delete('-p')
  end
  args = {
    :xclip => argv.delete('-c'),        # check for xclip flag
    :help =>  argv.delete('-h'),        # check for help flag
    :path =>  path                      # get path to file(s)
  }
  unless argv.empty?
    puts "\n------\nWrong set of arguments.\n------\n" 
    puts help_msg
    exit
  else
    args
  end

end