schema_to_scaffold 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,41 +1,34 @@
1
- Schema to Scaffold
2
- ==================
1
+ # Schema to Scaffold #
3
2
 
4
- After I cross with rake db:schema:dump I feel that it could do a litle more in my case. So there it is.
3
+ Generate rails scaffold pages based on a rails database schema you already have.
5
4
 
6
- Usage
7
- -------
5
+ Use your schema.rb file from `<rails_app>/db` or generated with `rake db:schema:dump`
8
6
 
9
- The code is very simple and the usage is not friendly but almost.
10
7
 
11
- 1. download the zip (or copy paste de code)
12
- 2. extract to folder
13
- 3. cd folder
14
- 4. if your projects are outside your user folder: edit the main.rb and change the path to point to your schema.rb (generated with the rake db:schema:dump)
15
- 5. ruby main.rb
16
- 6. chose the path to your schema.rb
17
- 7. chose your table
18
- 8. copy the rails generate scaffold command
8
+ SchemaToScaffold will generate rails scaffolding scripts by table like this:
19
9
 
20
- * Eight quick steps that will save you a lot of time
21
- * It will give some alerts if your names are not following the rails convention.
10
+ rails g scaffold users fname:string lname:string bdate:date email:string encrypted_password:string
22
11
 
23
- read a litle about [rails convention](http://itsignals.cascadia.com.au/?p=7)
24
12
 
25
- Contributing
26
- ------------
13
+ ## Installation ##
27
14
 
28
- Want to contribute? Great!
15
+ We assume you have rubygems-bundler installed, just type:
29
16
 
30
- 1. Fork it.
31
- 2. Create a branch (`git checkout -b my_schema_to_scafold`)
32
- 3. Commit your changes (`git commit -am "Added great stuff"`)
33
- 4. Push to the branch (`git push origin my_schema_to_scafold`)
34
- 5. Open a [Pull Request][1]
35
- 6. That's all!!
17
+ gem install schema_to_scaffold
36
18
 
37
- [1]: http://github.com/frenesim/schema_to_scaffold/pulls
38
19
 
39
- Colaborate
40
- ------------
41
- if you want to colaborate send me an email please.
20
+ ## Usage ##
21
+
22
+ Just type:
23
+
24
+ scaffold /path/to/your/schema.rb
25
+
26
+ or if you are using linux you can use -c
27
+
28
+ scaffold /path/to/your/schema.rb -c
29
+
30
+ to have the script copied to your clipboard, you will need to have xclip installed(see below).
31
+
32
+ ### To install xclip ###
33
+
34
+ sudo apt-get install xclip
data/bin/scaffold CHANGED
@@ -2,46 +2,37 @@
2
2
  $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
3
3
  require 'schema_to_scaffold'
4
4
 
5
- HELP =<<-END_OF_HELP
6
- Usage: scaffold [OPTION] PATH
7
- Generate a rails scaffold script for the given schema.rb file
8
- PATH is the path to the schema.rb file.
9
-
10
- OPTIONS:
11
- -x put the rails scaffold script in your clipboard using xclip, type:
12
- sudo apt-get install xclip
13
- if you don't have it
14
-
15
- END_OF_HELP
16
-
17
- xclip = ARGV.delete('-x')
18
- if ARGV[0].nil? or ARGV.delete('-h')
19
- puts HELP
20
- else
21
- data = File.open(ARGV[0], 'r') {|f| f.read }
22
- until ARGV.empty? do
23
- ARGV.shift
24
- end
25
-
26
- schema = SchemaToScaffold::Schema.new(data)
27
-
28
- begin
29
- schema.check_rails_naming_conventions
30
- rescue NotFollowingConventionsError => msg
31
- puts msg
32
- end
33
-
34
- puts "\nLoaded tables:"
35
- schema.table_names.each_with_index {|name,i| puts "#{i}. #{name}" }
36
-
37
- begin
38
- print "\nSelect a table: "
39
- end while schema.table_names[(table_id = gets.to_i)].nil?
40
-
41
- script = SchemaToScaffold.generate_script(schema, table_id)
42
- puts "\n#{script}"
43
- if xclip
44
- puts("\n(copied to your clipboard)")
45
- exec("echo '#{script}' | xclip -selection c")
46
- end
5
+ ## Argument conditions
6
+
7
+ opts = SchemaToScaffold.parse_arguments(ARGV)
8
+ ARGV.shift until ARGV.empty?
9
+
10
+ if opts[:help] or opts[:path].nil?
11
+ puts SchemaToScaffold.help_msg
12
+ exit 0
13
+ end
14
+
15
+ begin
16
+ data = File.open(opts[:path], 'r') {|f| f.read }
17
+ rescue
18
+ puts "Unable to open file '#{path}'"
19
+ exit 1
20
+ end
21
+
22
+ ## Generate script from schema
23
+
24
+ schema = SchemaToScaffold::Schema.new(data)
25
+
26
+ puts "\nLoaded tables:"
27
+ schema.table_names.each_with_index {|name,i| puts "#{i}. #{name}" }
28
+
29
+ begin
30
+ print "\nSelect a table: "
31
+ end while schema.table_names[(table_id = gets.to_i)].nil?
32
+
33
+ script = SchemaToScaffold.generate_script(schema, table_id)
34
+ puts "\n#{script}"
35
+ if opts[:xclip]
36
+ puts("\n(copied to your clipboard)")
37
+ exec("echo '#{script}' | xclip -selection c")
47
38
  end
@@ -1,4 +1,3 @@
1
- require 'active_support/inflector'
2
1
  require 'schema_to_scaffold/version'
3
2
  require 'schema_to_scaffold/schema'
4
3
  require 'schema_to_scaffold/table'
@@ -7,6 +6,55 @@ require 'schema_to_scaffold/attribute'
7
6
  module SchemaToScaffold
8
7
  extend self
9
8
 
9
+ ## Usage help text to print in all platforms
10
+
11
+ GENERIC_HELP = <<-END_OF_HELP
12
+ Usage: scaffold [OPTION] PATH
13
+ Generate a rails scaffold script for the given schema.rb file
14
+ PATH is the path to the schema.rb file.
15
+
16
+ END_OF_HELP
17
+
18
+
19
+ ## Windows specific usage help text
20
+
21
+ WINDOWS_HELP = <<-WINDOWS_SAMPLE
22
+ Example: scaffold C:\Users\John\ Doe\Documents\schema.rb
23
+
24
+ WINDOWS_SAMPLE
25
+
26
+ ## Linux specific usage help text
27
+
28
+ LINUX_HELP = <<-LINUX_SAMPLE
29
+ OPTIONS:
30
+ -x put the rails scaffold script in your clipboard using xclip which should be installed
31
+
32
+ Example: scaffold ~/work/rails/my_app/db/schema.rb
33
+
34
+ LINUX_SAMPLE
35
+
36
+ def help_msg
37
+ return GENERIC_HELP +
38
+ case RUBY_PLATFORM
39
+ when /win/i then WINDOWS_HELP
40
+ when /linux/i then LINUX_HELP
41
+ end
42
+ end
43
+
44
+ ##
45
+ # Parses ARGV and returns a hash of options.
46
+
47
+ def parse_arguments(argv)
48
+ {
49
+ xclip: argv.delete('-c'), # check for xclip flag
50
+ help: argv.delete('-h'), # check for help flag
51
+ path: argv[0], # get path to file, must be the last for argv[0] to work
52
+ }
53
+ end
54
+
55
+ ##
56
+ # Generates the rails scaffold script
57
+
10
58
  def self.generate_script(schema, table=nil)
11
59
  schema = Schema.new(schema) unless schema.is_a? Schema
12
60
  return schema.to_script if table.nil?
@@ -3,8 +3,6 @@ module SchemaToScaffold
3
3
 
4
4
  attr_reader :data, :tables
5
5
 
6
- ERROR_MSG = "Warning: You should change the table names according to rails conventions."
7
-
8
6
  def initialize(data)
9
7
  @data, @tables = data, Schema.parse(data)
10
8
  end
@@ -13,10 +11,6 @@ module SchemaToScaffold
13
11
  tables.map(&:name)
14
12
  end
15
13
 
16
- def check_rails_naming_conventions
17
- raise NotFollowingConventionsError, ERROR_MSG if table_names.any? {|n| n == n.singularize or n == n.camelcase }
18
- end
19
-
20
14
  def table(id)
21
15
  case id
22
16
  when Symbol then table(id.to_s)
@@ -1,3 +1,3 @@
1
1
  module SchemaToScaffold
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.authors = ["Humberto Pinto", "João Soares"]
10
10
  gem.email = ["h.lsp999@gmail.com", "jsoaresgeral@gmail.com"]
11
11
  gem.description = <<-EOD
12
- Command line app for windows and linux which parses a schema.rb file obtained from your rails repo or by running rake:schema:dump
12
+ Command line app which parses a schema.rb file obtained from your rails repo or by running rake:schema:dump
13
13
  EOD
14
14
  gem.summary = %q{Generate rails scaffold script from a schema.rb file.}
15
15
  gem.homepage = "http://github.com/frenesim/schema_to_scaffold"
@@ -17,6 +17,4 @@ EOD
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
-
21
- gem.add_runtime_dependency "active_support"
22
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_to_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,25 +11,9 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
  date: 2012-11-26 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: active_support
17
- requirement: !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
30
- version: '0'
31
- description: ! ' Command line app for windows and linux which parses a schema.rb
32
- file obtained from your rails repo or by running rake:schema:dump
14
+ dependencies: []
15
+ description: ! ' Command line app which parses a schema.rb file obtained from your
16
+ rails repo or by running rake:schema:dump
33
17
 
34
18
  '
35
19
  email: