schema_to_scaffold 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/frenesim/schema_to_scaffold)
4
4
 
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
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]>`
9
9
 
10
10
  Important:
11
11
  This gem will not run code for you. It will only generate a string for you to copy and paste
data/bin/scaffold CHANGED
@@ -13,12 +13,8 @@ if opts[:help]
13
13
  end
14
14
 
15
15
  ## looking for /schema\S*.rb$/ in user directory
16
-
17
- unless opts[:path].to_s.match(/\.rb$/)
18
- paths = SchemaToScaffold::Path.new(opts[:path])
19
- paths.search_rb
20
- path = paths.choose
21
- end
16
+ paths = SchemaToScaffold::Path.new(opts[:path])
17
+ path = paths.choose unless opts[:path].to_s.match(/\.rb$/)
22
18
 
23
19
  ## Opening file
24
20
  path||=opts[:path]
@@ -34,9 +30,7 @@ end
34
30
  schema = SchemaToScaffold::Schema.new(data)
35
31
 
36
32
  begin
37
- if schema.table_names.empty? then
38
- raise "Could not find tables in '#{path}'"
39
- end
33
+ raise if schema.table_names.empty?
40
34
  puts "\nLoaded tables:"
41
35
  schema.table_names.each_with_index {|name,i| puts "#{i}. #{name}" }
42
36
  print "\nSelect a table: "
@@ -45,10 +39,10 @@ rescue
45
39
  exit 1
46
40
  end while schema.table_names[(table_id = gets.to_i)].nil?
47
41
 
48
- script_scaffold = SchemaToScaffold.generate_script_scaffold(schema, table_id,"scaffold")
42
+ script_scaffold = SchemaToScaffold.generate_script(schema, table_id,"scaffold")
49
43
  puts "\nScript for rails scaffold\n#{script_scaffold}"
50
44
 
51
- script_factory_girl = SchemaToScaffold.generate_script_scaffold(schema, table_id,"factory_girl:model")
45
+ script_factory_girl = SchemaToScaffold.generate_script(schema, table_id,"factory_girl:model")
52
46
  puts "\nScript for factory girl\n#{script_factory_girl}"
53
47
 
54
48
 
@@ -73,7 +73,7 @@ LINUX_SAMPLE
73
73
  ##
74
74
  # Generates the rails scaffold script
75
75
 
76
- def self.generate_script_scaffold(schema, table=nil,target)
76
+ def self.generate_script(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
79
  schema.table(table).to_script target
@@ -21,20 +21,11 @@ module SchemaToScaffold
21
21
  puts "\nLooking for schema.rb in #{@search_path}"
22
22
  end
23
23
 
24
- ##
25
- # Will search for /schema[^\/]*.rb$/ in the current directory
26
- def search_rb
27
- @search_path = @path.to_s unless @path.nil?
28
- check_directory
29
- @schema_paths = Array.new
30
- Find.find(@search_path) do |s_p|
31
- @schema_paths<<s_p if s_p[/schema[^\/]*.rb$/]
32
- end
33
- end
34
-
24
+
35
25
  ##
36
26
  # Return the chosen path
37
27
  def choose
28
+ search_rb
38
29
  if @schema_paths.empty?
39
30
  puts "\nSorry there is none /schema[^\/]*.rb$/ in the directory #{@search_path}"
40
31
  exit
@@ -45,7 +36,19 @@ module SchemaToScaffold
45
36
  end while @schema_paths[(id = gets.to_i)].nil?
46
37
  @schema_paths[id]
47
38
  end
48
-
39
+
40
+ private
41
+ ##
42
+ # Will search for /schema[^\/]*.rb$/ in the current directory
43
+ def search_rb
44
+ @search_path = @path.to_s unless @path.nil?
45
+ check_directory
46
+ @schema_paths = Array.new
47
+ Find.find(@search_path) do |s_p|
48
+ @schema_paths<<s_p if s_p[/schema[^\/]*.rb$/]
49
+ end
50
+ end
51
+
49
52
  end
50
53
 
51
54
  end
@@ -1,5 +1,5 @@
1
1
  module SchemaToScaffold
2
-
2
+ require 'active_support/inflector'
3
3
  ##
4
4
  # fetch table names and convert them to a scaffold syntax
5
5
  class Table
@@ -11,7 +11,8 @@ module SchemaToScaffold
11
11
  end
12
12
 
13
13
  def to_script(target)
14
- "rails generate #{target} #{name} #{attributes.map(&:to_script).join(' ')}"
14
+ return "rails generate #{target} #{name} #{attributes.map(&:to_script).join(' ')}" if target == "scaffold"
15
+ return "rails generate #{target} #{name.camelize.singularize} #{attributes.map(&:to_script).join(' ')}" if target == "factory_girl:model"
15
16
  end
16
17
 
17
18
  def self.parse(table_data)
@@ -1,6 +1,6 @@
1
1
  module SchemaToScaffold
2
2
  MAJOR = 0
3
3
  MINOR = 4
4
- REVISION = 0
4
+ REVISION = 1
5
5
  VERSION = [MAJOR, MINOR, REVISION].join('.')
6
6
  end
@@ -19,4 +19,6 @@ EOD
19
19
  gem.require_paths = ["lib"]
20
20
  gem.post_install_message = "Thanks for installing!"
21
21
  gem.licenses = ['MIT']
22
+
23
+ gem.add_dependency('activesupport', '>= 3.2.1')
22
24
  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.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-17 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2013-05-20 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 3.2.1
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: 3.2.1
15
31
  description: ! ' Command line app which parses a schema.rb file obtained from your
16
32
  rails repo or by running rake:schema:dump
17
33