oracle-model-generator 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -0
- data/README +11 -7
- data/bin/omg +19 -11
- data/lib/oracle/model/generator.rb +1 -1
- data/oracle-model-generator.gemspec +1 -1
- data/test/test_oracle_model_generator.rb +1 -1
- metadata +11 -13
data/CHANGES
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
= 0.3.1 - 3-Apr-2012
|
2
|
+
* Added the --class option that allows you to specify the model name on the
|
3
|
+
command line. Thanks go to Daniel Luna for the patch (plus some minor fixes).
|
4
|
+
|
1
5
|
= 0.3.0 - 12-May-2011
|
2
6
|
* Added automatic test generation. In addition to the active record model file,
|
3
7
|
a test file will be generated that includes a series of stock tests that
|
data/README
CHANGED
@@ -7,11 +7,11 @@ Using the command line tool:
|
|
7
7
|
|
8
8
|
omg -d your_database -t locations -u some_user -p some_password
|
9
9
|
|
10
|
-
|
11
|
-
declaration, with all validations, primary keys,
|
12
|
-
relationships defined.
|
10
|
+
The above command results in a file called "location.rb". This is an
|
11
|
+
ActiveRecord model declaration, with all validations, primary keys,
|
12
|
+
table name and belongs_to relationships defined.
|
13
13
|
|
14
|
-
If your
|
14
|
+
If your LOCATIONS table looks like this:
|
15
15
|
|
16
16
|
create table locations(
|
17
17
|
location_id number(4,0) primary key,
|
@@ -26,7 +26,7 @@ If your locations table looks like this:
|
|
26
26
|
|
27
27
|
The omg library will generate this:
|
28
28
|
|
29
|
-
class
|
29
|
+
class Location < ActiveRecord::Base
|
30
30
|
set_table_name :locations
|
31
31
|
set_primary_key :location_id
|
32
32
|
|
@@ -111,7 +111,8 @@ application.
|
|
111
111
|
I also do not go out of my way to get the model name correct with regards
|
112
112
|
to singular vs plural. I do a simple guess that covers most cases, but
|
113
113
|
complex cases will break it. It's much easier for you to rename a class or
|
114
|
-
file name than it is for me to get this 100% correct.
|
114
|
+
file name than it is for me to get this 100% correct. As of 0.3.1 there's
|
115
|
+
also the --class option that let's you eplicitly set it if you like.
|
115
116
|
|
116
117
|
= Author's Comments
|
117
118
|
I chose not to patch legacy_data because I have no interest in supporting
|
@@ -126,6 +127,9 @@ Add automatic test suite generation for rspec.
|
|
126
127
|
Explicitly set :foreign_key if using CPK in belongs_to relationships.
|
127
128
|
The output could use a little formatting love.
|
128
129
|
|
130
|
+
= Acknowlegements
|
131
|
+
Thanks go to Daniel Luna for his --class patch.
|
132
|
+
|
129
133
|
= Known Issues
|
130
134
|
None known. If you find any issues, please report them on the github project
|
131
135
|
page at http://www.github.com/djberg96/oracle-model-generator.
|
@@ -136,7 +140,7 @@ implied warranties, including, without limitation, the implied
|
|
136
140
|
warranties of merchantability and fitness for a particular purpose.
|
137
141
|
|
138
142
|
= Copyright
|
139
|
-
(C) 2010
|
143
|
+
(C) 2010-2012 Daniel J. Berger
|
140
144
|
All Rights Reserved
|
141
145
|
|
142
146
|
= License
|
data/bin/omg
CHANGED
@@ -11,6 +11,7 @@ rescue LoadError
|
|
11
11
|
end
|
12
12
|
|
13
13
|
opts = Getopt::Long.getopts(
|
14
|
+
|
14
15
|
['--help', '-h'],
|
15
16
|
['--table', '-t', Getopt::REQUIRED],
|
16
17
|
['--view', '-v', Getopt::REQUIRED],
|
@@ -19,7 +20,8 @@ opts = Getopt::Long.getopts(
|
|
19
20
|
['--database', '-d', Getopt::REQUIRED],
|
20
21
|
['--output', '-o', Getopt::REQUIRED],
|
21
22
|
['--rails', '-r', Getopt::REQUIRED],
|
22
|
-
['--tests',
|
23
|
+
['--tests', '-x', Getopt::OPTIONAL],
|
24
|
+
['--class', '-c', Getopt::OPTIONAL]
|
23
25
|
)
|
24
26
|
|
25
27
|
def help
|
@@ -35,6 +37,7 @@ def help
|
|
35
37
|
-p, --password => The password used to establish a connection to the database.
|
36
38
|
-r, --rails => The version of rails you're using (2 or 3).
|
37
39
|
-x, --tests => Generate tests (the default).
|
40
|
+
-c, --class => Class name for the generated table (optional)
|
38
41
|
|
39
42
|
If no user or password are supplied, then OMG will attempt to glean that
|
40
43
|
information using a combination of the database name and your .dbrc file.
|
@@ -130,16 +133,18 @@ if rails < 2 || rails > 3
|
|
130
133
|
puts "Invalid version of Rails. Specify either 2 or 3."
|
131
134
|
exit!
|
132
135
|
end
|
136
|
+
|
137
|
+
omg.instance_eval { @model = opts['class'] } if opts['class'] # dirty fix
|
133
138
|
|
134
139
|
File.open(ofile, 'w') do |fh|
|
135
140
|
fh.puts "class #{omg.model} < ActiveRecord::Base"
|
136
|
-
fh.puts " set_table_name
|
141
|
+
fh.puts " set_table_name :\"#{table}\""
|
137
142
|
|
138
143
|
if omg.primary_keys.size > 1
|
139
144
|
fh.puts "\n # Requires the composite-primary-keys library"
|
140
145
|
fh.puts " set_primary_keys " + omg.primary_keys.inspect
|
141
146
|
else
|
142
|
-
fh.puts "\n set_primary_key " + omg.primary_keys.first.to_sym.inspect
|
147
|
+
fh.puts "\n set_primary_key " + omg.primary_keys.first.to_sym.inspect unless omg.primary_keys.first.nil?
|
143
148
|
end
|
144
149
|
|
145
150
|
fh.puts "\n # Table relationships\n\n"
|
@@ -213,21 +218,24 @@ File.open(ofile, 'w') do |fh|
|
|
213
218
|
max = "9" * col.precision
|
214
219
|
max.insert(col.precision - col.scale, ".") if col.scale > 0
|
215
220
|
|
216
|
-
validation = "\n validates :#{col.name.downcase}
|
221
|
+
validation = "\n validates :#{col.name.downcase}"
|
217
222
|
|
218
223
|
unless col.nullable?
|
219
|
-
validation << ":presence => #{!col.nullable?}
|
224
|
+
validation << ", :presence => #{!col.nullable?}"
|
220
225
|
end
|
221
226
|
|
222
|
-
|
223
|
-
|
224
|
-
|
227
|
+
unless max.empty?
|
228
|
+
validation << ", :numericality => {"
|
229
|
+
validation << "\n :less_than_or_equal_to => #{max}, "
|
230
|
+
validation << "\n :greater_than_or_equal_to => -#{max}"
|
231
|
+
|
232
|
+
if col.scale == 0
|
233
|
+
validation << ",\n :only_integer => true"
|
234
|
+
end
|
225
235
|
|
226
|
-
|
227
|
-
validation << ",\n :only_integer => true"
|
236
|
+
validation << "\n }\n\n"
|
228
237
|
end
|
229
238
|
|
230
|
-
validation << "\n }\n\n"
|
231
239
|
end
|
232
240
|
|
233
241
|
fh.puts " #{validation}"
|
@@ -20,7 +20,7 @@ class TC_Oracle_Model_Generator < Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
test "version number is correct" do
|
23
|
-
assert_equal('0.3.
|
23
|
+
assert_equal('0.3.1', Oracle::Model::Generator::VERSION)
|
24
24
|
end
|
25
25
|
|
26
26
|
test "constructor accepts an oci8 connection object" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oracle-model-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel J. Berger
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2012-04-03 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: ruby-oci8
|
@@ -75,16 +74,15 @@ extra_rdoc_files:
|
|
75
74
|
- README
|
76
75
|
- MANIFEST
|
77
76
|
files:
|
78
|
-
-
|
79
|
-
-
|
80
|
-
- oracle-model-generator.gemspec
|
77
|
+
- bin/omg
|
78
|
+
- CHANGES
|
81
79
|
- lib/oracle/model/generator.rb
|
82
80
|
- lib/oracle_model_generator.rb
|
83
|
-
- CHANGES
|
84
|
-
- test/test_oracle_model_generator.rb
|
85
81
|
- MANIFEST
|
86
|
-
-
|
87
|
-
|
82
|
+
- oracle-model-generator.gemspec
|
83
|
+
- Rakefile
|
84
|
+
- README
|
85
|
+
- test/test_oracle_model_generator.rb
|
88
86
|
homepage: http://www.github.com/djberg96/oracle-model-generator
|
89
87
|
licenses:
|
90
88
|
- Artistic 2.0
|
@@ -114,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
112
|
requirements: []
|
115
113
|
|
116
114
|
rubyforge_project: N/A
|
117
|
-
rubygems_version: 1.
|
115
|
+
rubygems_version: 1.8.10
|
118
116
|
signing_key:
|
119
117
|
specification_version: 3
|
120
118
|
summary: A Ruby interface for determining protocol information
|