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,52 @@
1
+ ###
2
+ ### $Rev: 44 $
3
+ ### $Release: 0.3.0 $
4
+ ### copyright(c) 2005 kuwata-lab.com all rights reserved.
5
+ ###
6
+
7
+ DATAFILE = tabledef.yaml
8
+
9
+ OPTS_DDL = --droptable
10
+ OPTS_DTO_JAVA = --package=my.example --parent=Object --populate --constructor --collection=set
11
+ OPTS_DTO_RUBY = --module=Example --parent=Object --reqpath=lib --populate --symbolkey
12
+ OPTS_RAILS_KWARTZ = --lang=ja --charset=UTF8 --stylesheet=site,local --session-token
13
+ OPTS_RAILS_MODEL = --lang=ja --encoding=UTF8
14
+ OPTS_RAILS_CONTROLLER = --lang=ja --encoding=UTF8 --session-token
15
+ OPTS_HIBERNATE = --collection=set --package=my.example
16
+
17
+ RAILS_DIR = rails
18
+ VIEWS_DIR = $(RAILS_DIR)/views
19
+ MODELS_DIR = $(RAILS_DIR)/models
20
+ CONTROLLERS_DIR = $(RAILS_DIR)/controllers
21
+
22
+
23
+ all:
24
+ kwatable -t ddl-mysql $(DATAFILE) > ddl-mysql.sql
25
+ kwatable -t ddl-postgresql $(DATAFILE) > ddl-postgresql.sql
26
+ kwatable -t dto-java $(DATAFILE)
27
+ kwatable -t dto-ruby $(DATAFILE)
28
+ kwatable -t hibernate $(DATAFILE) > hibernate.hbm.xml
29
+ mkdir -p $(VIEWS_DIR)
30
+ kwatable -t rails-kwartz -d $(VIEWS_DIR) $(DATAFILE)
31
+ mkdir -p $(MODELS_DIR)
32
+ kwatable -t rails-model -d $(MODELS_DIR) $(DATAFILE)
33
+ mkdir -p $(CONTROLLERS_DIR)
34
+ kwatable -t rails-controller -d $(CONTROLLERS_DIR) $(DATAFILE)
35
+
36
+ all2:
37
+ kwatable -t ddl-mysql $(OPTS_DDL) $(DATAFILE) > ddl-mysql.sql
38
+ kwatable -t ddl-postgresql $(OPTS_DDL) $(DATAFILE) > ddl-postgresql.sql
39
+ kwatable -t dto-java $(OPTS_DTO_JAVA) $(DATAFILE)
40
+ kwatable -t dto-ruby $(OPTS_DTO_RUBY) $(DATAFILE)
41
+ kwatable -t hibernate $(OPTS_HIBERNATE) $(DATAFILE) > hibernate.hbm.xml
42
+ mkdir -p $(VIEWS_DIR)
43
+ kwatable -t rails-kwartz -d $(VIEWS_DIR) $(OPTS_RAILS_KWARTZ) $(DATAFILE)
44
+ mkdir -p $(MODELS_DIR)
45
+ kwatable -t rails-model -d $(MODELS_DIR) $(OPTS_RAILS_MODEL) $(DATAFILE)
46
+ mkdir -p $(CONTROLLERS_DIR)
47
+ kwatable -t rails-controller -d $(CONTROLLERS_DIR) $(OPTS_RAILS_CONTROLLER) $(DATAFILE)
48
+
49
+
50
+ clean:
51
+ rm -rf *.sql *.java *.rb *.class *.xml $(RAILS_DIR)
52
+
@@ -0,0 +1,136 @@
1
+
2
+ columns:
3
+
4
+ - name: 'no'
5
+ type: int
6
+ ident: yes
7
+ serial: yes
8
+
9
+ - name: code
10
+ type: str
11
+ ident: yes
12
+ width: 4
13
+
14
+ - name: name
15
+ type: str
16
+ unique: yes
17
+
18
+ - name: desc
19
+ type: str
20
+
21
+ - name: active
22
+ type: boolean
23
+ default: true
24
+
25
+
26
+ tables:
27
+
28
+ - name: dept
29
+ class: Department
30
+ desc: Department master table
31
+ columns:
32
+ - name: code
33
+ - name: name
34
+ - name: desc
35
+ - name: mngr_no
36
+ ref: emp.no
37
+ attr: manager_no
38
+ - name: active
39
+ relations:
40
+ - kind: '1:n'
41
+ referrer: emp.dept_code
42
+ attr: employees
43
+
44
+ - name: emp
45
+ class: Employee
46
+ desc: Employee master table
47
+ columns:
48
+ - name: 'no'
49
+ - name: name
50
+ unique: no
51
+ - name: desc
52
+ - name: class
53
+ ref: emp_class.code
54
+ attr: class_code
55
+ required: yes
56
+ - name: dept_code
57
+ ref: dept.code
58
+ attr: department_code
59
+ required: yes
60
+ - name: supervisor_no
61
+ ref: emp.no
62
+ - name: hired
63
+ type: date
64
+ - name: retired
65
+ type: date
66
+ relations:
67
+ - kind: 'n:n'
68
+ referrer: team.code
69
+ join-table: membership
70
+ - kind: '1:n'
71
+ referrer: emp.no
72
+ attr: subordinates
73
+ - kind: '1:1'
74
+ referrer: personal_data.emp
75
+
76
+ - name: emp_class
77
+ desc: Employee class
78
+ class: EmployeeClass
79
+ columns:
80
+ - name: code
81
+ - name: name
82
+ - name: desc
83
+ relations:
84
+ - kind: '1:n'
85
+ referrer: emp.class
86
+ attr: employees
87
+
88
+ - name: team
89
+ desc: Team master table
90
+ columns:
91
+ - name: code
92
+ - name: name
93
+ - name: desc
94
+ - name: leader_no
95
+ ref: emp.no
96
+ - name: subleader_no
97
+ ref: emp.no
98
+ - name: start_date
99
+ type: date
100
+ - name: end_date
101
+ type: date
102
+ relations:
103
+ - kind: 'n:n'
104
+ referrer: emp.no
105
+ join-table: membership
106
+ attr: members
107
+
108
+ - name: membership
109
+ desc: Join table of emp and team
110
+ columns:
111
+ - name: emp_no
112
+ ref: emp.no
113
+ attr: employee_no
114
+ ref-name: employee
115
+ - name: team_code
116
+ ref: team.code
117
+ ident-columns: [ emp_no, team_code ]
118
+ modeling: no
119
+
120
+ - name: personal_data
121
+ desc: Personal data of employees
122
+ columns:
123
+ - name: emp
124
+ ref: emp.no
125
+ ref-name: employee
126
+ ident: yes
127
+ - name: gender
128
+ type: char
129
+ enum: [ M, F, X ]
130
+ required: yes
131
+ - name: birth
132
+ type: date
133
+ required: yes
134
+ - name: married
135
+ type: boolean
136
+ required: yes
@@ -4,8 +4,8 @@
4
4
  ### RubyGems Specification file for kwatable
5
5
  ###
6
6
  ### copyright(c) 2005 kuwata-lab.com all rights reserved.
7
- ### $Release: 0.2.0 $
8
- ### $Rev: 10 $
7
+ ### $Release: 0.3.0 $
8
+ ### $Rev: 45 $
9
9
  ###
10
10
 
11
11
  require 'rubygems'
@@ -14,7 +14,7 @@ spec = Gem::Specification.new do |s|
14
14
  ## package information
15
15
  s.name = 'kwatable'
16
16
  s.author = 'makoto kuwata'
17
- s.version = ("$Release: 0.2.0 $" =~ /Release: ([\.\d]+)/) && $1
17
+ s.version = ("$Release: 0.3.0 $" =~ /Release: ([\.\d]+)/) && $1
18
18
  s.platform = Gem::Platform::RUBY
19
19
  s.homepage = 'http://www.kuwata-lab.com/kwatable'
20
20
  s.summary = "SQL and DTO generator from table definition"
@@ -26,20 +26,21 @@ spec = Gem::Specification.new do |s|
26
26
  DTO class file for Java and Ruby.
27
27
  You can add your own eRuby template.
28
28
  END
29
-
29
+
30
30
  ## files
31
31
  files = []
32
- files += Dir.glob('lib/**/*')
33
- files += Dir.glob('bin/**/*')
34
- files += Dir.glob('templates/**/*')
35
- files += Dir.glob('examples/**/*')
36
- files += Dir.glob('test/**/*')
37
- files += %w[README.txt ChangeLog.txt COPYING setup.rb kwatable.gemspec]
32
+ files.concat Dir.glob('lib/**/*')
33
+ files.concat Dir.glob('bin/**/*')
34
+ #files += Dir.glob('templates/**/*')
35
+ files.concat Dir.glob('examples/**/*')
36
+ files.concat Dir.glob('test/**/*')
37
+ files.concat %w[README.txt ChangeLog MIT-LICENSE setup.rb kwatable.gemspec]
38
38
  #s.files = files.delete_if { |path| path =~ /\.svn/ }
39
39
  s.files = files
40
40
  s.executables = ['kwatable']
41
41
  s.bindir = 'bin'
42
42
  s.test_file = 'test/test.rb'
43
+ s.add_dependency('kwalify', ['>= 0.6.0'])
43
44
  end
44
45
 
45
46
  if $0 == __FILE__
@@ -1,30 +1,36 @@
1
1
  ###
2
2
  ### copyright(c) 2005 kuwata-lab.com all rights reserved.
3
- ### $Release: 0.2.0 $
4
- ### $Rev: 15 $
3
+ ### $Release: 0.3.0 $
4
+ ### $Rev: 33 $
5
5
  ###
6
6
 
7
7
  module Kwatable
8
8
 
9
- ## base class of exception
10
- class KwatableError < StandardError
11
- end
9
+ ## release number
10
+ RELEASE = ("$Release: 0.3.0 $" =~ /[\.\d]+/) && $&
12
11
 
13
- ## template path
14
- @@template_path = []
15
- if ENV['KWATABLE_PATH']
16
- @@template_path += ENV['KWATABLE_PATH'].split(File::PATH_SEPARATOR)
17
- end
18
- $LOAD_PATH.each do |path|
19
- template_path = "#{path}/kwatable/templates"
20
- @@template_path << template_path if test(?d, template_path)
21
- end
12
+ ## base class of exception
13
+ class KwatableError < StandardError
14
+ end
22
15
 
23
- def self.template_path
24
- return @@template_path
25
- end
16
+ ## template path
17
+ @@template_path = []
18
+ if ENV['KWATABLE_PATH']
19
+ @@template_path.concat ENV['KWATABLE_PATH'].split(File::PATH_SEPARATOR)
20
+ end
21
+ $LOAD_PATH.each do |path|
22
+ dir = "#{path}/kwatable/template"
23
+ @@template_path << dir if test(?d, dir)
24
+ end
25
+ dirs = [ "#{ENV['HOME']}/lib/kwatable/template" ]
26
+ @@template_path.concat dirs.find_all { |dir| test(?d, dir) }
27
+
28
+ def self.template_path
29
+ return @@template_path
30
+ end
26
31
 
27
32
  end
28
33
 
29
- require 'kwatable/error-msg'
34
+
35
+ require 'kwatable/messages'
30
36
  require 'kwatable/manipulator'
@@ -2,8 +2,8 @@
2
2
  ### schema definition of kwalify for kwatable
3
3
  ###
4
4
  ### copyright(c) 2005 kuwata-lab.com all rights reserved.
5
- ### $Release: 0.2.0 $
6
- ### $Rev: 17 $
5
+ ### $Release: 0.3.0 $
6
+ ### $Rev: 39 $
7
7
  ###
8
8
 
9
9
 
@@ -11,15 +11,20 @@ type: map
11
11
  mapping:
12
12
  "columns":
13
13
  type: seq
14
+ name: COLUMNS
14
15
  sequence:
15
16
  - type: map
16
- mapping: &columrule
17
+ name: COLUMN
18
+ mapping: &column
17
19
  "name":
18
20
  type: str
19
21
  required: yes
20
22
  pattern: /^\w+$/
23
+ unique: yes
21
24
  "desc":
22
25
  type: text
26
+ "attr":
27
+ type: str
23
28
  "label":
24
29
  type: str
25
30
  "type":
@@ -44,21 +49,27 @@ mapping:
44
49
  - blob
45
50
  "width":
46
51
  type: int
52
+ "class":
53
+ type: str
47
54
  #"identifier":
48
55
  "ident":
49
56
  type: bool
57
+ desc: means primary-key constraint
50
58
  "primary-key":
51
59
  type: bool
52
60
  desc: alias of 'ident'
53
61
  "required":
54
62
  type: bool
63
+ desc: means not-null constraint
55
64
  "not-null":
56
65
  type: bool
57
66
  desc: alias of 'required'
58
67
  "unique":
59
68
  type: bool
69
+ desc: means unique constraint
60
70
  "serial":
61
71
  type: bool
72
+ desc: means auto_increment in MySQL or serial in PostgreSQL
62
73
  "enum":
63
74
  type: seq
64
75
  sequence:
@@ -66,22 +77,50 @@ mapping:
66
77
  "ref":
67
78
  type: str
68
79
  pattern: /^\w+(\.\w+|\(\w+\))$/
80
+ desc: means foregin key
69
81
  "ref-name":
70
82
  type: str
83
+ "cascade":
84
+ type: bool
71
85
  "pattern":
72
86
  type: str
73
87
  pattern: /^\/.*\/$/
74
-
88
+ "range":
89
+ type: map
90
+ mapping:
91
+ "max": { type: number }
92
+ "min": { type: number }
93
+ "length":
94
+ type: map
95
+ mapping:
96
+ "max": { type: int }
97
+ "min": { type: int }
98
+ "default":
99
+ type: any
100
+ "status":
101
+ type: str
102
+ enum:
103
+ - active
104
+ - pending
105
+ - obsolete
106
+ "vendor": &vendor
107
+ type: map
108
+ mapping:
109
+ =:
110
+ type: any
75
111
 
76
112
  "tables":
77
113
  type: seq
114
+ name: TABLES
78
115
  sequence:
79
116
  - type: map
117
+ name: TABLE
80
118
  mapping:
81
119
  "name":
82
120
  type: str
83
121
  required: yes
84
122
  pattern: /^\w+$/
123
+ unique: yes
85
124
  "desc":
86
125
  type: text
87
126
  "label":
@@ -89,8 +128,59 @@ mapping:
89
128
  "class":
90
129
  type: str
91
130
  pattern: /^[A-Z]\w+$/
131
+ unique: yes
92
132
  "columns":
93
133
  type: seq
94
134
  sequence:
95
135
  - type: map
96
- mapping: *columrule
136
+ mapping: *column
137
+ "ident-columns": &ident_columns
138
+ type: seq
139
+ sequence:
140
+ - type: str
141
+ "primary-keys": *ident_columns
142
+ "display-column":
143
+ type: str
144
+ "modeling":
145
+ type: bool
146
+ "relations":
147
+ type: seq
148
+ name: RELATIONS
149
+ sequence:
150
+ - type: map
151
+ name: RELATION
152
+ mapping:
153
+ "kind": { type: str, required: yes,
154
+ enum: [ '1:1', '1:n', 'n:n' ] }
155
+ "referrer": { type: str, required: yes,
156
+ pattern: /^(\w+\.\w+|\w+\(\w+(,\s*\w+)*\))$/ }
157
+ #"table": { type: str, required: yes }
158
+ #"column": { type: str }
159
+ "attr": { type: str }
160
+ "desc": { type: text }
161
+ "cascade": { type: bool }
162
+ "where": { type: str }
163
+ "order-by": { type: str }
164
+ "group-by": { type: str }
165
+ "join-table": { type: str }
166
+ "as": { type: str }
167
+ "through": { type: str }
168
+ "source": { type: str }
169
+ "vendor": *vendor
170
+
171
+ "connections":
172
+ type: seq
173
+ name: CONNECTIONS
174
+ sequence:
175
+ - type: map
176
+ name: CONNECTION
177
+ mapping:
178
+ "dbms": { type: str, required: yes }
179
+ "database": { type: str, required: yes }
180
+ "user": { type: str }
181
+ "password": { type: str }
182
+ "host": { type: str }
183
+ "port": { type: str }
184
+ "vendor": *vendor
185
+
186
+ "vendor": *vendor