schema_to_scaffold 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -2
- data/bin/scaffold +6 -5
- data/lib/schema_to_scaffold.rb +21 -10
- data/lib/schema_to_scaffold/path.rb +16 -7
- data/lib/schema_to_scaffold/version.rb +1 -1
- data/schema_to_scaffold.gemspec +10 -8
- metadata +7 -7
- data/lib/CommandLineHelpers.rb +0 -24
data/README.md
CHANGED
@@ -12,7 +12,7 @@ SchemaToScaffold will generate rails scaffolding scripts by table like this:
|
|
12
12
|
|
13
13
|
## Installation ##
|
14
14
|
|
15
|
-
|
15
|
+
Assuming that you have rubygems-bundler installed, just type:
|
16
16
|
|
17
17
|
gem install schema_to_scaffold
|
18
18
|
|
@@ -25,7 +25,8 @@ Just type:
|
|
25
25
|
|
26
26
|
[options]
|
27
27
|
-h Displays help.
|
28
|
-
-p <path> It specifies a
|
28
|
+
-p <path> It specifies a search path or a path to a file
|
29
|
+
ex: -p /user/path or /path/to/your/schema.rb
|
29
30
|
-c Works only on linux. Will copy the script copied to your clipboard.
|
30
31
|
You will need to have xclip installed(see below).
|
31
32
|
|
data/bin/scaffold
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$:.unshift File.expand_path('../lib', File.dirname(__FILE__))
|
3
3
|
require 'schema_to_scaffold'
|
4
|
-
require 'find'
|
5
4
|
|
6
5
|
## Argument conditions
|
7
6
|
|
@@ -14,17 +13,19 @@ if opts[:help]
|
|
14
13
|
end
|
15
14
|
|
16
15
|
## looking for schema.rb in user directory
|
17
|
-
|
16
|
+
|
17
|
+
unless opts[:path].to_s.match(/\.rb$/)
|
18
18
|
paths = SchemaToScaffold::Path.new
|
19
|
-
paths.
|
19
|
+
paths.search_in opts[:path]
|
20
|
+
path = paths.choose
|
20
21
|
end
|
21
22
|
|
22
23
|
## Opening file
|
24
|
+
path||=opts[:path]
|
23
25
|
begin
|
24
|
-
path = opts[:path] || paths.choose
|
25
26
|
data = File.open(path, 'r') {|f| f.read }
|
26
27
|
rescue
|
27
|
-
puts "
|
28
|
+
puts "\nUnable to open file '#{path}'"
|
28
29
|
exit 1
|
29
30
|
end
|
30
31
|
|
data/lib/schema_to_scaffold.rb
CHANGED
@@ -14,7 +14,7 @@ module SchemaToScaffold
|
|
14
14
|
Usage: scaffold [options]
|
15
15
|
Generate a rails scaffold script for a given schema.rb
|
16
16
|
-h Displays help.
|
17
|
-
-p <path> It specifies a path to a file
|
17
|
+
-p <path> It specifies a path to a folder or to a file
|
18
18
|
|
19
19
|
END_OF_HELP
|
20
20
|
|
@@ -24,7 +24,7 @@ END_OF_HELP
|
|
24
24
|
WINDOWS_HELP = <<-WINDOWS_SAMPLE
|
25
25
|
Examples:
|
26
26
|
scaffold
|
27
|
-
|
27
|
+
scaffold -p C:\\Users\\JohnDoe
|
28
28
|
scaffold -p C:\\Users\\JohnDoe\\Documents\\schema.rb
|
29
29
|
WINDOWS_SAMPLE
|
30
30
|
|
@@ -34,8 +34,8 @@ WINDOWS_SAMPLE
|
|
34
34
|
-c Works only on linux. Will copy the script copied to your clipboard. You will need to have xclip installed(see below).
|
35
35
|
Examples:
|
36
36
|
scaffold
|
37
|
-
|
38
|
-
scaffold -
|
37
|
+
scaffold -c -p ~/work/rails/my_app
|
38
|
+
scaffold -c -p ~/work/rails/my_app/db/schema.rb
|
39
39
|
LINUX_SAMPLE
|
40
40
|
|
41
41
|
def help_msg
|
@@ -51,12 +51,23 @@ LINUX_SAMPLE
|
|
51
51
|
# Parses ARGV and returns a hash of options.
|
52
52
|
|
53
53
|
def parse_arguments(argv)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
if argv_index = argv.index("-p")
|
55
|
+
path = argv.delete_at(argv_index+1)
|
56
|
+
argv.delete('-p')
|
57
|
+
end
|
58
|
+
args = {
|
59
|
+
xclip: argv.delete('-c'), # check for xclip flag
|
60
|
+
help: argv.delete('-h'), # check for help flag
|
61
|
+
path: path # get path to file(s)
|
62
|
+
}
|
63
|
+
unless argv.empty?
|
64
|
+
puts "\n------\nWrong set of arguments.\n------\n"
|
65
|
+
puts help_msg
|
66
|
+
exit
|
67
|
+
else
|
68
|
+
args
|
69
|
+
end
|
70
|
+
|
60
71
|
end
|
61
72
|
|
62
73
|
##
|
@@ -6,16 +6,25 @@ module SchemaToScaffold
|
|
6
6
|
class Path
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
@
|
9
|
+
@search_path = ENV[PATH_NAMES.detect {|h| ENV[h] != nil}]
|
10
|
+
end
|
11
|
+
|
12
|
+
def check_directory(path)
|
13
|
+
unless File.directory?(path)
|
14
|
+
puts "\nSorry #{path} is not a valid directory!"
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
path
|
10
18
|
end
|
11
19
|
|
12
20
|
##
|
13
21
|
# Will search for schema.rb in the user directory
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
def search_in(path = nil)
|
23
|
+
@search_path = path.to_s unless path.nil?
|
24
|
+
puts "\nLooking for schema.rb in #{check_directory @search_path}"
|
25
|
+
@schema_paths = Array.new
|
26
|
+
Find.find(@search_path) do |s_p|
|
27
|
+
@schema_paths<<s_p if s_p[/schema\.rb$/]
|
19
28
|
end
|
20
29
|
end
|
21
30
|
|
@@ -25,7 +34,7 @@ module SchemaToScaffold
|
|
25
34
|
@schema_paths.each_with_index {|path,i| puts "#{i}. #{path}" }
|
26
35
|
begin
|
27
36
|
print "\nSelect a path to the target schema: "
|
28
|
-
end while (id = gets.
|
37
|
+
end while @schema_paths[(id = gets.to_i)].nil?
|
29
38
|
@schema_paths[id]
|
30
39
|
end
|
31
40
|
|
data/schema_to_scaffold.gemspec
CHANGED
@@ -6,15 +6,17 @@ require 'schema_to_scaffold/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "schema_to_scaffold"
|
8
8
|
gem.version = SchemaToScaffold::VERSION
|
9
|
-
gem.authors = ["
|
10
|
-
gem.email = ["
|
9
|
+
gem.authors = ["João Soares", "Humberto Pinto"]
|
10
|
+
gem.email = ["jsoaresgeral@gmail.com", "hlsp999@gmail.com"]
|
11
11
|
gem.description = <<-EOD
|
12
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
|
-
gem.summary
|
15
|
-
gem.homepage
|
16
|
-
gem.
|
17
|
-
gem.
|
18
|
-
gem.
|
19
|
-
gem.require_paths
|
14
|
+
gem.summary = %q{Generate rails scaffold script from a schema.rb file.}
|
15
|
+
gem.homepage = "http://github.com/frenesim/schema_to_scaffold"
|
16
|
+
gem.bindir = "bin"
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.post_install_message = "Thanks for installing!"
|
21
|
+
gem.licenses = ['MIT']
|
20
22
|
end
|
metadata
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_to_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
- Humberto Pinto
|
9
8
|
- João Soares
|
9
|
+
- Humberto Pinto
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-12-
|
13
|
+
date: 2012-12-06 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: ! ' Command line app which parses a schema.rb file obtained from your
|
16
16
|
rails repo or by running rake:schema:dump
|
17
17
|
|
18
18
|
'
|
19
19
|
email:
|
20
|
-
- hlsp999@gmail.com
|
21
20
|
- jsoaresgeral@gmail.com
|
21
|
+
- hlsp999@gmail.com
|
22
22
|
executables:
|
23
23
|
- scaffold
|
24
24
|
extensions: []
|
@@ -30,7 +30,6 @@ files:
|
|
30
30
|
- README.md
|
31
31
|
- Rakefile
|
32
32
|
- bin/scaffold
|
33
|
-
- lib/CommandLineHelpers.rb
|
34
33
|
- lib/schema_to_scaffold.rb
|
35
34
|
- lib/schema_to_scaffold/attribute.rb
|
36
35
|
- lib/schema_to_scaffold/path.rb
|
@@ -39,8 +38,9 @@ files:
|
|
39
38
|
- lib/schema_to_scaffold/version.rb
|
40
39
|
- schema_to_scaffold.gemspec
|
41
40
|
homepage: http://github.com/frenesim/schema_to_scaffold
|
42
|
-
licenses:
|
43
|
-
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
post_install_message: Thanks for installing!
|
44
44
|
rdoc_options: []
|
45
45
|
require_paths:
|
46
46
|
- lib
|
data/lib/CommandLineHelpers.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'active_support/inflector'
|
2
|
-
|
3
|
-
module CommandLineHelpers
|
4
|
-
extend self
|
5
|
-
|
6
|
-
class NotFollowingConventionsError < StandardError ; end
|
7
|
-
|
8
|
-
class HelpMessages
|
9
|
-
|
10
|
-
def help
|
11
|
-
print "Usage: schemafold [OPTION] PATH
|
12
|
-
Generate a rails scaffold script for the given schema.rb file
|
13
|
-
PATH is the path to the schema.rb file.
|
14
|
-
|
15
|
-
OPTIONS:
|
16
|
-
-x put the rails scaffold script in your clipboard using xclip, type:
|
17
|
-
sudo apt-get install xclip
|
18
|
-
if you don't have it
|
19
|
-
"
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|