File: test-action.yaml

package info (click to toggle)
kwalify 0.7.2-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 2,352 kB
  • sloc: ruby: 8,428; xml: 170; makefile: 37; java: 36
file content (525 lines) | stat: -rw-r--r-- 14,145 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
##
## $Rev$
## $Release: 0.7.2 $
## copyright(c) 2005-2010 kuwata-lab all rights reserved.
##
---
- name:  action_genclass_ruby1
  desc:  action 'genclass-ruby'
  action: genclass-ruby
  method: action
  args:  [ -a, genclass-ruby, -tf, action_genclass_ruby1.schema ]
  schema: &action_schema1 |
	type:  map
	class: Context
	mapping:
	 "groups":
	    type:  seq
	    sequence:
	      - type:  map
	        class: Group
	        mapping:
		 "name":
		    type:  str
		    required:  yes
		 "desc":
		    type:  str
		 "owner": &userschema
		    type:  map
		    class: User
		    mapping:
		     "name":
		        type:  str
			required: yes
	             "desc":
		        type:  str
	             "gender":
		        type:  bool
		     "mail":
		        type:   str
		     "manager": *userschema
		     "deleted":
		        type:   bool
		        default: false
	 "users":
	    type: seq
	    sequence:
	      - *userschema
  document: &action_document1 |
	groups:
	  - name:	admin
	    desc:	administrator group
	    owner: &root
	      name:	root
	      desc:	root user
	  - name:       users
	    desc:	user group
	    owner: &guest
	      name:	guest
	      desc:	guest user
	users:
	  - *root
	  - *guest
	  - &user1
	    name: user1
	  - name: user2
	    manager: *user1
  expected: |
	## 
	class Context
	  def initialize(hash=nil)
	    if hash.nil?
	      return
	    end
	    @groups           = (v=hash['groups']) ? v.map!{|e| e.is_a?(Group) ? e : Group.new(e)} : v
	    @users            = (v=hash['users']) ? v.map!{|e| e.is_a?(User) ? e : User.new(e)} : v
	  end
	  attr_accessor :groups           # seq
	  attr_accessor :users            # seq
	end
	
	## 
	class Group
	  def initialize(hash=nil)
	    if hash.nil?
	      return
	    end
	    @name             = hash['name']
	    @desc             = hash['desc']
	    @owner            = (v=hash['owner']) && v.is_a?(Hash) ? User.new(v) : v
	  end
	  attr_accessor :name             # str
	  attr_accessor :desc             # str
	  attr_accessor :owner            # map
	end
	
	## 
	class User
	  def initialize(hash=nil)
	    if hash.nil?
	      @deleted          = false
	      return
	    end
	    @name             = hash['name']
	    @desc             = hash['desc']
	    @gender           = hash['gender']
	    @mail             = hash['mail']
	    @manager          = (v=hash['manager']) && v.is_a?(Hash) ? User.new(v) : v
	    @deleted          = (v=hash['deleted']).nil? ? false : v
	  end
	  attr_accessor :name             # str
	  attr_accessor :desc             # str
	  attr_accessor :gender           # bool
	  attr_accessor :mail             # str
	  attr_accessor :manager          # map
	  attr_accessor :deleted          # bool
	  def gender?       ;  @gender       ; end
	  def deleted?      ;  @deleted      ; end
	end

##
- name:  action_genclass_php1
  desc:  action 'genclass-php'
  action: genclass-php
  method: action
  args:  [ -a, genclass-php, -tf, action_genclass_php1.schema ]
  schema: *action_schema1
  document: *action_document1
  expected: |
	<?php
	
	/// 
	class Context {
	    var $groups;     // seq
	    var $users;      // seq
	    function __construct($arr=NULL) {
	        if (! $arr) return;
	        if (is_array(@$arr['groups']))
	            foreach ($arr['groups'] as $k=>$v)
	                $this->groups[$k] = is_array($v) ? new Group($v) : $v;
	        //else
	        //    $this->groups     = @$arr['groups'];
	        if (is_array(@$arr['users']))
	            foreach ($arr['users'] as $k=>$v)
	                $this->users[$k] = is_array($v) ? new User($v) : $v;
	        //else
	        //    $this->users      = @$arr['users'];
	    }
	}
	
	/// 
	class Group {
	    var $name;       // str
	    var $desc;       // str
	    var $owner;      // map
	    function __construct($arr=NULL) {
	        if (! $arr) return;
	        $this->name       = @$arr['name'];
	        $this->desc       = @$arr['desc'];
	        $this->owner      = is_array(@$arr['owner']) ? new User($arr['owner']) : @$arr['owner'];
	    }
	}
	
	/// 
	class User {
	    var $name;       // str
	    var $desc;       // str
	    var $gender;     // bool
	    var $mail;       // str
	    var $manager;    // map
	    var $deleted = false; // bool
	    function __construct($arr=NULL) {
	        if (! $arr) return;
	        $this->name       = @$arr['name'];
	        $this->desc       = @$arr['desc'];
	        $this->gender     = @$arr['gender'];
	        $this->mail       = @$arr['mail'];
	        $this->manager    = is_array(@$arr['manager']) ? new User($arr['manager']) : @$arr['manager'];
	        if (array_key_exists('deleted', $arr)) $this->deleted = $arr['deleted'];
	    }
	}
	
	?>

##	
- name:  action_genclass_java1
  desc:  action 'genclass-java'
  action: genclass-java
  method: action
  args:  [ -a, genclass-java, -tf, action_genclass_java1.schema ]
  schema: *action_schema1
  document: *action_document1
  output_files: [ Context.java, Group.java, User.java ]
  output_message: |+
      generating ./Context.java...done.
      generating ./Group.java...done.
      generating ./User.java...done.
  expected:
    'Context.java': |
	// generated by kwalify from action_genclass_java1.schema
	
	import java.util.*;
	
	/**
	 *  
	 */
	public class Context {
	
	    private List _groups;
	    private List _users;
	
	    public Context() {}
	
	    public Context(Map map) {
	        List seq;
	        Object obj;
	        if ((seq = (List)map.get("groups")) != null) {
	            for (int i = 0; i < seq.size(); i++) {
	                if ((obj = seq.get(i)) instanceof Map) {
	                    seq.set(i, new Group((Map)obj));
	                }
	            }
	        }
	        _groups       = seq;
	        if ((seq = (List)map.get("users")) != null) {
	            for (int i = 0; i < seq.size(); i++) {
	                if ((obj = seq.get(i)) instanceof Map) {
	                    seq.set(i, new User((Map)obj));
	                }
	            }
	        }
	        _users        = seq;
	    }
	
	    public List getGroups() { return _groups; }
	    public void setGroups(List groups_) { _groups = groups_; }
	    public List getUsers() { return _users; }
	    public void setUsers(List users_) { _users = users_; }
	}
	
    'Group.java': |
	// generated by kwalify from action_genclass_java1.schema
	
	import java.util.*;
	
	/**
	 *  
	 */
	public class Group {
	
	    private String _name;
	    private String _desc;
	    private User _owner;
	
	    public Group() {}
	
	    public Group(Map map) {
	        _name         = (String)map.get("name");
	        _desc         = (String)map.get("desc");
	        Object obj;
	        if ((obj = map.get("owner")) != null && obj instanceof Map) {
	            _owner    = new User((Map)obj);
	        } else {
	            _owner    = (User)obj;
	        }
	    }
	
	    public String getName() { return _name; }
	    public void setName(String name_) { _name = name_; }
	    public String getDesc() { return _desc; }
	    public void setDesc(String desc_) { _desc = desc_; }
	    public User getOwner() { return _owner; }
	    public void setOwner(User owner_) { _owner = owner_; }
	}

    'User.java': |
	// generated by kwalify from action_genclass_java1.schema
	
	import java.util.*;
	
	/**
	 *  
	 */
	public class User {
	
	    private String _name;
	    private String _desc;
	    private boolean _gender;
	    private String _mail;
	    private User _manager;
	    private boolean _deleted = false;
	
	    public User() {}
	
	    public User(Map map) {
	        _name         = (String)map.get("name");
	        _desc         = (String)map.get("desc");
	        if (map.get("gender") != null) {
	            _gender   = ((Boolean)map.get("gender")).booleanValue();
	        }
	        _mail         = (String)map.get("mail");
	        Object obj;
	        if ((obj = map.get("manager")) != null && obj instanceof Map) {
	            _manager  = new User((Map)obj);
	        } else {
	            _manager  = (User)obj;
	        }
	        if (map.get("deleted") != null) {
	            _deleted  = ((Boolean)map.get("deleted")).booleanValue();
	        }
	    }
	
	    public String getName() { return _name; }
	    public void setName(String name_) { _name = name_; }
	    public String getDesc() { return _desc; }
	    public void setDesc(String desc_) { _desc = desc_; }
	    public boolean isGender() { return _gender; }
	    public void setGender(boolean gender_) { _gender = gender_; }
	    public String getMail() { return _mail; }
	    public void setMail(String mail_) { _mail = mail_; }
	    public User getManager() { return _manager; }
	    public void setManager(User manager_) { _manager = manager_; }
	    public boolean isDeleted() { return _deleted; }
	    public void setDeleted(boolean deleted_) { _deleted = deleted_; }
	}

## not used
  main_file:
    name:  Example.java
    content: |
	import kwalify.*;
	import java.util.*;
	
	public class Example {
	  public static void main(String[] args) throws Exception {
	    String input = kwalify.Util.readFile("action_genclass_java1.document");
	    input = kwalify.Util.untabify(input);
	    YamlParser parser = new YamlParser(input);
	    Object ydoc = parser.parse();
	    //
	    Context context = new Context((Map)ydoc);
	    //
	    List groups = context.getGroups();
	    if (groups != null) {
	      for (Iterator it = groups.iterator(); it.hasNext(); ) {
	        Group g = (Group)it.next();
	        System.out.println("group.name = " + g.getName());
	        System.out.println("group.desc = " + g.getDesc());
	        System.out.println("group.owner.name = " + g.getOwner().getName());
	        System.out.println();
	      }
	    }
	    //
	    List users = context.getUsers();
	    if (users != null) {
	      for (Iterator it = users.iterator(); it.hasNext(); ) {
	        User u = (User)it.next();
	        System.out.println("user.name = " + u.getName());
	        System.out.println("user.desc = " + u.getDesc());
	        System.out.println("user.manager.name = " + (u.getManager() != null ? u.getManager().getName() : null));
	        System.out.println();
	      }
	    }
	  }
	}

##
- name:  action_genclass_ruby2
  desc:  action 'genclass-ruby'
  action: genclass-ruby
  method: action
  args:  [ -a, genclass-ruby, -tf, action_genclass_ruby2.schema, "--module=My::DTO", --parent=BaseObject, "--include=Enumerable,Comparable", --hashlike ]
  schema: &action_schema2 |
	type: map
	mapping:
	 "tables":
	    type:  seq
	    sequence:
	      - type:  map
		class: Table
		mapping:
		 "name":   {type: str}
		 "desc":   {type: text}
		 "columns":
		    type:  seq
		    sequence:
		      - type:  map
			class: Column
			mapping: &column
			 "name":  {type: str}
			 "type":  {type: str}
			 "desc":  {type: str}
			 "not-null":  {type: bool}
			 "primary-key": {type: bool}
			 "default":  {type: any}
			 "ref":	  {type: str}
	 "columns":
	    type:  seq
	    sequence:
	      - type:  map
		class: Column
		mapping:
		 <<: *column
		 "namepattern":	 {type: str}
	 "columnsets":
	    type:  seq
	    sequence:
	     - type:  map
	       class: Columnset
	       mapping:
		"name": {type: str}
		"columns":
		   type:  seq
		   sequence:
		     - type:  map
		       class: Column
		       mapping: *column
  document: &action_document3 |
	columns:
	  - name:	id
	    type:	int
	    primary-key: yes
	    not-null:	yes
	  - name:	updated_at
	    type:	timestamp
	    not-null:	yes
	    default:	current_timestamp
	  - name:	created_at
	    type:	timestamp
	    not-null:	yes
	    default:	current_timestamp
	columnsets:
	  - name:	common
	    columns:
	      - name:	created_at
	      - name:	updated_at
	tables:
	  - name:	customers
	    desc:	Customer master table
	    columns:
	      - name:	id
	      - name:	name
	        type:	str
	        not-null: yes
	      - name:	common
	  - name:	sales_orders
	    desc:	Sales orders master table
	    columns:
	      - name:	id
	      - name:	customer_id
	        ref:	customers.id
	        not-null: yes
	      - name:	ordered_date
	        type:	date
	        not-null:  yes
	      - name:	delivery_date
	        type:	date
  expected: |
	require 'kwalify/util/hashlike'
	
	module My::DTO
	
	  ## 
	  class Table < BaseObject
	    include Kwalify::Util::HashLike
	    include Enumerable,Comparable
	    def initialize(hash=nil)
	      if hash.nil?
	        return
	      end
	      @name             = hash['name']
	      @desc             = hash['desc']
	      @columns          = (v=hash['columns']) ? v.map!{|e| e.is_a?(Column) ? e : Column.new(e)} : v
	    end
	    attr_accessor :name             # str
	    attr_accessor :desc             # text
	    attr_accessor :columns          # seq
	  end
	
	  ## 
	  class Column < BaseObject
	    include Kwalify::Util::HashLike
	    include Enumerable,Comparable
	    def initialize(hash=nil)
	      if hash.nil?
	        return
	      end
	      @name             = hash['name']
	      @type             = hash['type']
	      @desc             = hash['desc']
	      @not_null         = hash['not-null']
	      @primary_key      = hash['primary-key']
	      @default          = hash['default']
	      @ref              = hash['ref']
	      @namepattern      = hash['namepattern']
	    end
	    attr_accessor :name             # str
	    attr_accessor :type             # str
	    attr_accessor :desc             # str
	    attr_accessor :not_null         # bool
	    attr_accessor :primary_key      # bool
	    attr_accessor :default          # any
	    attr_accessor :ref              # str
	    attr_accessor :namepattern      # str
	    def not_null?     ;  @not_null     ; end
	    def primary_key?  ;  @primary_key  ; end
	  end
	
	  ## 
	  class Columnset < BaseObject
	    include Kwalify::Util::HashLike
	    include Enumerable,Comparable
	    def initialize(hash=nil)
	      if hash.nil?
	        return
	      end
	      @name             = hash['name']
	      @columns          = (v=hash['columns']) ? v.map!{|e| e.is_a?(Column) ? e : Column.new(e)} : v
	    end
	    attr_accessor :name             # str
	    attr_accessor :columns          # seq
	  end
	
	end

##