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 -c             Will copy the script to your clipboard. Requires xclip be installed on Linux.\n -f             Generates a factory_girl:model rather than a full scaffold.\n -m             Add migration (use if your schema comes from a different database)\n\n"
WINDOWS_HELP =

Windows specific usage help text

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

Linux specific usage help text

"Examples:\nscaffold\nscaffold -c -p ~/work/rails/my_app\nscaffold -c -p ~/work/rails/my_app/db/schema.rb\n"
MAJOR =
0
MINOR =
5
REVISION =
3
VERSION =
[MAJOR, MINOR, REVISION].join('.')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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

Generates the rails scaffold script



81
82
83
84
85
# File 'lib/schema_to_scaffold.rb', line 81

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

Instance Method Details

#help_msgObject



43
44
45
46
47
48
49
50
51
# File 'lib/schema_to_scaffold.rb', line 43

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

#parse_arguments(argv) ⇒ Object

Parses ARGV and returns a hash of options.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/schema_to_scaffold.rb', line 56

def parse_arguments(argv)
  if argv_index = argv.index("-p")
    path = argv.delete_at(argv_index+1)
    argv.delete('-p')
  end
  args = {
    :clipboard => argv.delete('-c'),    # check for clipboard flag
    :factory_girl => argv.delete('-f'), # factory_girl instead of scaffold
    :migration => argv.delete('-m'),   # generate migrations
    :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