pokotarou 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +159 -77
- data/lib/pokotarou/additional_variables/additional_variables.rb +24 -0
- data/lib/pokotarou/additional_variables/def_const.rb +1 -0
- data/lib/pokotarou/arguments/arguments.rb +23 -0
- data/lib/pokotarou/arguments/def_args.rb +1 -0
- data/lib/pokotarou/data_register.rb +9 -1
- data/lib/pokotarou/data_structure.rb +84 -3
- data/lib/pokotarou/expression_parser.rb +146 -46
- data/lib/pokotarou/version.rb +1 -1
- data/lib/pokotarou.rb +9 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e36d9755f7ed2c3f0a2e723405f6a633b1f3d5034c9ba1823441ab1cf0fb01d
|
4
|
+
data.tar.gz: c7b5467264f7d06f79361b00277e752345ce14c0879fbceeb2752b5cd7b0eb6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cf01f158f6f73f494009bdcb930e2c12d6ee47ed9c017ff2408c04ae744aa605e388ee2843fbee493cd5a0b0847d0d66b63fe53887279fd5d1b6c2618cbb4d4
|
7
|
+
data.tar.gz: 69c4b0079556d2060d42c2c1a9f53e1fe7d65f95e107ce488c56dde6d278893b1d074f81883423e0b01300d2640db30abbd5bc9574b72fd6127d7258763fbcd5
|
data/README.md
CHANGED
@@ -45,7 +45,9 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
45
45
|
|
46
46
|
## Usage
|
47
47
|
|
48
|
-
|
48
|
+
Following yml file become seed data.
|
49
|
+
|
50
|
+
Please make following yml file in your favorite dir.
|
49
51
|
|
50
52
|
```yml
|
51
53
|
Default:
|
@@ -53,25 +55,24 @@ Default:
|
|
53
55
|
loop: 3
|
54
56
|
```
|
55
57
|
|
56
|
-
|
58
|
+
and write following ruby code in seeds.rb.
|
57
59
|
|
58
60
|
```ruby
|
59
61
|
Pokotarou.execute("./config_filepath")
|
60
62
|
```
|
61
63
|
|
62
|
-
run rails db:seed
|
64
|
+
when you finished writing, then run rails db:seed
|
63
65
|
|
64
66
|
```bash
|
65
67
|
$ rails db:seed
|
66
68
|
```
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
### Configration file
|
70
|
+
As a result, seed data is registerd your db.
|
71
71
|
|
72
|
-
|
72
|
+
## How to set configlation file(.yml)?
|
73
|
+
explain how to write the configuration file below.
|
73
74
|
|
74
|
-
|
75
|
+
### Model used for explanation
|
75
76
|
Table name below is 'prefs' and model name is 'Pref'
|
76
77
|
|
77
78
|
|Field|Type|NULL|
|
@@ -95,12 +96,14 @@ Table name below is 'members' and model name is 'Member'
|
|
95
96
|
|updated_at|datetime|NO|
|
96
97
|
|
97
98
|
|
98
|
-
|
99
|
-
|
99
|
+
### Standerd Setting
|
100
|
+
The basic setting method is written below
|
100
101
|
|
101
|
-
|
102
|
+
#### Automatic data entry
|
102
103
|
|
103
|
-
|
104
|
+
If there is no definition about col, then automatically prepared data is registrd.
|
105
|
+
|
106
|
+
For example, in the case of below, it is registered automatically prepared data three times.
|
104
107
|
|
105
108
|
```yml
|
106
109
|
Default:
|
@@ -108,8 +111,7 @@ Default:
|
|
108
111
|
loop: 3
|
109
112
|
```
|
110
113
|
|
111
|
-
|
112
|
-
|
114
|
+
also you can set seed_data by yourself.
|
113
115
|
```yml
|
114
116
|
Default:
|
115
117
|
Pref:
|
@@ -118,40 +120,24 @@ Default:
|
|
118
120
|
name: "Hokkaido"
|
119
121
|
```
|
120
122
|
|
121
|
-
####
|
122
|
-
|
123
|
-
|
124
|
-
Array data is registerd one by one.
|
123
|
+
#### Omitted loop
|
124
|
+
If you want to register the test data at once, I suggest ommited loop
|
125
125
|
|
126
126
|
```yml
|
127
127
|
Default:
|
128
|
-
Pref:
|
129
|
-
loop: 3
|
128
|
+
Pref:
|
130
129
|
col:
|
131
|
-
name: ["Hokkaido"
|
130
|
+
name: ["Hokkaido"]
|
132
131
|
```
|
133
132
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
Registration is possible using registerd data
|
138
|
-
|
139
|
-
Use maked in different model area in the following cases.
|
140
|
-
|
141
|
-
```yml
|
142
|
-
Default:
|
143
|
-
Pref:
|
144
|
-
loop: 2
|
145
|
-
col:
|
146
|
-
name: ["Hokkaido", "Aomori"]
|
147
|
-
Member:
|
148
|
-
loop: 2
|
149
|
-
col:
|
150
|
-
name: <maked[:Default][:Pref][:name]>
|
151
|
-
pref_id: F|Pref
|
133
|
+
```ruby
|
134
|
+
["Hokkaido"]
|
152
135
|
```
|
153
136
|
|
154
|
-
|
137
|
+
#### Array
|
138
|
+
You can set array_data.
|
139
|
+
|
140
|
+
Array data is registerd one by one.
|
155
141
|
|
156
142
|
```yml
|
157
143
|
Default:
|
@@ -159,24 +145,20 @@ Default:
|
|
159
145
|
loop: 3
|
160
146
|
col:
|
161
147
|
name: ["Hokkaido", "Aomori", "Iwate"]
|
162
|
-
Member:
|
163
|
-
loop: 3
|
164
|
-
col:
|
165
|
-
name: ["Tarou", "Jirou", "Saburou"]
|
166
|
-
remarks: <maked[:Default][:Member][:name]>
|
167
|
-
pref_id: F|Pref
|
168
|
-
|
169
148
|
```
|
170
149
|
|
171
|
-
|
150
|
+
#### Maked function
|
151
|
+
'maked' is very useful function.
|
152
|
+
it is hash and accumulate data created in the past.
|
153
|
+
|
154
|
+
For example, in the case of below, reffer name of Pref in Default block by maked
|
172
155
|
|
173
156
|
```yml
|
174
157
|
Default:
|
175
|
-
Pref:
|
158
|
+
Pref:
|
176
159
|
loop: 2
|
177
160
|
col:
|
178
161
|
name: ["Hokkaido", "Aomori"]
|
179
|
-
Default2:
|
180
162
|
Member:
|
181
163
|
loop: 2
|
182
164
|
col:
|
@@ -188,9 +170,9 @@ Default2:
|
|
188
170
|
|
189
171
|
**※ If you set association(belongs_to, has_many...), Pokotarou automatically register foreign keys**
|
190
172
|
|
191
|
-
' F| ' means foreign key.
|
173
|
+
' F| ' means foreign key. 'F|' is Model.all.pluck(:id)
|
192
174
|
|
193
|
-
|
175
|
+
For example, in the case of below, Member model record is registerd with pref_id(foregin key).
|
194
176
|
|
195
177
|
```yml
|
196
178
|
Default:
|
@@ -205,9 +187,8 @@ Default:
|
|
205
187
|
```
|
206
188
|
|
207
189
|
#### Expression expansion
|
208
|
-
'< >' means expression expansion
|
209
|
-
|
210
|
-
You can run ruby code in '< >'
|
190
|
+
'< >' means expression expansion.
|
191
|
+
You can run ruby code in '< >'.
|
211
192
|
|
212
193
|
```yml
|
213
194
|
Default:
|
@@ -218,7 +199,7 @@ Default:
|
|
218
199
|
created_at: <Date.parse('1997/02/05')>
|
219
200
|
```
|
220
201
|
|
221
|
-
####
|
202
|
+
#### Additional method
|
222
203
|
You can add method and use it in pokotarou
|
223
204
|
|
224
205
|
```yml
|
@@ -237,17 +218,18 @@ def pref_name
|
|
237
218
|
end
|
238
219
|
```
|
239
220
|
|
240
|
-
and
|
221
|
+
and run the following code in seeds.rb.
|
241
222
|
|
242
223
|
```ruby
|
243
224
|
Pokotarou.import("./method_filepath")
|
244
225
|
Pokotarou.execute("./config_filepath")
|
245
226
|
```
|
246
227
|
|
228
|
+
As as result, pokotarou can call pref_name method, and seed data is registrd by pref_name method.
|
247
229
|
|
248
|
-
####
|
230
|
+
#### Multiple blocks
|
249
231
|
|
250
|
-
|
232
|
+
You can use multiple blocks.
|
251
233
|
|
252
234
|
```yml
|
253
235
|
Default:
|
@@ -269,6 +251,10 @@ Fuga:
|
|
269
251
|
loop: 3
|
270
252
|
```
|
271
253
|
|
254
|
+
### option
|
255
|
+
Option is useful function.
|
256
|
+
If you can master it, it may be easier to create test data.
|
257
|
+
|
272
258
|
#### Random
|
273
259
|
Shuffle seed data when regist
|
274
260
|
|
@@ -324,6 +310,9 @@ The following results change from run to run
|
|
324
310
|
["Hokkaido_0", "Iwate_1", "Hokkaido_2"]
|
325
311
|
```
|
326
312
|
|
313
|
+
### Advanced Setting
|
314
|
+
The advanced setting method is written below
|
315
|
+
|
327
316
|
#### Validation
|
328
317
|
|
329
318
|
Run validation when regist
|
@@ -352,7 +341,10 @@ Default:
|
|
352
341
|
|
353
342
|
#### Pokotarou Handler
|
354
343
|
|
355
|
-
|
344
|
+
If you want to use configlation yml data in ruby code then you can use "PokotarouHandler"
|
345
|
+
|
346
|
+
When you use "PokotarouHandler", can update pokotarou's parameter
|
347
|
+
in ruby code.
|
356
348
|
|
357
349
|
|
358
350
|
<b>Change Operation</b>
|
@@ -405,9 +397,113 @@ In the following example, delete col config
|
|
405
397
|
Pokotarou.execute(handler.get_data)
|
406
398
|
```
|
407
399
|
|
408
|
-
####
|
400
|
+
#### Const
|
401
|
+
You can set const variables by const' key.
|
402
|
+
|
403
|
+
```yml
|
404
|
+
const':
|
405
|
+
name: "hoge"
|
406
|
+
Default:
|
407
|
+
Pref:
|
408
|
+
loop: 3
|
409
|
+
col:
|
410
|
+
name: <const[:name]>
|
411
|
+
```
|
412
|
+
|
413
|
+
#### Grouping
|
414
|
+
Grouping is very useful function.
|
415
|
+
Especially useful when setting multiple options.
|
416
|
+
|
417
|
+
|
418
|
+
```yml
|
419
|
+
Default:
|
420
|
+
Member:
|
421
|
+
grouping:
|
422
|
+
# set columns you want to group
|
423
|
+
hoge_g: ["name", "remark"]
|
424
|
+
col:
|
425
|
+
# you can use "hoge_g" at col
|
426
|
+
hoge_g: <['fugafuga!']>
|
427
|
+
option:
|
428
|
+
# also you can use "hoge_g" at option
|
429
|
+
hoge_g: ["add_id"]
|
430
|
+
|
431
|
+
```
|
432
|
+
|
433
|
+
#### Template
|
434
|
+
You can set template config by template' key.
|
435
|
+
|
436
|
+
The template can be overwritten with the one set later.
|
437
|
+
|
438
|
+
```yml
|
439
|
+
template':
|
440
|
+
pref_template:
|
441
|
+
loop: 3
|
442
|
+
col:
|
443
|
+
pref_id: F|Pref
|
444
|
+
name: ["hogeta", "fuga", "pokota"]
|
445
|
+
Pref:
|
446
|
+
Pref:
|
447
|
+
loop: 3
|
448
|
+
col:
|
449
|
+
name: ["Hokkaido", "Aomori", "Iwate"]
|
450
|
+
|
451
|
+
Member1:
|
452
|
+
Member:
|
453
|
+
template: pref_template
|
454
|
+
|
455
|
+
Member2:
|
456
|
+
Member:
|
457
|
+
template: pref_template
|
458
|
+
col:
|
459
|
+
name: ["hogeta2", "fuga2", "pokota2"]
|
460
|
+
```
|
461
|
+
|
462
|
+
#### Return
|
463
|
+
You can set return val by return' key.
|
464
|
+
|
465
|
+
```yml
|
466
|
+
Default:
|
467
|
+
Pref:
|
468
|
+
loop: 3
|
469
|
+
col:
|
470
|
+
name: ["Hokkaido", "Aomori", "Iwate"]
|
471
|
+
|
472
|
+
return': <maked[:Default][:Pref][:name]>
|
473
|
+
|
474
|
+
```
|
475
|
+
|
476
|
+
```ruby
|
477
|
+
return_val = Pokotarou.execute("filepath")
|
478
|
+
puts return_val
|
479
|
+
```
|
480
|
+
|
481
|
+
result
|
482
|
+
```
|
483
|
+
Hokkaido
|
484
|
+
Aomori
|
485
|
+
Iwate
|
486
|
+
```
|
487
|
+
#### Args
|
488
|
+
|
489
|
+
You can set args by hash.
|
490
|
+
|
491
|
+
```yml
|
492
|
+
Default:
|
493
|
+
Pref:
|
494
|
+
loop: 3
|
495
|
+
col:
|
496
|
+
name: <args[:name]>
|
497
|
+
```
|
498
|
+
```ruby
|
499
|
+
Pokotarou.set_args({ name: ["Hokkaido", "Aomori", "Iwate"] })
|
500
|
+
Pokotarou.execute("filepath")
|
501
|
+
```
|
409
502
|
|
410
|
-
|
503
|
+
### Convert
|
504
|
+
convert is a convenient function. Will convert the seed data.
|
505
|
+
|
506
|
+
#### convert option
|
411
507
|
|
412
508
|
|convert |description |
|
413
509
|
|:---------|------------------------------------------|
|
@@ -432,7 +528,7 @@ Default:
|
|
432
528
|
[nil, nil, nil]
|
433
529
|
```
|
434
530
|
|
435
|
-
complex version
|
531
|
+
a little complex version
|
436
532
|
|
437
533
|
```yml
|
438
534
|
Default:
|
@@ -446,18 +542,4 @@ Default:
|
|
446
542
|
|
447
543
|
```ruby
|
448
544
|
["", nil, nil]
|
449
|
-
```
|
450
|
-
|
451
|
-
#### Omitted loop
|
452
|
-
If you want to register the test data at once, I suggest ommited loop
|
453
|
-
|
454
|
-
```yml
|
455
|
-
Default:
|
456
|
-
Pref:
|
457
|
-
col:
|
458
|
-
name: ["Hokkaido"]
|
459
|
-
```
|
460
|
-
|
461
|
-
```ruby
|
462
|
-
["Hokkaido"]
|
463
545
|
```
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AdditionalVariables
|
2
|
+
class << self
|
3
|
+
CONST_KEY = :"const'"
|
4
|
+
@const = nil
|
5
|
+
attr_reader :const
|
6
|
+
|
7
|
+
def import data
|
8
|
+
return unless data.has_key?(CONST_KEY)
|
9
|
+
@const = data[CONST_KEY]
|
10
|
+
|
11
|
+
# parse expression configlation
|
12
|
+
@const.each do |key, val|
|
13
|
+
@const[key] = ConstExpressionParser.parse(val)
|
14
|
+
end
|
15
|
+
|
16
|
+
data.delete(CONST_KEY)
|
17
|
+
end
|
18
|
+
|
19
|
+
def filepath
|
20
|
+
"pokotarou/additional_variables/def_const.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
def const; AdditionalVariables.const end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class MisMatchArgType < StandardError; end
|
2
|
+
module Arguments
|
3
|
+
class << self
|
4
|
+
@args = nil
|
5
|
+
attr_reader :args
|
6
|
+
|
7
|
+
def import hash_data
|
8
|
+
unless hash_data.kind_of?(Hash)
|
9
|
+
raise MisMatchArgType.new("Please use Hash for args")
|
10
|
+
end
|
11
|
+
@args = hash_data
|
12
|
+
end
|
13
|
+
|
14
|
+
def remove
|
15
|
+
@args = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def filepath
|
19
|
+
"pokotarou/arguments/def_args.rb"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
def args; Arguments.args end
|
@@ -11,12 +11,15 @@ class DataRegister
|
|
11
11
|
ActiveRecord::Base.transaction do
|
12
12
|
begin
|
13
13
|
data.each do |sym_block, model_data|
|
14
|
+
next if is_dush?(sym_block.to_s)
|
14
15
|
regist_models(sym_block, model_data, maked, model_cache)
|
15
16
|
end
|
16
17
|
rescue => e
|
17
18
|
raise StandardError.new("#{e.message}")
|
18
19
|
end
|
19
20
|
end
|
21
|
+
|
22
|
+
ReturnExpressionParser.parse(data[:"return'"], maked)
|
20
23
|
end
|
21
24
|
|
22
25
|
private
|
@@ -142,7 +145,7 @@ class DataRegister
|
|
142
145
|
def set_expand_expression config_data, key, val, maked
|
143
146
|
# if it exists type, there is no need for doing 'expand expression'
|
144
147
|
return if config_data[:type][key].present?
|
145
|
-
config_data[:col][key] =
|
148
|
+
config_data[:col][key] = SeedExpressionParser.parse(val, maked)
|
146
149
|
end
|
147
150
|
|
148
151
|
def set_loop_expand_expression config_data, maked
|
@@ -170,5 +173,10 @@ class DataRegister
|
|
170
173
|
puts log
|
171
174
|
end
|
172
175
|
|
176
|
+
DUSH_OPTION = /^.*\'$/
|
177
|
+
def is_dush? val
|
178
|
+
return false unless val.kind_of?(String)
|
179
|
+
DUSH_OPTION =~ val
|
180
|
+
end
|
173
181
|
end
|
174
182
|
end
|
@@ -1,12 +1,15 @@
|
|
1
1
|
class DataStructure
|
2
2
|
class << self
|
3
3
|
def gen data
|
4
|
+
execute_template_option_setting(data)
|
4
5
|
# return data structure bellow
|
5
6
|
# [{ block_name => { model_name => { column_configration }}}, ...]
|
6
7
|
data.reduce(Hash.new) do |acc, r|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
if is_dush?(r.first.to_s)
|
9
|
+
acc[r.first] = r.second
|
10
|
+
else
|
11
|
+
set_reshape_data_to_acc(acc, r)
|
12
|
+
end
|
10
13
|
|
11
14
|
acc
|
12
15
|
end
|
@@ -14,6 +17,69 @@ class DataStructure
|
|
14
17
|
|
15
18
|
private
|
16
19
|
|
20
|
+
def execute_template_option_setting data
|
21
|
+
return unless data.has_key?(:"template'")
|
22
|
+
templates = data[:"template'"]
|
23
|
+
data.delete(:"template'")
|
24
|
+
data.each do |_, val|
|
25
|
+
set_template_option(val, templates)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_template_option model_data, templates
|
30
|
+
model_data.each do |key, val|
|
31
|
+
next unless has_template?(val)
|
32
|
+
template_name = val[:template]
|
33
|
+
template = templates[template_name.to_sym]
|
34
|
+
apply_template_option(val, template)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def apply_template_option config_data, template
|
39
|
+
template.each do |key, val|
|
40
|
+
if val.kind_of?(Hash)
|
41
|
+
config_data[key] ||= Hash.new
|
42
|
+
apply_template_option(config_data[key], val)
|
43
|
+
else
|
44
|
+
|
45
|
+
config_data[key] ||= val
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_reshape_data_to_acc acc, r
|
51
|
+
execute_grouping_option_setting(r.second)
|
52
|
+
# r.first is block_name
|
53
|
+
# r.second is model_data, like { Pref: {loop: 3}, Member: {loop: 3}... }
|
54
|
+
acc[r.first] = gen_structure(r.second)
|
55
|
+
end
|
56
|
+
|
57
|
+
def execute_grouping_option_setting model_data
|
58
|
+
model_data.each do |key, val|
|
59
|
+
set_grouping_option(val) if has_grouping?(val)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_grouping_option val
|
64
|
+
val[:grouping].each do |grouping_key, cols|
|
65
|
+
apply_grouping_col(:col, val, grouping_key, cols)
|
66
|
+
apply_grouping_col(:option, val, grouping_key, cols)
|
67
|
+
apply_grouping_col(:convert, val, grouping_key, cols)
|
68
|
+
end
|
69
|
+
|
70
|
+
val.delete(:grouping)
|
71
|
+
end
|
72
|
+
|
73
|
+
def apply_grouping_col config_name, val, grouping_key, cols
|
74
|
+
return if val[config_name].blank?
|
75
|
+
return unless val[config_name].has_key?(grouping_key)
|
76
|
+
cols.each do |e|
|
77
|
+
val[config_name][e.to_sym] = val[config_name][grouping_key]
|
78
|
+
end
|
79
|
+
|
80
|
+
val[config_name].delete(grouping_key)
|
81
|
+
end
|
82
|
+
|
17
83
|
def gen_structure model_data
|
18
84
|
model_data.reduce(Hash.new) do |acc, r|
|
19
85
|
# r.second is config_data, like {loop: 3, ...}
|
@@ -84,5 +150,20 @@ class DataStructure
|
|
84
150
|
return false unless val.kind_of?(String)
|
85
151
|
ENUM =~ val
|
86
152
|
end
|
153
|
+
|
154
|
+
DUSH_OPTION = /^.*\'$/
|
155
|
+
def is_dush? val
|
156
|
+
return false unless val.kind_of?(String)
|
157
|
+
DUSH_OPTION =~ val
|
158
|
+
end
|
159
|
+
|
160
|
+
def has_grouping? config_data
|
161
|
+
return false if config_data.blank?
|
162
|
+
config_data.has_key?(:grouping)
|
163
|
+
end
|
164
|
+
|
165
|
+
def has_template? config_data
|
166
|
+
config_data.has_key?(:template)
|
167
|
+
end
|
87
168
|
end
|
88
169
|
end
|
@@ -1,74 +1,162 @@
|
|
1
1
|
require "pokotarou/additional_methods.rb"
|
2
|
+
require "pokotarou/additional_variables/additional_variables.rb"
|
3
|
+
require "pokotarou/arguments/arguments.rb"
|
2
4
|
class ParseError < StandardError; end
|
3
5
|
FOREIGN_KEY_SYMBOL = "F|"
|
4
6
|
|
5
|
-
# for seed data
|
6
7
|
class ExpressionParser
|
7
8
|
class << self
|
8
|
-
def parse config_val, maked
|
9
|
+
def parse config_val, maked = nil
|
9
10
|
begin
|
10
|
-
require AdditionalMethods.filepath if AdditionalMethods.filepath.present?
|
11
11
|
case
|
12
|
-
|
13
|
-
|
12
|
+
# Array
|
13
|
+
when is_array?(config_val)
|
14
|
+
array_procees(config_val)
|
15
|
+
|
16
|
+
# ForeignKey
|
14
17
|
when is_foreign_key?(config_val)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
return model.pluck(:id)
|
18
|
+
foreign_key_process(config_val)
|
19
|
+
|
20
|
+
# Expression
|
19
21
|
when is_expression?(config_val)
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
expression_process(config_val, maked)
|
23
|
+
|
24
|
+
# Integer
|
25
|
+
when is_integer?(config_val)
|
26
|
+
integer_process(config_val)
|
27
|
+
|
28
|
+
# Nil
|
29
|
+
when is_nil?(config_val)
|
30
|
+
nil_process(config_val)
|
31
|
+
|
32
|
+
# Other
|
23
33
|
else
|
24
|
-
|
25
|
-
# escape \\
|
26
|
-
[config_val.tr("\\","")]
|
27
|
-
else
|
28
|
-
[config_val]
|
29
|
-
end
|
34
|
+
nothing_apply_process(config_val)
|
30
35
|
end
|
31
36
|
rescue => e
|
32
|
-
|
37
|
+
output_error(e)
|
33
38
|
end
|
34
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def array_procees val
|
43
|
+
return val
|
44
|
+
end
|
45
|
+
|
46
|
+
def foreign_key_process val
|
47
|
+
# remove 'F|'
|
48
|
+
str_model = val.sub(FOREIGN_KEY_SYMBOL, "")
|
49
|
+
model = eval(str_model)
|
50
|
+
return model.pluck(:id)
|
51
|
+
end
|
52
|
+
|
53
|
+
def expression_process val, maked
|
54
|
+
# remove '<>'
|
55
|
+
expression = val.strip[1..-2]
|
56
|
+
require AdditionalVariables.filepath if AdditionalVariables.const.present?
|
57
|
+
require AdditionalMethods.filepath if AdditionalMethods.filepath.present?
|
58
|
+
require Arguments.filepath if Arguments.filepath.present?
|
59
|
+
return self.parse(eval(expression), maked)
|
60
|
+
end
|
61
|
+
|
62
|
+
def integer_process val
|
63
|
+
nothing_apply_process(val)
|
64
|
+
end
|
65
|
+
|
66
|
+
def nil_process val
|
67
|
+
nothing_apply_process(val)
|
68
|
+
end
|
69
|
+
|
70
|
+
def nothing_apply_process val
|
71
|
+
# for escape \\
|
72
|
+
val.instance_of?(String) ? val.tr("\\","") : val
|
73
|
+
end
|
74
|
+
|
75
|
+
def output_error e
|
76
|
+
raise ParseError.new("Failed Expression parse:#{e.message}")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# for seed data
|
82
|
+
class SeedExpressionParser < ExpressionParser
|
83
|
+
class << self
|
84
|
+
private
|
85
|
+
def nothing_apply_process val
|
86
|
+
# for escape \\
|
87
|
+
val.instance_of?(String) ? [val.tr("\\","")] : [val]
|
88
|
+
end
|
89
|
+
|
90
|
+
def output_error e
|
91
|
+
raise ParseError.new("Failed Seed Expression parse:#{e.message}")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# for return variables
|
97
|
+
class ReturnExpressionParser < ExpressionParser
|
98
|
+
class << self
|
99
|
+
private
|
100
|
+
def output_error e
|
101
|
+
ParseError.new("Failed Const Expression parse:#{e.message}")
|
102
|
+
end
|
35
103
|
end
|
36
104
|
end
|
37
105
|
|
38
106
|
# for loop data
|
39
|
-
class LoopExpressionParser
|
107
|
+
class LoopExpressionParser < ExpressionParser
|
40
108
|
class << self
|
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
|
-
|
109
|
+
private
|
110
|
+
def array_procees val
|
111
|
+
val.size
|
112
|
+
end
|
113
|
+
|
114
|
+
def foreign_key_process val
|
115
|
+
# remove 'F|'
|
116
|
+
str_model = val.sub(FOREIGN_KEY_SYMBOL, "")
|
117
|
+
model = eval(str_model)
|
118
|
+
return model.pluck(:id).size
|
119
|
+
end
|
120
|
+
|
121
|
+
def integer_process val
|
122
|
+
val
|
123
|
+
end
|
124
|
+
|
125
|
+
def nil_process _
|
126
|
+
1
|
127
|
+
end
|
128
|
+
|
129
|
+
def output_error e
|
130
|
+
ParseError.new("Failed Loop Expression parse: #{e.message}")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# for const variables
|
136
|
+
class ConstExpressionParser < ExpressionParser
|
137
|
+
class << self
|
138
|
+
private
|
139
|
+
def expression_process val, _
|
140
|
+
# remove '<>'
|
141
|
+
expression = val.strip[1..-2]
|
142
|
+
require AdditionalMethods.filepath if AdditionalMethods.filepath.present?
|
143
|
+
require Arguments.filepath if Arguments.filepath.present?
|
144
|
+
return self.parse(eval(expression))
|
145
|
+
end
|
146
|
+
|
147
|
+
def nothing_apply_process val
|
148
|
+
# for escape \\
|
149
|
+
val.instance_of?(String) ? val.tr("\\","") : val
|
150
|
+
end
|
151
|
+
|
152
|
+
def output_error
|
153
|
+
ParseError.new("Failed Const Expression parse: #{e.message}")
|
66
154
|
end
|
67
155
|
end
|
68
156
|
end
|
69
157
|
|
70
158
|
FOREIGN_KEY = /^F\|[A-Z][:A-Za-z0-9]*$/
|
71
|
-
def is_foreign_key? val
|
159
|
+
def is_foreign_key? val
|
72
160
|
return false unless val.kind_of?(String)
|
73
161
|
FOREIGN_KEY =~ val
|
74
162
|
end
|
@@ -77,4 +165,16 @@ EXPRESSION = /^\s*<.*>\s*$/
|
|
77
165
|
def is_expression? val
|
78
166
|
return false unless val.kind_of?(String)
|
79
167
|
EXPRESSION =~ val
|
168
|
+
end
|
169
|
+
|
170
|
+
def is_array? val
|
171
|
+
val.instance_of?(Array)
|
172
|
+
end
|
173
|
+
|
174
|
+
def is_integer? val
|
175
|
+
val.instance_of?(Integer)
|
176
|
+
end
|
177
|
+
|
178
|
+
def is_nil? val
|
179
|
+
val.nil?
|
80
180
|
end
|
data/lib/pokotarou/version.rb
CHANGED
data/lib/pokotarou.rb
CHANGED
@@ -20,8 +20,13 @@ module Pokotarou
|
|
20
20
|
AdditionalMethods.import(filepath)
|
21
21
|
end
|
22
22
|
|
23
|
+
def set_args hash
|
24
|
+
Arguments.import(hash)
|
25
|
+
end
|
26
|
+
|
23
27
|
def reset
|
24
28
|
AdditionalMethods.remove()
|
29
|
+
Arguments.remove()
|
25
30
|
end
|
26
31
|
|
27
32
|
def gen_handler filepath
|
@@ -32,9 +37,13 @@ module Pokotarou
|
|
32
37
|
|
33
38
|
def gen_config filepath
|
34
39
|
contents = load_file(filepath)
|
40
|
+
set_const_val_config(contents)
|
35
41
|
DataStructure.gen(contents)
|
36
42
|
end
|
37
43
|
|
44
|
+
def set_const_val_config contents
|
45
|
+
AdditionalVariables.import(contents)
|
46
|
+
end
|
38
47
|
|
39
48
|
def load_file filepath
|
40
49
|
case File.extname(filepath)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pokotarou
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kashiwara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -50,6 +50,10 @@ files:
|
|
50
50
|
- Rakefile
|
51
51
|
- lib/pokotarou.rb
|
52
52
|
- lib/pokotarou/additional_methods.rb
|
53
|
+
- lib/pokotarou/additional_variables/additional_variables.rb
|
54
|
+
- lib/pokotarou/additional_variables/def_const.rb
|
55
|
+
- lib/pokotarou/arguments/arguments.rb
|
56
|
+
- lib/pokotarou/arguments/def_args.rb
|
53
57
|
- lib/pokotarou/array_operation.rb
|
54
58
|
- lib/pokotarou/converter.rb
|
55
59
|
- lib/pokotarou/data_register.rb
|