schema_to_scaffold 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8de36372e8689f2dde99b643b28c3a716db14e70
4
- data.tar.gz: dfa57a6943cd21193c7c25fd2bc68b24211a5821
3
+ metadata.gz: b7d161bb74f929c36273c630bbb0aee8e2bc88f0
4
+ data.tar.gz: c7094d6063f157b02b866c345ca2d69c3c7b8a4d
5
5
  SHA512:
6
- metadata.gz: dd9f750ec2ef14231d6ca6c3aec459f0e52fb90717d1872a93d9b3ac56c25d0ca4728f4c2e0618fb9af1a8d30475cc60d301ad976cd18a3b7a734f5a39b4348f
7
- data.tar.gz: 47faed47d547fe093e0113418ac0bd2f9ef1543f0de9259629d4bab33fef9770ac97f10487e227c593f35e2dfd3585f40fdcab808fd03a6edb5c569739214d56
6
+ metadata.gz: cca1fb55d406a0e04f794ee9914d5e75a2b78cd033db3424f550acee5daf06cc0c726c427c74634aa17663117b7c2f5a3c4057360634fcead6e665984472bb66
7
+ data.tar.gz: 9e7759ac83755b438f47e21e9d512a51843a8704f5b2521f2dc65516039849445dcbc50585db43467d64ac3a8e53d2dc46dc593b400fa7431ce0910f62b8a55f
data/README.md CHANGED
@@ -2,22 +2,21 @@
2
2
 
3
3
  [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/frenesim/schema_to_scaffold)
4
4
 
5
- This Gem shall generate rails commands strings based on a rails database schema you already have.<br>
6
- Generated string commands available are:<br>
7
- `rails generate scaffold <model_name> <field[:type]>`<br>
8
- `rails generate factory_girl:model <ModelName> <field[:type]>`
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.
9
6
 
10
- Important:
11
- This gem will not run code for you. It will only generate a string for you to copy and paste
7
+ This Gem does not modify anything; it simply prints a string which will then invoke the Rails generators, and optionally copies the string to your clipboard. Generated string commands available are:
8
+ ```bash
9
+ rails generate scaffold <model_name> <field[:type]>
10
+ rails generate factory_girl:model <ModelName> <field[:type]>
11
+ ```
12
12
 
13
- Use your schema.rb file from `<rails_app>/db` or generated with `rake db:schema:dump`
14
- You can rename schema.rb to schema_your_fav_name.rb that I will find it to. This will prevent schema.rb from being
15
- overwritten when one run rake db:migrate.
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 when you run `rake db:migrate`.
16
14
 
17
- SchemaToScaffold will generate rails scaffolding scripts by table like this:
15
+ Schema to Scaffold will generate rails scaffolding scripts by table like this:
18
16
 
19
- rails g scaffold users fname:string lname:string bdate:date email:string encrypted_password:string
17
+ rails generate scaffold users fname:string lname:string bdate:date email:string encrypted_password:string
20
18
 
19
+ It's possible to generate scripts for all your tables at once. Just choose `*` when choosing the table.
21
20
 
22
21
  ## Installation
23
22
 
@@ -25,25 +24,50 @@ Assuming that you have rubygems-bundler installed, just type:
25
24
 
26
25
  gem install schema_to_scaffold
27
26
 
28
-
29
27
  ## Usage
30
28
 
31
- Just type:
32
-
33
- scaffold [options]
34
-
35
- [options]
36
- -h Displays help.
37
- -p <path> It specifies a search path or a path to a file
38
- ex: -p /user/path or /path/to/your/schema.rb
39
- -c Works only on linux. Will copy the script copied to your clipboard.
40
- You will need to have xclip installed(see below).
41
-
42
- ### To install xclip
29
+ ```
30
+ Usage: scaffold [options]
31
+ Generate a rails scaffold script for a given schema.rb
32
+ -h Displays help.
33
+ -p <path> It specifies a path to a folder or to a file.
34
+ -c Will copy the script to your clipboard. Requires xclip be installed on Linux.
35
+ -f Generates a factory_girl:model rather than a full scaffold.
36
+
37
+ Examples:
38
+ scaffold
39
+ scaffold -c -p ~/work/rails/my_app
40
+ scaffold -c -p ~/work/rails/my_app/db/schema.rb
41
+ ```
42
+ ## Generators
43
+
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.
45
+
46
+ Generator options are configured in `config/application.rb`. Here is an example setting:
47
+
48
+ ```ruby
49
+ module YourApplication
50
+ class Application < Rails::Application
51
+ config.generators do |g|
52
+ g.hidden_namespaces << :test_unit << :erb # Hide unwanted generators
53
+ g.template_engine :slim # Select template engine
54
+ g.test_framework :rspec, :view_specs => false
55
+ g.integration_tool :rspec
56
+ g.fixture_replacement :factory_girl # Choose between fixtures and factories
57
+ g.factory_girl dir: 'spec/factories'
58
+ g.javascript_engine :js # Disable coffeescript
59
+ g.scaffold_controller "responders_controller" # from responders gem
60
+ end
61
+ end
62
+ end
63
+ ```
64
+ 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
+
66
+ ## To install xclip on Linux
43
67
 
44
68
  sudo apt-get install xclip
45
-
46
- ### Contributing
69
+
70
+ ## Contributing
47
71
 
48
72
  Want to contribute? Great!
49
73
 
@@ -56,6 +80,6 @@ Just type:
56
80
 
57
81
  [1]: http://github.com/frenesim/schema_to_scaffold/pulls
58
82
 
59
- ### Collaborate
83
+ ## Collaborate
60
84
 
61
85
  If you want to collaborate send me an email please.
data/bin/scaffold CHANGED
@@ -51,21 +51,24 @@ else
51
51
  tables = [result.to_i]
52
52
  end
53
53
 
54
- script_scaffold = []
55
- script_factory_girl = []
56
- tables.each do |table_id|
57
- script_scaffold << SchemaToScaffold.generate_script(schema, table_id,"scaffold")
58
- script_factory_girl << SchemaToScaffold.generate_script(schema, table_id,"factory_girl:model")
59
- end
60
-
61
- puts "\nScript for rails scaffold"
62
- puts script_scaffold.join("\n")
63
-
64
- puts "\nScript for factory girl"
65
- puts script_factory_girl.join("\n")
54
+ script = []
66
55
 
56
+ if opts[:factory_girl]
57
+ tables.each { |table_id| script << SchemaToScaffold.generate_script(schema, table_id, "factory_girl:model") }
58
+ puts "\nScript for factory girl:\n\n"
59
+ puts script.join("")
60
+ else
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
67
65
 
68
- if opts[:xclip]
66
+ if opts[:clipboard]
69
67
  puts("\n(copied to your clipboard)")
70
- exec("echo '#{script}' | xclip -selection c")
68
+ case RUBY_PLATFORM
69
+ when /darwin/i then exec("echo '#{script.join("")}' | tr -d '\n' | pbcopy")
70
+ when /linux/i then exec("echo '#{script.join("")}' | tr -d '\n' | xclip -selection c")
71
+ when /mingw/i then exec("echo '#{script.join("")}' | clip")
72
+ when /win/i then exec("echo '#{script.join("")}' | clip")
73
+ end
71
74
  end
@@ -14,7 +14,9 @@ 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 folder or to a file
17
+ -p <path> It specifies a path to a folder or to a file.
18
+ -c Will copy the script to your clipboard. Requires xclip be installed on Linux.
19
+ -f Generates a factory_girl:model rather than a full scaffold.
18
20
 
19
21
  END_OF_HELP
20
22
 
@@ -25,13 +27,12 @@ END_OF_HELP
25
27
  Examples:
26
28
  scaffold
27
29
  scaffold -p C:\\Users\\JohnDoe
28
- scaffold -p C:\\Users\\JohnDoe\\Documents\\schema.rb
30
+ scaffold -c -p C:\\Users\\JohnDoe\\Documents\\schema.rb
29
31
  WINDOWS_SAMPLE
30
32
 
31
33
  ## Linux specific usage help text
32
34
 
33
35
  LINUX_HELP = <<-LINUX_SAMPLE
34
- -c Works only on linux. Will copy the script copied to your clipboard. You will need to have xclip installed(see below).
35
36
  Examples:
36
37
  scaffold
37
38
  scaffold -c -p ~/work/rails/my_app
@@ -41,9 +42,10 @@ LINUX_SAMPLE
41
42
  def help_msg
42
43
  return GENERIC_HELP +
43
44
  case RUBY_PLATFORM
44
- when /win/i then WINDOWS_HELP
45
- when /mingw/i then WINDOWS_HELP
46
- when /linux/i then LINUX_HELP
45
+ when /darwin/i then LINUX_HELP
46
+ when /linux/i then LINUX_HELP
47
+ when /mingw/i then WINDOWS_HELP
48
+ when /win/i then WINDOWS_HELP
47
49
  end
48
50
  end
49
51
 
@@ -56,7 +58,8 @@ LINUX_SAMPLE
56
58
  argv.delete('-p')
57
59
  end
58
60
  args = {
59
- :xclip => argv.delete('-c'), # check for xclip flag
61
+ :clipboard => argv.delete('-c'), # check for clipboard flag
62
+ :factory_girl => argv.delete('-f'), # factory_girl instead of scaffold
60
63
  :help => argv.delete('-h'), # check for help flag
61
64
  :path => path # get path to file(s)
62
65
  }
@@ -12,12 +12,12 @@ module SchemaToScaffold
12
12
  end
13
13
 
14
14
  def to_script(target)
15
- return "rails generate #{target} #{modelize name} #{attributes.map(&:to_script).reject{|x| x.nil? || x.empty?}.join(' ')}" if target == "scaffold"
15
+ return "rails generate #{target} #{modelize name} #{attributes.map(&:to_script).reject{|x| x.nil? || x.empty?}.join(' ')} --no-migration" if target == "scaffold"
16
16
  return "rails generate #{target} #{modelize name} #{attributes.map(&:to_script).reject{|x| x.nil? || x.empty?}.join(' ')}" if target == "factory_girl:model"
17
17
  end
18
18
 
19
19
  def self.parse(table_data)
20
- return unless name = table_data[/table "(.+)"/]
20
+ return unless name = table_data[/table "([^"]+?)"/]
21
21
  name = $1
22
22
  atts = table_data.lines.to_a.select {|line| line =~ /t\.\w+/ }.map {|att| Attribute.parse att }
23
23
  Table.new(name, atts)
@@ -1,6 +1,6 @@
1
1
  module SchemaToScaffold
2
2
  MAJOR = 0
3
3
  MINOR = 5
4
- REVISION = 0
4
+ REVISION = 1
5
5
  VERSION = [MAJOR, MINOR, REVISION].join('.')
6
6
  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.5.0
4
+ version: 0.5.1
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: 2013-12-19 00:00:00.000000000 Z
12
+ date: 2014-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport