schema_to_scaffold 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -6
- data/bin/scaffold +10 -14
- data/lib/schema_to_scaffold/table.rb +2 -2
- data/lib/schema_to_scaffold/version.rb +1 -1
- data/lib/schema_to_scaffold.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d673c2a71ab1f619041dc8044c8be792aa9c616
|
4
|
+
data.tar.gz: f409f89344e0108f61a374383e8a61259409eea8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78af7d0a89aec5adfdf5f7c51cb0fb33153d55a86c8487b122c515db7d94e8967045e87c569c9100fe3b1d27a7b8ace46e4d3ae01835bf9aebf268327a22dfac
|
7
|
+
data.tar.gz: f118752b73266eae93a6455d20fb0cf735c85dce954887db98b4f47af04e741d087ac1b86165a181c9419ab3a7f56f5f67d7b5a0b5852e93e4f8d97f891b919c
|
data/README.md
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# Schema to Scaffold
|
2
2
|
|
3
|
-
[![Code Climate](https://codeclimate.com/
|
3
|
+
[![Code Climate](https://codeclimate.com/github/frenesim/schema_to_scaffold.png)](https://codeclimate.com/github/frenesim/schema_to_scaffold)
|
4
4
|
|
5
|
-
This Gem generates Rails command strings based on a Rails database schema you already have. Unlike traditional migrations, which modify the database as they generate Rails scaffolding code, this Gem reads the database and generates the Rails code which matches your database's existing columns.
|
5
|
+
This Gem generates Rails command strings based on a Rails database schema you already have. Unlike traditional migrations, which modify the database as they generate Rails scaffolding code, this Gem reads the schema for your database and generates the Rails code which matches your database's existing columns.
|
6
6
|
|
7
|
-
This Gem does not modify anything; it simply prints a string which
|
7
|
+
This Gem does not modify anything; it simply prints a string which you can then use to invoke the Rails generators, and optionally copies the string to your clipboard. Generated string commands available are:
|
8
8
|
```bash
|
9
9
|
rails generate scaffold <model_name> <field[:type]>
|
10
10
|
rails generate factory_girl:model <ModelName> <field[:type]>
|
11
11
|
```
|
12
12
|
|
13
|
-
Use your schema.rb file from `<rails_app>/db` or generated with `rake db:schema:dump`. You can optionally rename schema.rb to `schema_your_fav_name.rb` and it will still be found. Unique schema file names will prevent schema.rb from being overwritten
|
13
|
+
Use your schema.rb file from `<rails_app>/db` or generated with `rake db:schema:dump`. You can optionally rename schema.rb to `schema_your_fav_name.rb` and it will still be found. Unique schema file names will prevent schema.rb from being overwritten if you use migrations and run `rake db:migrate`.
|
14
14
|
|
15
|
-
Schema to Scaffold
|
15
|
+
Schema to Scaffold output looks like this:
|
16
16
|
|
17
17
|
rails generate scaffold users fname:string lname:string bdate:date email:string encrypted_password:string
|
18
18
|
|
@@ -33,15 +33,17 @@ Generate a rails scaffold script for a given schema.rb
|
|
33
33
|
-p <path> It specifies a path to a folder or to a file.
|
34
34
|
-c Will copy the script to your clipboard. Requires xclip be installed on Linux.
|
35
35
|
-f Generates a factory_girl:model rather than a full scaffold.
|
36
|
+
-m Add migration (use if your schema comes from a different database)
|
36
37
|
|
37
38
|
Examples:
|
38
39
|
scaffold
|
39
40
|
scaffold -c -p ~/work/rails/my_app
|
40
41
|
scaffold -c -p ~/work/rails/my_app/db/schema.rb
|
42
|
+
|
41
43
|
```
|
42
44
|
## Generators
|
43
45
|
|
44
|
-
Since this gem will let you invoke Rails generators for your scaffolding, make sure you've configured your generators with your preferred settings before start. There's a good [Rails Guide](http://guides.rubyonrails.org/generators.html) and you can invoke `rails g scaffold -h` to see options.
|
46
|
+
Since this gem will let you invoke Rails generators for your scaffolding, make sure you've configured your generators with your preferred settings before you start. There's a good [Rails Guide](http://guides.rubyonrails.org/generators.html) and you can invoke `rails g scaffold -h` to see options.
|
45
47
|
|
46
48
|
Generator options are configured in `config/application.rb`. Here is an example setting:
|
47
49
|
|
@@ -51,6 +53,7 @@ module YourApplication
|
|
51
53
|
config.generators do |g|
|
52
54
|
g.hidden_namespaces << :test_unit << :erb # Hide unwanted generators
|
53
55
|
g.template_engine :slim # Select template engine
|
56
|
+
g.helper false # Don't create view helpers
|
54
57
|
g.test_framework :rspec, :view_specs => false
|
55
58
|
g.integration_tool :rspec
|
56
59
|
g.fixture_replacement :factory_girl # Choose between fixtures and factories
|
@@ -63,6 +66,10 @@ end
|
|
63
66
|
```
|
64
67
|
If you configure factory_girl as your fixture_replacement here, there is no need to invoke factory_girl separately with the `scaffold -f` command.
|
65
68
|
|
69
|
+
## Migrations
|
70
|
+
|
71
|
+
Schema to Scaffold is set up by default to support creating scaffolds for your existing database, presuming that you have generated schema.rb with `rake db:schema:dump`. Therefore, no migrations are necessary, because the database already contains the desired table. If instead you are using a schema.rb that was generated from a database other than current development database, you can use the `-m` option to build a generator command that includes migrations.
|
72
|
+
|
66
73
|
## To install xclip on Linux
|
67
74
|
|
68
75
|
sudo apt-get install xclip
|
data/bin/scaffold
CHANGED
@@ -52,23 +52,19 @@ else
|
|
52
52
|
end
|
53
53
|
|
54
54
|
script = []
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
tables.each { |table_id| script << SchemaToScaffold.generate_script(schema, table_id, "scaffold") }
|
62
|
-
puts "\nScript for rails scaffold:\n\n"
|
63
|
-
puts script.join("")
|
64
|
-
end
|
55
|
+
target = opts[:factory_girl] ? "factory_girl:model" : "scaffold"
|
56
|
+
tables.each { |table_id| script << SchemaToScaffold.generate_script(schema, table_id, target) }
|
57
|
+
script << " --no-migration" unless opts[:migration] || opts[:factory_girl]
|
58
|
+
output = script.join("")
|
59
|
+
puts "\nScript for #{target}:\n\n"
|
60
|
+
puts output
|
65
61
|
|
66
62
|
if opts[:clipboard]
|
67
63
|
puts("\n(copied to your clipboard)")
|
68
64
|
case RUBY_PLATFORM
|
69
|
-
when /darwin/i then exec("echo '#{
|
70
|
-
when /linux/i then exec("echo '#{
|
71
|
-
when /mingw/i then exec("echo '#{
|
72
|
-
when /win/i then exec("echo '#{
|
65
|
+
when /darwin/i then exec("echo '#{output}' | tr -d '\n' | pbcopy")
|
66
|
+
when /linux/i then exec("echo '#{output}' | tr -d '\n' | xclip -selection c")
|
67
|
+
when /mingw/i then exec("echo '#{output}' | clip")
|
68
|
+
when /win/i then exec("echo '#{output}' | clip")
|
73
69
|
end
|
74
70
|
end
|
@@ -12,8 +12,8 @@ module SchemaToScaffold
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_script(target)
|
15
|
-
|
16
|
-
return "rails generate #{target} #{modelize name} #{
|
15
|
+
attributes_list = attributes.map(&:to_script).reject{|x| x.nil? || x.empty?}.join(' ')
|
16
|
+
return "rails generate #{target} #{modelize name} #{attributes_list}"
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.parse(table_data)
|
data/lib/schema_to_scaffold.rb
CHANGED
@@ -17,6 +17,7 @@ Generate a rails scaffold script for a given schema.rb
|
|
17
17
|
-p <path> It specifies a path to a folder or to a file.
|
18
18
|
-c Will copy the script to your clipboard. Requires xclip be installed on Linux.
|
19
19
|
-f Generates a factory_girl:model rather than a full scaffold.
|
20
|
+
-m Add migration (use if your schema comes from a different database)
|
20
21
|
|
21
22
|
END_OF_HELP
|
22
23
|
|
@@ -58,8 +59,9 @@ LINUX_SAMPLE
|
|
58
59
|
argv.delete('-p')
|
59
60
|
end
|
60
61
|
args = {
|
61
|
-
:clipboard => argv.delete('-c'),
|
62
|
+
:clipboard => argv.delete('-c'), # check for clipboard flag
|
62
63
|
:factory_girl => argv.delete('-f'), # factory_girl instead of scaffold
|
64
|
+
:migration => argv.delete('-m'), # generate migrations
|
63
65
|
:help => argv.delete('-h'), # check for help flag
|
64
66
|
:path => path # get path to file(s)
|
65
67
|
}
|
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.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Soares
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|