kwatable 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/ChangeLog +46 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.txt +4 -2
  4. data/bin/kwatable +4 -4
  5. data/examples/ex1/Makefile +40 -14
  6. data/examples/ex1/{example1.yaml → tabledef.yaml} +42 -11
  7. data/examples/ex2/Makefile +41 -14
  8. data/examples/ex2/{example2.yaml → tabledef.yaml} +45 -30
  9. data/examples/ex3/Makefile +52 -0
  10. data/examples/ex3/tabledef.yaml +136 -0
  11. data/kwatable.gemspec +11 -10
  12. data/lib/kwatable.rb +24 -18
  13. data/lib/kwatable/kwatable.schema.yaml +95 -5
  14. data/lib/kwatable/main.rb +331 -0
  15. data/lib/kwatable/manipulator.rb +320 -192
  16. data/lib/kwatable/messages.rb +59 -0
  17. data/lib/kwatable/template/ddl-mysql.eruby +202 -0
  18. data/lib/kwatable/{templates → template}/ddl-postgresql.eruby +71 -45
  19. data/lib/kwatable/{templates → template}/defaults.yaml +2 -2
  20. data/lib/kwatable/template/dictionary.en.yaml +70 -0
  21. data/lib/kwatable/template/dictionary.ja.yaml +165 -0
  22. data/lib/kwatable/template/dto-java.eruby +77 -0
  23. data/lib/kwatable/template/dto-java.sub.eruby +259 -0
  24. data/lib/kwatable/template/dto-ruby.eruby +63 -0
  25. data/lib/kwatable/template/dto-ruby.sub.eruby +213 -0
  26. data/lib/kwatable/template/helper/column.rb +70 -0
  27. data/lib/kwatable/template/helper/common.rb +151 -0
  28. data/lib/kwatable/template/helper/java.rb +83 -0
  29. data/lib/kwatable/template/helper/label.rb +90 -0
  30. data/lib/kwatable/template/helper/ruby.rb +36 -0
  31. data/lib/kwatable/template/helper/table.rb +62 -0
  32. data/lib/kwatable/template/hibernate.eruby +139 -0
  33. data/lib/kwatable/template/rails-controller.eruby +66 -0
  34. data/lib/kwatable/template/rails-controller.sub.eruby +114 -0
  35. data/lib/kwatable/template/rails-kwartz.eruby +164 -0
  36. data/lib/kwatable/template/rails-kwartz/_attr.plogic.eruby +56 -0
  37. data/lib/kwatable/template/rails-kwartz/_form.plogic.eruby +81 -0
  38. data/lib/kwatable/template/rails-kwartz/_link.plogic.eruby +36 -0
  39. data/lib/kwatable/template/rails-kwartz/edit.cfg.yaml.eruby +16 -0
  40. data/lib/kwatable/template/rails-kwartz/edit.html.eruby +46 -0
  41. data/lib/kwatable/template/rails-kwartz/edit.plogic.eruby +20 -0
  42. data/lib/kwatable/template/rails-kwartz/layout.html.eruby +39 -0
  43. data/lib/kwatable/template/rails-kwartz/layout.plogic.eruby +32 -0
  44. data/lib/kwatable/template/rails-kwartz/list.html.eruby +94 -0
  45. data/lib/kwatable/template/rails-kwartz/list.plogic.eruby +41 -0
  46. data/lib/kwatable/template/rails-kwartz/new.html.eruby +100 -0
  47. data/lib/kwatable/template/rails-kwartz/new.plogic.eruby +26 -0
  48. data/lib/kwatable/template/rails-kwartz/show.html.eruby +51 -0
  49. data/lib/kwatable/template/rails-kwartz/show.plogic.eruby +9 -0
  50. data/lib/kwatable/template/rails-model.eruby +35 -0
  51. data/lib/kwatable/template/rails-model.sub.eruby +136 -0
  52. data/lib/kwatable/{templates → template}/validator-ruby.eruby +18 -11
  53. data/lib/kwatable/util.rb +133 -0
  54. data/lib/kwatable/util/assert-text-equal.rb +47 -0
  55. data/lib/kwatable/util/assertion.rb +115 -0
  56. data/lib/kwatable/validator.rb +50 -0
  57. data/test/assert-diff.rb +1 -1
  58. data/test/test-ex.rb +306 -0
  59. data/test/test.rb +37 -127
  60. metadata +66 -17
  61. data/COPYING +0 -340
  62. data/ChangeLog.txt +0 -65
  63. data/lib/kwatable/error-msg.rb +0 -38
  64. data/lib/kwatable/main-program.rb +0 -216
  65. data/lib/kwatable/templates/ddl-mysql.eruby +0 -172
  66. data/lib/kwatable/templates/dto-java.eruby +0 -260
  67. data/lib/kwatable/templates/dto-ruby.eruby +0 -185
@@ -0,0 +1,50 @@
1
+ ###
2
+ ### copyright(c) 2005 kuwata-lab.com all rights reserved.
3
+ ### $Release: 0.3.0 $
4
+ ### $Rev: 39 $
5
+ ###
6
+
7
+ require 'kwatable/util'
8
+ require 'yaml'
9
+ require 'kwalify'
10
+
11
+
12
+ module Kwatable
13
+
14
+ class Validator < Kwalify::Validator
15
+
16
+ def validate_hook(value, rule, path, errors) # :nodoc:
17
+ case rule.name
18
+ when 'COLUMN'
19
+ if value['cascade'] && !value['ref']
20
+ msg = "`cascade:' is available only with `ref:'."
21
+ errors << Kwalify::ValidationError.new(msg, path)
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ filename = Util.find_file('kwatable/kwatable.schema.yaml', $LOAD_PATH)
29
+ @@schema = YAML.load_file(filename)
30
+
31
+ ## schema definition
32
+ def self.schema
33
+ return @@schema
34
+ end
35
+
36
+ ## validator
37
+ def self.validate(tabledef, content=nil)
38
+ validator = Validator.new(self.schema)
39
+ errors = validator.validate(tabledef)
40
+ if errors && !errors.empty?
41
+ if content
42
+ parser = Kwalify::YamlParser.new(content)
43
+ parser.parse()
44
+ parser.set_errors_linenum(errors)
45
+ end
46
+ end
47
+ return errors
48
+ end
49
+
50
+ end
@@ -1,6 +1,6 @@
1
1
  ###
2
2
  ### copyright(c) 2005 kuwata-lab.com all rights reserved.
3
- ### $Release: 0.2.0 $
3
+ ### $Release: 0.3.0 $
4
4
  ### $Rev: 10 $
5
5
  ###
6
6
 
@@ -0,0 +1,306 @@
1
+ ###
2
+ ### $Rev: 43 $
3
+ ### $Release: 0.3.0 $
4
+ ### copyright(c) 2005 kuwata-lab.com all rights reserved.
5
+ ###
6
+
7
+ require "#{File.dirname(__FILE__)}/test.rb"
8
+
9
+
10
+ class KwatableExamplesTest < Test::Unit::TestCase
11
+
12
+ DATE_PATTERN = /^.*?at [\w ]+ \d\d:\d\d:\d\d [A-Z]{3} \d\d\d\d\s*$/
13
+
14
+ def _test
15
+ name = (caller().first =~ /in `test_(.*?)'/) && $1
16
+ return if ENV['TEST'] && ENV['TEST'] != name
17
+ name =~ /\A(ex\d)_(\w+)_(\d)\z/
18
+ exdir, tplname, testkind = $1, $2, $3
19
+ @expath ||= "#{EXAMPLES_DIR}/#{exdir}"
20
+ @datafile ||= 'tabledef.yaml'
21
+ @template ||= tplname.gsub(/_/, '-')
22
+ @filenames ||= FILENAMES["#{exdir}/#{@template}"]
23
+ @outdir ||= OUTDIRS[@template]
24
+ @options ||= OPTIONS["#{@template}_#{testkind}"]
25
+ #
26
+ Dir.chdir @expath
27
+ FileUtils.mkdir_p @outdir if @outdir
28
+ #
29
+ argv = ["-f", @template]
30
+ argv.concat @options if @options
31
+ argv.concat ["-d", @outdir] if @outdir
32
+ argv << @datafile
33
+ #$stderr.puts "*** debug: argv=#{argv.inspect}"
34
+ #
35
+ main = Kwatable::Main.new(argv)
36
+ output = main.execute()
37
+ #
38
+ expdir = testkind == '1' ? '.expected' : ".expected#{testkind}"
39
+ if @filenames
40
+ @filenames.each do |expfile|
41
+ expected = File.read("#{expdir}/#{expfile}")
42
+ actual = output ? output.dup : File.read(expfile)
43
+ File.unlink(expfile) if !output && test(?f, expfile)
44
+ actual.sub!(DATE_PATTERN, '')
45
+ expected.sub!(DATE_PATTERN, '')
46
+ assert_text_equal(expected, actual, nil, :prefix=>"*** filename=#{expfile}\n")
47
+ end
48
+ end
49
+ #
50
+ if @outdir
51
+ diff = `diff -ur #{expdir}/#{@outdir} #{@outdir}`
52
+ diff.gsub!(/^.*\.svn\n/, '')
53
+ FileUtils.rm_rf @outdir
54
+ FileUtils.rm_rf "rails" if test(?d, "rails")
55
+ if !diff || diff.empty?
56
+ assert(true)
57
+ else
58
+ flunk(diff)
59
+ end
60
+ end
61
+ end
62
+
63
+
64
+ FILENAMES = {
65
+ 'ex1/ddl-mysql' => %w[ddl-mysql.sql],
66
+ 'ex2/ddl-mysql' => %w[ddl-mysql.sql],
67
+ 'ex3/ddl-mysql' => %w[ddl-mysql.sql],
68
+ 'ex1/ddl-postgresql' => %w[ddl-postgresql.sql],
69
+ 'ex2/ddl-postgresql' => %w[ddl-postgresql.sql],
70
+ 'ex3/ddl-postgresql' => %w[ddl-postgresql.sql],
71
+ 'ex1/dto-java' => %w[Group.java User.java],
72
+ 'ex2/dto-java' => %w[Customer.java Item.java
73
+ SalesOrder.java SalesOrderLine.java], # Address.java
74
+ 'ex3/dto-java' => %w[Department.java Employee.java EmployeeClass.java
75
+ PersonalDatum.java Team.java], # Membership.java
76
+ 'ex1/dto-ruby' => %w[group.rb user.rb],
77
+ 'ex2/dto-ruby' => %w[customer.rb item.rb
78
+ sales_order.rb sales_order_line.rb], # address.rb
79
+ 'ex3/dto-ruby' => %w[department.rb employee.rb employee_class.rb
80
+ personal_datum.rb team.rb], # membership.rb
81
+ }
82
+
83
+ OPTIONS = {
84
+ 'ddl-mysql_1' => nil,
85
+ 'ddl-mysql_2' => %w[--droptable],
86
+ 'ddl-postgresql_1' => nil,
87
+ 'ddl-postgresql_2' => %w[--droptable],
88
+ 'dto-java_1' => %w[-q],
89
+ 'dto-java_2' => %w[-q --package=my.example --parent=Object --populate --constructor],
90
+ 'dto-ruby_1' => %w[-q],
91
+ 'dto-ruby_2' => %w[-q --module=Example --parent=Object --reqpath=lib --populate --symbolkey],
92
+ 'rails-kwartz_1' => %w[-q],
93
+ 'rails-kwartz_2' => %w[-q --lang=ja --charset=UTF8 --stylesheet=site,local --session-token],
94
+ 'rails-model_1' => %w[-q],
95
+ 'rails-model_2' => %w[-q --lang=ja --encoding=UTF8],
96
+ 'rails-controller_1' => %w[-q],
97
+ 'rails-controller_2' => %w[-q --lang=ja --encoding=UTF8 --session-token],
98
+ }
99
+
100
+ OUTDIRS = {
101
+ 'rails-kwartz' => 'rails/views',
102
+ 'rails-model' => 'rails/models',
103
+ 'rails-controller' => 'rails/controllers',
104
+ }
105
+
106
+
107
+ # --------------------
108
+
109
+
110
+ def test_ex1_ddl_mysql_1
111
+ _test
112
+ end
113
+
114
+ def test_ex1_ddl_mysql_2
115
+ _test
116
+ end
117
+
118
+
119
+ def test_ex1_ddl_postgresql_1
120
+ _test
121
+ end
122
+
123
+ def test_ex1_ddl_postgresql_2
124
+ _test
125
+ end
126
+
127
+
128
+ def test_ex1_dto_java_1
129
+ _test
130
+ end
131
+
132
+ def test_ex1_dto_java_2
133
+ _test
134
+ end
135
+
136
+
137
+ def test_ex1_dto_ruby_1
138
+ _test
139
+ end
140
+
141
+ def test_ex1_dto_ruby_2
142
+ _test
143
+ end
144
+
145
+
146
+ def test_ex1_rails_kwartz_1
147
+ _test
148
+ end
149
+
150
+ def test_ex1_rails_kwartz_2
151
+ _test
152
+ end
153
+
154
+
155
+ def test_ex1_rails_model_1
156
+ _test
157
+ end
158
+
159
+ def test_ex1_rails_model_2
160
+ _test
161
+ end
162
+
163
+
164
+ def test_ex1_rails_controller_1
165
+ _test
166
+ end
167
+
168
+ def test_ex1_rails_controller_2
169
+ _test
170
+ end
171
+
172
+
173
+ ## --------------------
174
+
175
+
176
+ def test_ex2_ddl_mysql_1
177
+ _test
178
+ end
179
+
180
+ def test_ex2_ddl_mysql_2
181
+ _test
182
+ end
183
+
184
+
185
+ def test_ex2_ddl_postgresql_1
186
+ _test
187
+ end
188
+
189
+ def test_ex2_ddl_postgresql_2
190
+ _test
191
+ end
192
+
193
+
194
+ def test_ex2_dto_java_1
195
+ _test
196
+ end
197
+
198
+ def test_ex2_dto_java_2
199
+ _test
200
+ end
201
+
202
+
203
+ def test_ex2_dto_ruby_1
204
+ _test
205
+ end
206
+
207
+ def test_ex2_dto_ruby_2
208
+ _test
209
+ end
210
+
211
+
212
+ def test_ex2_rails_kwartz_1
213
+ _test
214
+ end
215
+
216
+ def test_ex2_rails_kwartz_2
217
+ _test
218
+ end
219
+
220
+
221
+ def test_ex2_rails_model_1
222
+ _test
223
+ end
224
+
225
+ def test_ex2_rails_model_2
226
+ _test
227
+ end
228
+
229
+
230
+ def test_ex2_rails_controller_1
231
+ _test
232
+ end
233
+
234
+ def test_ex2_rails_controller_2
235
+ _test
236
+ end
237
+
238
+
239
+ ## --------------------
240
+
241
+
242
+ def test_ex3_ddl_mysql_1
243
+ _test
244
+ end
245
+
246
+ def test_ex3_ddl_mysql_2
247
+ _test
248
+ end
249
+
250
+
251
+ def test_ex3_ddl_postgresql_1
252
+ _test
253
+ end
254
+
255
+ def test_ex3_ddl_postgresql_2
256
+ _test
257
+ end
258
+
259
+
260
+ def test_ex3_dto_java_1
261
+ _test
262
+ end
263
+
264
+ def test_ex3_dto_java_2
265
+ _test
266
+ end
267
+
268
+
269
+ def test_ex3_dto_ruby_1
270
+ _test
271
+ end
272
+
273
+ def test_ex3_dto_ruby_2
274
+ _test
275
+ end
276
+
277
+ #
278
+ # def test_ex3_rails_kwartz_1
279
+ # _test
280
+ # end
281
+ #
282
+ # def test_ex3_rails_kwartz_2
283
+ # _test
284
+ # end
285
+ #
286
+ #
287
+ # def test_ex3_rails_model_1
288
+ # _test
289
+ # end
290
+ #
291
+ # def test_ex3_rails_model_2
292
+ # _test
293
+ # end
294
+ #
295
+ #
296
+ # def test_ex3_rails_controller_1
297
+ # _test
298
+ # end
299
+ #
300
+ # def test_ex3_rails_controller_2
301
+ # _test
302
+ # end
303
+ #
304
+
305
+
306
+ end
@@ -1,138 +1,48 @@
1
1
  ###
2
+ ### $Rev: 36 $
3
+ ### $Release: 0.3.0 $
2
4
  ### copyright(c) 2005 kuwata-lab.com all rights reserved.
3
- ### $Release: 0.2.0 $
4
- ### $Rev: 17 $
5
5
  ###
6
6
 
7
7
  unless defined?(BASE_DIR)
8
- TEST_DIR = File.expand_path(File.dirname(__FILE__))
9
- BASE_DIR = File.dirname(TEST_DIR)
10
- LIB_DIR = BASE_DIR + "/lib"
11
- BIN_DIR = BASE_DIR + "/bin"
12
- EXAMPLES_DIR = BASE_DIR + "/examples"
13
- $LOAD_PATH << LIB_DIR << TEST_DIR
8
+ TEST_DIR = File.expand_path(File.dirname(__FILE__))
9
+ BASE_DIR = File.dirname(TEST_DIR)
10
+ LIB_DIR = BASE_DIR + "/lib"
11
+ BIN_DIR = BASE_DIR + "/bin"
12
+ EXAMPLES_DIR = BASE_DIR + "/examples"
13
+ $LOAD_PATH << LIB_DIR # << TEST_DIR
14
+
15
+ sep = File::PATH_SEPARATOR
16
+ ENV['RUBYLIB'] = LIB_DIR
17
+ ENV['PATH'] = "#{BIN_DIR}#{sep}#{ENV['PATH']}"
18
+ #puts ENV['PATH']
19
+ #puts `kwatable -h`
20
+ #exit 0
21
+
22
+ require 'test/unit'
23
+ #require 'test/unit/ui/console/testrunner'
24
+
25
+ require 'kwatable'
26
+ require 'kwatable/main'
27
+ require 'kwatable/util/assert-text-equal'
28
+ require 'fileutils'
29
+
30
+
31
+ class Test::Unit::TestCase # :nodoc:
32
+ def assert_file_equal(expected_filename, actual_filename, message=nil, options={}) # :nodoc:
33
+ diffopt = options[:diffopt] || '-u'
34
+ flag_cut = options.key?(:cut) ? options[:key] : false
35
+ diff = `diff #{diffopt} #{expfile.path} #{actfile.path}`
36
+ diff.sub!(/\A.*\n.*\n/, '') if flag_cut # cut 1st & 2nd lines
37
+ assert_block(message || diff) { false } # or assert(false, message || diff)
38
+ end
39
+ end
40
+
14
41
 
15
- ENV['RUBYLIB'] = LIB_DIR
16
- ENV['PATH'] = "#{BIN_DIR}:#{ENV['PATH']}"
17
- #puts ENV['PATH']
18
- #puts `kwatable -h`
19
- #exit 0
20
42
  end
21
43
  Dir.chdir TEST_DIR
22
44
 
23
45
 
24
- require 'test/unit'
25
- require 'test/unit/ui/console/testrunner'
26
-
27
- require 'kwatable.rb'
28
- require 'kwatable/main-program'
29
- require 'assert-diff'
30
-
31
-
32
-
33
- DATE_PATTERN = /^.*?at [\w ]+ \d\d:\d\d:\d\d [A-Z]{3} \d\d\d\d\s*$/
34
-
35
- class ExampleTest < Test::Unit::TestCase
36
-
37
-
38
- def _test
39
- #Dir.chdir TEST_DIR
40
- Dir.chdir @dir
41
- argv = ["-f", @template]
42
- argv.concat @options if @options
43
- argv << @datafile
44
- main = Kwatable::MainProgram.new(argv)
45
- output = main.execute()
46
- @expfiles.each do |expfile|
47
- expected = File.read(".expected/#{expfile}")
48
- actual = output ? output.dup : File.read(expfile)
49
- actual.sub!(DATE_PATTERN, '')
50
- expected.sub!(DATE_PATTERN, '')
51
- assert_equal_with_diff(expected, actual)
52
- end
53
- end
54
-
55
-
56
- def test_ex1_mysql
57
- @dir = "#{EXAMPLES_DIR}/ex1"
58
- @template = 'ddl-mysql.eruby'
59
- @datafile = 'example1.yaml'
60
- @expfiles = %w[ddl-mysql.sql]
61
- _test
62
- end
63
-
64
-
65
- def test_ex1_postgresql
66
- @dir = "#{EXAMPLES_DIR}/ex1"
67
- @template = 'ddl-postgresql.eruby'
68
- @datafile = 'example1.yaml'
69
- @expfiles = %w[ddl-postgresql.sql]
70
- _test
71
- end
72
-
73
-
74
- def test_ex1_java
75
- @dir = "#{EXAMPLES_DIR}/ex1"
76
- @template = 'dto-java.eruby'
77
- @datafile = 'example1.yaml'
78
- @expfiles = %w[Group.java User.java]
79
- @options = %w[-qm --package=my.example --parent=Object --populate --constructor]
80
- begin
81
- _test
82
- ensure
83
- @expfiles.each { |filename| File.unlink(filename) }
84
- end
85
- end
86
-
87
-
88
- def test_ex1_ruby
89
- @dir = "#{EXAMPLES_DIR}/ex1"
90
- @template = 'dto-ruby.eruby'
91
- @datafile = 'example1.yaml'
92
- @expfiles = %w[Group.rb User.rb]
93
- @options = %w[-qm --module=Example --parent=Object --reqpath=lib --populate --symbolkey]
94
- begin
95
- _test
96
- ensure
97
- @expfiles.each { |filename| File.unlink(filename) }
98
- end
99
- end
100
-
101
-
102
- ##---
103
-
104
-
105
- def test_ex2_mysql
106
- @dir = "#{EXAMPLES_DIR}/ex2"
107
- @template = 'ddl-mysql.eruby'
108
- @datafile = 'example2.yaml'
109
- @expfiles = %w[ddl-mysql.sql]
110
- _test
111
- end
112
-
113
-
114
- def test_ex2_postgresql
115
- @dir = "#{EXAMPLES_DIR}/ex2"
116
- @template = 'ddl-postgresql.eruby'
117
- @datafile = 'example2.yaml'
118
- @expfiles = %w[ddl-postgresql.sql]
119
- _test
120
- end
121
-
122
-
123
- def test_ex2_java
124
- @dir = "#{EXAMPLES_DIR}/ex2"
125
- @template = 'dto-java.eruby'
126
- @datafile = 'example2.yaml'
127
- @expfiles = %w[Address.java Customer.java Item.java SalesOrder.java SalesOrderLine.java]
128
- @options = %w[-qm --package=my.example --parent=Object --populate --constructor]
129
- begin
130
- _test
131
- ensure
132
- @expfiles.each { |filename| File.unlink(filename) if test(?f, filename)}
133
- end
134
- end
135
-
136
-
46
+ if $0 == __FILE__
47
+ require 'test-ex'
137
48
  end
138
-