db_discovery_generator 0.1.0 → 0.1.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/USAGE CHANGED
@@ -7,13 +7,12 @@ Description:
7
7
  and a migrations in db/migrate.
8
8
 
9
9
  Example:
10
- ./script/generate db_discovery --no-fields
10
+ ./script/generate db_discovery --discover --no-fields
11
11
 
12
12
  This will create an discovered models:
13
13
  Model: app/models/<table name>.rb
14
14
  Test: test/unit/<table name>_test.rb
15
15
  Fixtures: test/fixtures/<table name>s.yml
16
- Migration: db/migrate/XXX_add_<table name>s.rb
17
16
 
18
17
  If --no-fields is provided then table's available field
19
18
  definitions will be skipped
@@ -3,23 +3,34 @@ class DbDiscoveryGenerator < Rails::Generator::Base
3
3
 
4
4
  def initialize(runtime_args, runtime_options = {})
5
5
  super
6
- if options[:help] then
6
+ if !options[:discover] || options[:help] then
7
7
  usage
8
8
  exit
9
9
  end
10
- @no_fields = options['no_fields']
10
+ @no_fields = options[:no_fields]
11
11
  end
12
12
 
13
13
  def manifest
14
14
  record do |m|
15
15
  m.directory 'app/models'
16
+ m.directory 'test/unit'
17
+ m.directory 'test/fixtures'
18
+
16
19
 
17
20
  generate_models.each do
18
21
  |table, model|
22
+ # Model class, unit test, and fixtures.
23
+ file_name = table.singularize.underscore
24
+ m.template 'unit_test.rb',
25
+ File.join('test/unit', "#{file_name}_test.rb"),
26
+ :assigns => {
27
+ :model => model
28
+ }
29
+ m.template 'fixtures.yml',
30
+ File.join('test/fixtures', "#{model[:table].pluralize}.yml")
19
31
  m.template 'model.rb',
20
- "app/models/#{table.singularize.underscore}.rb",
32
+ "app/models/#{file_name}.rb",
21
33
  :assigns => {
22
- :table_name => table.singularize.underscore.camelize,
23
34
  :model => model,
24
35
  :no_fields => @no_fields
25
36
  }
@@ -35,6 +46,8 @@ class DbDiscoveryGenerator < Rails::Generator::Base
35
46
  "Don't show a list of available fields") { |v| options[:no_fields] = v }
36
47
  opt.on("-h","--help",
37
48
  "Show this help message") { |v| options[:help] = v }
49
+ opt.on("--discover",
50
+ "Does actual work, discovers and creates all models") { |v| options[:discover] = v }
38
51
  end
39
52
 
40
53
  def mysql_primary_key (table_name, name = nil)#:nodoc:
@@ -1,7 +1,7 @@
1
- require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
2
 
3
- class <%= class_name %>Test < Test::Unit::TestCase
4
- fixtures :<%= table_name %>
3
+ class <%= model[:table].camelize %>Test < Test::Unit::TestCase
4
+ fixtures :<%= model[:table].pluralize %>
5
5
 
6
6
  # Replace this with your real tests.
7
7
  def test_truth
data/version.rb CHANGED
@@ -2,7 +2,7 @@ module DbDiscovery #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: db_discovery_generator
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2006-10-14 00:00:00 -04:00
6
+ version: 0.1.1
7
+ date: 2006-10-15 00:00:00 -04:00
8
8
  summary: db_discovery generator allows you to create the DB models with associations from existing DB
9
9
  require_paths:
10
10
  - ''