ez_model 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -1
- data/bin/ezmodel +7 -6
- data/ez_model.gemspec +3 -3
- data/lib/ez_model/version.rb +1 -1
- metadata +5 -5
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# EZModel
|
2
|
+
|
2
3
|
Generate models and schema.rb from existing database just in one command line. If you prefer design ER diagram and export scripts to generate database schema, or if you have to work with a legacy database, this can save you insane amount of time. All you need to do is to have a database.yml configuraiton file in ~/config/. Besides creating all models it sets proper table name and primary key if tables and columns naming doesn’t follow Rails convention. It also tries to read all foreign keys data from a database.
|
3
4
|
|
4
5
|
It uses [Rmre](https://github.com/bosko/rmre "Rmre") as underlying reverse engine to generate models. I made some modifications to Rmre to support mysql2 adapter, and had those auto-generated model files placed in a subfolder inside ~/app/models/ez_models/ instead of the default ~/app/models/, so that regenerating models will not overwrite the existing ones. Over the times, db schema can ge changed, all it needs is to run the command again to regenerate models, developers can feel free to add methods to the models classes in ~/app/models/ without worrying about being overwritten.
|
5
6
|
|
6
7
|
|
7
8
|
## How it works
|
9
|
+
|
8
10
|
First let's take a look at what it does.
|
9
11
|
|
10
12
|
In ~/app/models/ez_models/, it will generate model files inherit ActiveRecord::Base
|
@@ -38,8 +40,11 @@ In ~/app/models/, it will generate same model files and inherit the above classe
|
|
38
40
|
|
39
41
|
|
40
42
|
## How to use it
|
43
|
+
|
41
44
|
###Prerequisite
|
45
|
+
|
42
46
|
####1. Setup database schema, if you already have a database set up, skip this step;
|
47
|
+
|
43
48
|
there are many tools can be use for database design, you can then export scripts to generate db schema;
|
44
49
|
checkout mysql-workbench and its forward-engineering feature for more details about designing ER diagram and generate schema;
|
45
50
|
|
@@ -71,6 +76,7 @@ checkout mysql-workbench and its forward-engineering feature for more details ab
|
|
71
76
|
socket: /var/run/mysqld/mysqld.sock
|
72
77
|
|
73
78
|
###Generate models
|
79
|
+
|
74
80
|
cd to rails root directory
|
75
81
|
|
76
82
|
cd /path_to_rails_root
|
@@ -99,11 +105,13 @@ see version
|
|
99
105
|
ezmodel -v
|
100
106
|
|
101
107
|
## Installation
|
102
|
-
|
108
|
+
|
109
|
+
gem install ez_model
|
103
110
|
|
104
111
|
See here for more details: [http://rubygems.org/gems/ez_model](http://rubygems.org/gems/ez_model "EZModel RubyGem Page")
|
105
112
|
|
106
113
|
## Authors
|
114
|
+
|
107
115
|
Tianyu Huang
|
108
116
|
The reverse engine for generating models was created by Bosko Ivanisevic, check out https://github.com/bosko/rmre for details
|
109
117
|
|
data/bin/ezmodel
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
lib = File.expand_path("../../lib/", __FILE__)
|
2
3
|
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
3
4
|
|
@@ -12,7 +13,7 @@ require "rmre"
|
|
12
13
|
########################################################################################################
|
13
14
|
options = {:db => {}}
|
14
15
|
optparse = OptionParser.new do |opts|
|
15
|
-
opts.banner = "Usage: ezmodel -g [
|
16
|
+
opts.banner = "Usage: ezmodel -g [-o] [-d PATH] [-e ENVIRONMENT]"
|
16
17
|
|
17
18
|
options[:generate] = false
|
18
19
|
opts.on("-g", "--generate", "Generate models") do
|
@@ -21,18 +22,18 @@ optparse = OptionParser.new do |opts|
|
|
21
22
|
|
22
23
|
options[:overwrite] = false
|
23
24
|
opts.on("-o", "--overwrite",
|
24
|
-
"Overwrite
|
25
|
+
"Overwrite model files (before you do so, back up your models in '~app/models/')") do
|
25
26
|
options[:overwrite] = true
|
26
27
|
end
|
27
28
|
|
28
29
|
options[:dbconfig] = "config/database.yml"
|
29
|
-
opts.on("-d", "--dbconfig
|
30
|
+
opts.on("-d", "--dbconfig PATH",
|
30
31
|
"the path to db config file (default 'config/database.yml')") do |e|
|
31
32
|
options[:environment] = e unless e.nil?
|
32
33
|
end
|
33
34
|
|
34
35
|
options[:environment] = "development"
|
35
|
-
opts.on("-e", "--environment
|
36
|
+
opts.on("-e", "--environment ENVIRONMENT",
|
36
37
|
"from which db config you want to choose, choose from 'development/test/production' (default 'development')") do |e|
|
37
38
|
options[:environment] = e unless e.nil?
|
38
39
|
end
|
@@ -44,7 +45,7 @@ optparse = OptionParser.new do |opts|
|
|
44
45
|
|
45
46
|
opts.on("-v", "--version", "Show version") do |v|
|
46
47
|
puts "rmre version #{Rmre::VERSION} (modified)"
|
47
|
-
puts "ezmodel version #{EZModel::VERSION}"
|
48
|
+
puts "ezmodel(aka:ez_model) version #{EZModel::VERSION}"
|
48
49
|
exit
|
49
50
|
end
|
50
51
|
|
@@ -162,4 +163,4 @@ puts "Generating models in #{options[:model_path]}..."
|
|
162
163
|
EZModel::Generator.CreateModels(options[:model_path], generator.connection.tables, options[:overwrite])
|
163
164
|
|
164
165
|
puts "Congratulations, your schema.rb and all of your models have been generated"
|
165
|
-
puts "Feel free to customize your model in ~/app/models/"
|
166
|
+
puts "Feel free to customize your model in ~/app/models/"
|
data/ez_model.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.name = "ez_model"
|
11
11
|
s.version = ::EZModel::VERSION
|
12
12
|
s.platform = Gem::Platform::RUBY
|
13
|
-
s.date = "2012-04-
|
13
|
+
s.date = "2012-04-16"
|
14
14
|
s.summary = "Rails gem for generating model files in one command line"
|
15
15
|
s.description = "Generate models and schema.rb from existing(legacy) database just in one command line. If you prefer design ER diagram and export scripts to generate database schema, or if you have to work with a legacy database, this can save you insane amount of time. All you need to do is to have a database.yml configuraiton file in ~/config/. Besides creating all models it sets proper table name and primary key if tables and columns naming doesn’t follow Rails convention. It also tries to read all foreign keys data from a database. It uses Rmre as underlying reverse engine to generate models..."
|
16
16
|
|
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.homepage = "http://rubygems.org/gems/ez_model"
|
21
21
|
|
22
22
|
# Dependencies
|
23
|
-
s.required_rubygems_version = ">= 1.
|
23
|
+
#s.required_rubygems_version = ">= 1.8.22"
|
24
24
|
s.add_dependency "activerecord", ">= 3.0.0"
|
25
|
-
s.add_dependency "erubis", "
|
25
|
+
s.add_dependency "erubis", ">= 2.6.6"
|
26
26
|
#s.add_development_dependency "rspec"
|
27
27
|
|
28
28
|
# Files
|
data/lib/ez_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ez_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: 2.6.6
|
38
38
|
type: :runtime
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 2.6.6
|
46
46
|
description: Generate models and schema.rb from existing(legacy) database just in
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
94
94
|
- - ! '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
99
|
rubygems_version: 1.8.22
|