kwatable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/COPYING +340 -0
  2. data/ChangeLog.txt +27 -0
  3. data/README.txt +81 -0
  4. data/bin/kwatable +20 -0
  5. data/examples/ex1/Makefile +34 -0
  6. data/examples/ex1/example1.yaml +85 -0
  7. data/examples/ex2/Makefile +34 -0
  8. data/examples/ex2/example2.yaml +94 -0
  9. data/kwatable.gemspec +48 -0
  10. data/lib/kwatable.rb +31 -0
  11. data/lib/kwatable/error-msg.rb +37 -0
  12. data/lib/kwatable/kwatable.schema.yaml +133 -0
  13. data/lib/kwatable/main-program.rb +197 -0
  14. data/lib/kwatable/manufactory.rb +213 -0
  15. data/lib/kwatable/templates/ddl-mysql.eruby +169 -0
  16. data/lib/kwatable/templates/ddl-postgresql.eruby +153 -0
  17. data/lib/kwatable/templates/defaults.yaml +87 -0
  18. data/lib/kwatable/templates/dto-java.eruby +204 -0
  19. data/lib/kwatable/templates/dto-ruby.eruby +180 -0
  20. data/setup.rb +1331 -0
  21. data/test/assert-diff.rb +44 -0
  22. data/test/test.rb +202 -0
  23. data/test/test1/test1.ddl-mysql.expected +22 -0
  24. data/test/test1/test1.ddl-postgresql.expected +22 -0
  25. data/test/test1/test1.dto-java.Group.expected +32 -0
  26. data/test/test1/test1.dto-java.User.expected +59 -0
  27. data/test/test1/test1.dto-ruby.Group.expected +21 -0
  28. data/test/test1/test1.dto-ruby.User.expected +36 -0
  29. data/test/test1/test1.yaml +85 -0
  30. data/test/test2/test2.ddl-mysql.expected +49 -0
  31. data/test/test2/test2.ddl-postgresql.expected +49 -0
  32. data/test/test2/test2.dto-java.Address.expected +42 -0
  33. data/test/test2/test2.dto-java.Customer.expected +49 -0
  34. data/test/test2/test2.dto-java.Item.expected +37 -0
  35. data/test/test2/test2.dto-java.SalesOrder.expected +50 -0
  36. data/test/test2/test2.dto-java.SalesOrderLine.expected +56 -0
  37. data/test/test2/test2.dto-ruby.Address.expected +25 -0
  38. data/test/test2/test2.dto-ruby.Customer.expected +32 -0
  39. data/test/test2/test2.dto-ruby.Item.expected +23 -0
  40. data/test/test2/test2.dto-ruby.SalesOrder.expected +32 -0
  41. data/test/test2/test2.dto-ruby.SalesOrderLine.expected +39 -0
  42. data/test/test2/test2.yaml +94 -0
  43. metadata +91 -0
@@ -0,0 +1,44 @@
1
+ ###
2
+ ### copyright(c) 2005 kuwata-lab.com all rights reserved.
3
+ ### $Release: 0.0.1 $
4
+ ### $Rev: 10 $
5
+ ###
6
+
7
+ require 'test/unit'
8
+ require 'tempfile'
9
+
10
+ module Test
11
+ module Unit
12
+ class TestCase
13
+ def assert_equal_with_diff(expected, actual, message=nil, diffopt='-u', flag_cut=true)
14
+ if expected == actual
15
+ assert(true)
16
+ return
17
+ end
18
+
19
+ if expected[-1] != ?\n || actual[-1] != ?\n
20
+ expected += "\n"
21
+ actual += "\n"
22
+ end
23
+ begin
24
+ expfile = Tempfile.new(".expected.")
25
+ expfile.write(expected); expfile.flush()
26
+ actfile = Tempfile.new(".actual.")
27
+ actfile.write(actual); actfile.flush()
28
+ diff = `diff #{diffopt} #{expfile.path} #{actfile.path}`
29
+ ensure
30
+ expfile.close(true) if expfile
31
+ actfile.close(true) if actfile
32
+ end
33
+
34
+ # cut 1st & 2nd lines
35
+ message = (flag_cut ? diff.gsub(/\A.*\n.*\n/, '') : diff) unless message
36
+ #raise Test::Unit::AssertionFailedError.new(message)
37
+ assert_block(message) { false } # or assert(false, message)
38
+ end
39
+ #def assert_equal(expected, actual, message=nil)
40
+ # return assert_equal_with_diff(expected, actual, message)
41
+ #end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,202 @@
1
+ ###
2
+ ### copyright(c) 2005 kuwata-lab.com all rights reserved.
3
+ ### $Release: 0.0.1 $
4
+ ### $Rev: 11 $
5
+ ###
6
+
7
+ dir = Dir.pwd
8
+ dir = File.dirname(dir) if File.basename(dir) == 'test'
9
+
10
+ BASE_DIR = dir
11
+ TEST_DIR = "#{BASE_DIR}/test"
12
+ LIB_DIR = "#{BASE_DIR}/lib"
13
+ EXAMPLES_DIR = "#{BASE_DIR}/examples"
14
+
15
+ Dir.chdir(TEST_DIR)
16
+
17
+ $: << LIB_DIR
18
+ $: << TEST_DIR
19
+
20
+ ENV['RUBYLIB'] = LIB_DIR
21
+
22
+ require 'test/unit'
23
+ require 'test/unit/ui/console/testrunner'
24
+
25
+ require 'kwatable.rb'
26
+ require 'assert-diff'
27
+
28
+
29
+ class KwatableExampleTest < Test::Unit::TestCase
30
+
31
+ def _test(options={})
32
+ optstr = "#{@option}"
33
+ if options[:multiple] # or if @classnames
34
+ outdir = prefix()
35
+ optstr << " -smd #{outdir}"
36
+ end
37
+ cmd = "kwatable -f #{@template} #{optstr} #{@datafile}"
38
+ #cmd = "kwatable -I #{BASE_DIR}/templates -f #{@template} #{optstr} #{@datafile}"
39
+ $logger.write("- command: #{cmd}\n thread: #{Thread.current.__id__}\n timestamp: #{Time.new.to_s}\n")
40
+ #$stderr.puts "*** debug: cmd=#{cmd.inspect}"
41
+ actual = `#{cmd}`
42
+ if @classnames
43
+ actuals = {}
44
+ @classnames.each do |classname|
45
+ actual = File.read(@output % classname)
46
+ File.unlink(@output % classname)
47
+ if options[:ignore_linenum]
48
+ actual = _ignore_line(actual, options[:ignore_linenum])
49
+ end
50
+ actuals[classname] = actual
51
+ File.open(@actual % classname, 'w') { |f| f.write(actual) }
52
+ end
53
+ @classnames.each do |classname|
54
+ actual = actuals[classname]
55
+ expected = File.read(@expected % classname)
56
+ assert_equal_with_diff(expected, actual)
57
+ end
58
+ else
59
+ if options[:ignore_linenum]
60
+ actual = _ignore_line(actual, options[:ignore_linenum])
61
+ end
62
+ File.open(@actual, 'w') { |f| f.write(actual) }
63
+ expected = File.open(@expected) { |f| f.read() }
64
+ assert_equal_with_diff(expected, actual)
65
+ end
66
+ end
67
+
68
+ def prefix
69
+ raise NotImplementedError.new("#{self.class.name}#prefix() is not implemented.")
70
+ end
71
+
72
+ def classnames
73
+ raise NotImplementedError.new("#{self.class.name}#classnames() is not implemented.")
74
+ end
75
+
76
+
77
+ def _ignore_line(str, linenum)
78
+ s = ''
79
+ i = 0
80
+ str.each_line do |line|
81
+ i += 1
82
+ s << line if i != linenum
83
+ end
84
+ return s
85
+ end
86
+
87
+ def _setup_ddl(basename)
88
+ dir = prefix()
89
+ @datafile = "#{dir}/#{prefix()}.yaml"
90
+ @template = "#{basename}.eruby"
91
+ @actual = "#{dir}/#{prefix()}.#{basename}.actual"
92
+ @expected = "#{dir}/#{prefix()}.#{basename}.expected"
93
+ end
94
+
95
+ def _setup_dto(basename, suffix)
96
+ dir = prefix()
97
+ @datafile = "#{dir}/#{prefix()}.yaml"
98
+ @template = "#{basename}.eruby"
99
+ @actual = "#{dir}/#{prefix()}.#{basename}.%s.actual"
100
+ @expected = "#{dir}/#{prefix()}.#{basename}.%s.expected"
101
+ @classnames = classnames()
102
+ @output = "#{dir}/%s#{suffix}"
103
+ end
104
+
105
+ end
106
+
107
+
108
+ class KwatableExample1Test < KwatableExampleTest
109
+
110
+ def prefix
111
+ return 'test1'
112
+ end
113
+
114
+ def classnames
115
+ return %w[Group User]
116
+ end
117
+
118
+
119
+ def test1_ddl_mysql
120
+ #@datafile = "test1.yaml"
121
+ #@template = "ddl-mysql.eruby"
122
+ #@actual = "test1.ddl-mysql.actual"
123
+ #@expected = "test1.ddl-mysql.expected"
124
+ _setup_ddl('ddl-mysql')
125
+ _test(:ignore_linenum=>4)
126
+ end
127
+
128
+ def test1_ddl_postgresql
129
+ #@datafile = "test1.yaml"
130
+ #@template = "ddl-postgresql.eruby"
131
+ #@actual = "test1.ddl-postgresql.actual"
132
+ #@expected = "test1.ddl-postgresql.expected"
133
+ _setup_ddl('ddl-postgresql')
134
+ _test(:ignore_linenum=>4)
135
+ end
136
+
137
+ def test1_dto_java
138
+ #@datafile = "test1.yaml"
139
+ #@template = "dto-java.eruby"
140
+ #@actual = "test1.dto-java.%s.actual"
141
+ #@expected = "test1.dto-java.%s.expected"
142
+ #@classnames = dto_classes()
143
+ #@output = "%s.java"
144
+ _setup_dto('dto-java', '.java')
145
+ _test(:ignore_linenum=>4, :multiple=>true)
146
+ end
147
+
148
+ def test1_dto_ruby
149
+ #@datafile = "#test1.yaml"
150
+ #@template = "dto-ruby.eruby"
151
+ #@actual = "test1.dto-ruby.%s.actual"
152
+ #@expected = "test1.dto-ruby.%s.expected"
153
+ #@classnames = dto_classes()
154
+ #@output = "%s.rb"
155
+ _setup_dto('dto-ruby', '.rb')
156
+ _test(:ignore_linenum=>4, :multiple=>true)
157
+ end
158
+
159
+ end
160
+
161
+
162
+ class KwatableExample2Test < KwatableExampleTest
163
+
164
+ def prefix
165
+ return 'test2'
166
+ end
167
+
168
+ def classnames
169
+ return %w[Address Customer Item SalesOrder SalesOrderLine]
170
+ end
171
+
172
+
173
+ def test2_ddl_mysql
174
+ _setup_ddl('ddl-mysql')
175
+ _test(:ignore_linenum=>4)
176
+ end
177
+
178
+ def test2_ddl_postgresql
179
+ _setup_ddl('ddl-postgresql')
180
+ _test(:ignore_linenum=>4)
181
+ end
182
+
183
+ def test2_dto_java
184
+ _setup_dto('dto-java', '.java')
185
+ _test(:ignore_linenum=>4, :multiple=>true)
186
+ end
187
+
188
+ def test2_dto_ruby
189
+ _setup_dto('dto-ruby', '.rb')
190
+ _test(:ignore_linenum=>4, :multiple=>true)
191
+ end
192
+
193
+ end
194
+
195
+
196
+ File.open('test.log', 'a') do |f|
197
+ $logger = f
198
+ suite = Test::Unit::TestSuite.new()
199
+ suite << KwatableExample1Test.suite()
200
+ suite << KwatableExample2Test.suite()
201
+ Test::Unit::UI::Console::TestRunner.run(suite)
202
+ end
@@ -0,0 +1,22 @@
1
+ ----------------------------------------------------------------------
2
+ -- DDL for MySQL
3
+ -- generated by kwatable with template 'ddl-mysql.eruby'
4
+ ----------------------------------------------------------------------
5
+
6
+ -- Group master table
7
+ create table groups (
8
+ id integer auto_increment primary key,
9
+ name varchar(63) not null,
10
+ `desc` varchar(255)
11
+ );
12
+
13
+ -- User master table
14
+ create table users (
15
+ id integer auto_increment primary key,
16
+ name varchar(63) not null,
17
+ `desc` varchar(255) ,
18
+ email varchar(63) ,
19
+ group_id integer , -- references groups.id
20
+ account varchar(31) not null,
21
+ password varchar(31) not null
22
+ );
@@ -0,0 +1,22 @@
1
+ ----------------------------------------------------------------------
2
+ -- DDL for PostgreSQL
3
+ -- generated by kwatable with template 'ddl-postgresql.eruby'
4
+ ----------------------------------------------------------------------
5
+
6
+ -- Group master table
7
+ create table groups (
8
+ id serial primary key,
9
+ name varchar(63) not null,
10
+ "desc" varchar(255)
11
+ );
12
+
13
+ -- User master table
14
+ create table users (
15
+ id serial primary key,
16
+ name varchar(63) not null,
17
+ "desc" varchar(255) ,
18
+ email varchar(63) ,
19
+ group_id integer references groups(id),
20
+ account varchar(31) not null,
21
+ password varchar(31) not null
22
+ );
@@ -0,0 +1,32 @@
1
+ /*
2
+ * DTO for Java
3
+ * generated by kwatable with template 'dto-java.eruby'
4
+ */
5
+
6
+ /**
7
+ * Group master table
8
+ */
9
+ public class Group implements java.io.Serializable {
10
+
11
+ private int id; /* */
12
+ private String name; /* */
13
+ private String desc; /* */
14
+
15
+ public Group(int id, String name, String desc) {
16
+ this.id = id;
17
+ this.name = name;
18
+ this.desc = desc;
19
+ }
20
+
21
+ public int getId() { return id }
22
+ public void setId(int id) { this.id = id; }
23
+
24
+ public String getName() { return name }
25
+ public void setName(String name) { this.name = name; }
26
+
27
+ public String getDesc() { return desc }
28
+ public void setDesc(String desc) { this.desc = desc; }
29
+
30
+ // -----------
31
+
32
+ }
@@ -0,0 +1,59 @@
1
+ /*
2
+ * DTO for Java
3
+ * generated by kwatable with template 'dto-java.eruby'
4
+ */
5
+
6
+ /**
7
+ * User master table
8
+ */
9
+ public class User implements java.io.Serializable {
10
+
11
+ private int id; /* */
12
+ private String name; /* */
13
+ private String desc; /* */
14
+ private String email; /* */
15
+ private int group_id; /* */
16
+ private String account; /* */
17
+ private String password; /* */
18
+
19
+ public User(int id, String name, String desc, String email, int group_id, String account, String password) {
20
+ this.id = id;
21
+ this.name = name;
22
+ this.desc = desc;
23
+ this.email = email;
24
+ this.group_id = group_id;
25
+ this.account = account;
26
+ this.password = password;
27
+ }
28
+
29
+ public int getId() { return id }
30
+ public void setId(int id) { this.id = id; }
31
+
32
+ public String getName() { return name }
33
+ public void setName(String name) { this.name = name; }
34
+
35
+ public String getDesc() { return desc }
36
+ public void setDesc(String desc) { this.desc = desc; }
37
+
38
+ public String getEmail() { return email }
39
+ public void setEmail(String email) { this.email = email; }
40
+
41
+ public int getGroupId() { return group_id }
42
+ public void setGroupId(int group_id) { this.group_id = group_id; }
43
+
44
+ public String getAccount() { return account }
45
+ public void setAccount(String account) { this.account = account; }
46
+
47
+ public String getPassword() { return password }
48
+ public void setPassword(String password) { this.password = password; }
49
+
50
+ // -----------
51
+
52
+ private Group group;
53
+ public Group getGroup() { return group; }
54
+ public void setGroup(Group group) {
55
+ this.group = group;
56
+ this.group_id = group.getId();
57
+ }
58
+
59
+ }
@@ -0,0 +1,21 @@
1
+ ##
2
+ ## DTO for Ruby
3
+ ## generated by kwatable with template 'dto-ruby.eruby'
4
+ ##
5
+
6
+ ## Group master table
7
+ class Group
8
+
9
+ def initialize(id, name, desc)
10
+ @id = id
11
+ @name = name
12
+ @desc = desc
13
+ end
14
+
15
+ attr_accessor :id #
16
+ attr_accessor :name #
17
+ attr_accessor :desc #
18
+
19
+ // -----------
20
+
21
+ end
@@ -0,0 +1,36 @@
1
+ ##
2
+ ## DTO for Ruby
3
+ ## generated by kwatable with template 'dto-ruby.eruby'
4
+ ##
5
+ require 'Group'
6
+
7
+ ## User master table
8
+ class User
9
+
10
+ def initialize(id, name, desc, email, group_id, account, password)
11
+ @id = id
12
+ @name = name
13
+ @desc = desc
14
+ @email = email
15
+ @group_id = group_id
16
+ @account = account
17
+ @password = password
18
+ end
19
+
20
+ attr_accessor :id #
21
+ attr_accessor :name #
22
+ attr_accessor :desc #
23
+ attr_accessor :email #
24
+ attr_accessor :group_id #
25
+ attr_accessor :account #
26
+ attr_accessor :password #
27
+
28
+ // -----------
29
+
30
+ attr_reader :group
31
+ def group=(group)
32
+ @group = group
33
+ @group_id = group.id
34
+ end
35
+
36
+ end