schema_to_scaffold 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/frenesim/schema_to_scaffold)
4
4
 
5
- Generate rails scaffold pages based on a rails database schema you already have.
5
+ Generate rails commands strings based on a rails database schema you already have.
6
+ Commands available are:
7
+ -rails generate scaffold
8
+ -rails generate factory_girl:model
9
+
10
+ Important:
11
+ This gem will not run code for you. It will only generate a string for you to copy and paste
6
12
 
7
13
  Use your schema.rb file from `<rails_app>/db` or generated with `rake db:schema:dump`
8
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
data/bin/scaffold CHANGED
@@ -29,7 +29,7 @@ rescue
29
29
  exit 1
30
30
  end
31
31
 
32
- ## Generate script from schema
32
+ ## Generate scripts from schema
33
33
 
34
34
  schema = SchemaToScaffold::Schema.new(data)
35
35
 
@@ -45,8 +45,13 @@ rescue
45
45
  exit 1
46
46
  end while schema.table_names[(table_id = gets.to_i)].nil?
47
47
 
48
- script = SchemaToScaffold.generate_script(schema, table_id)
49
- puts "\n#{script}"
48
+ script_scaffold = SchemaToScaffold.generate_script_scaffold(schema, table_id,"scaffold")
49
+ puts "\nScript for rails scaffold\n#{script_scaffold}"
50
+
51
+ script_factory_girl = SchemaToScaffold.generate_script_scaffold(schema, table_id,"factory_girl:model")
52
+ puts "\nScript for factory girl\n#{script_factory_girl}"
53
+
54
+
50
55
  if opts[:xclip]
51
56
  puts("\n(copied to your clipboard)")
52
57
  exec("echo '#{script}' | xclip -selection c")
@@ -73,9 +73,9 @@ LINUX_SAMPLE
73
73
  ##
74
74
  # Generates the rails scaffold script
75
75
 
76
- def self.generate_script(schema, table=nil)
76
+ def self.generate_script_scaffold(schema, table=nil,target)
77
77
  schema = Schema.new(schema) unless schema.is_a? Schema
78
78
  return schema.to_script if table.nil?
79
- schema.table(table).to_script
79
+ schema.table(table).to_script target
80
80
  end
81
81
  end
@@ -14,5 +14,7 @@ module SchemaToScaffold
14
14
  def self.parse(attribute)
15
15
  Attribute.new(*attribute.match(/t\.(\w+)\s+"(\w+)"/).captures)
16
16
  end
17
+
18
+
17
19
  end
18
20
  end
@@ -15,7 +15,7 @@ module SchemaToScaffold
15
15
  # Validate if a given path leads to a directory
16
16
  def check_directory
17
17
  unless File.directory?(@search_path)
18
- puts "\nSorry #{@search_path} is not a valid directory!"
18
+ puts "\nSorry #{@search_path} is not a valid directory!\nHere is an example:\nscaffold -p /home/foo/bar"
19
19
  exit
20
20
  end
21
21
  puts "\nLooking for schema.rb in #{@search_path}"
@@ -10,8 +10,8 @@ module SchemaToScaffold
10
10
  @name, @attributes = name, attributes
11
11
  end
12
12
 
13
- def to_script
14
- "rails g scaffold #{name} #{attributes.map(&:to_script).join(' ')}"
13
+ def to_script(target)
14
+ "rails generate #{target} #{name} #{attributes.map(&:to_script).join(' ')}"
15
15
  end
16
16
 
17
17
  def self.parse(table_data)
@@ -1,6 +1,6 @@
1
1
  module SchemaToScaffold
2
2
  MAJOR = 0
3
- MINOR = 3
4
- REVISION = 2
3
+ MINOR = 4
4
+ REVISION = 0
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.3.2
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-26 00:00:00.000000000 Z
13
+ date: 2013-05-17 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
@@ -58,9 +58,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 1.8.15
61
+ rubygems_version: 1.8.24
62
62
  signing_key:
63
63
  specification_version: 3
64
64
  summary: Generate rails scaffold script from a schema.rb file.
65
65
  test_files: []
66
- has_rdoc: