pokotarou 1.1.7 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pokotarou.rb +146 -73
- data/lib/pokotarou/additional_arguments/main.rb +24 -0
- data/lib/pokotarou/additional_methods/main.rb +49 -0
- data/lib/pokotarou/additional_variables/main.rb +28 -0
- data/lib/pokotarou/parser/const_parser.rb +25 -0
- data/lib/pokotarou/parser/loop_expression_parser.rb +32 -0
- data/lib/pokotarou/parser/parser.rb +108 -0
- data/lib/pokotarou/parser/parser_domain.rb +40 -0
- data/lib/pokotarou/parser/return_expression_parser..rb +27 -0
- data/lib/pokotarou/parser/seed_data_expression_parser.rb +18 -0
- data/lib/pokotarou/registration_config_maker/column_domain.rb +17 -0
- data/lib/pokotarou/registration_config_maker/config_domain.rb +48 -0
- data/lib/pokotarou/registration_config_maker/grouping_option_setter.rb +28 -0
- data/lib/pokotarou/registration_config_maker/import_option_setter.rb +13 -0
- data/lib/pokotarou/registration_config_maker/main.rb +65 -0
- data/lib/pokotarou/registration_config_maker/model_option_setter.rb +65 -0
- data/lib/pokotarou/registration_config_maker/preset_option_setter.rb +45 -0
- data/lib/pokotarou/registration_config_maker/template_option_setter.rb +63 -0
- data/lib/pokotarou/registration_config_updater/array_utils.rb +15 -0
- data/lib/pokotarou/registration_config_updater/convert_config.rb +28 -0
- data/lib/pokotarou/registration_config_updater/default_value_maker.rb +32 -0
- data/lib/pokotarou/registration_config_updater/main.rb +170 -0
- data/lib/pokotarou/registration_config_updater/option_config.rb +53 -0
- data/lib/pokotarou/seed_data_register/main.rb +81 -0
- data/lib/pokotarou/version.rb +1 -1
- metadata +26 -17
- data/lib/pokotarou/additional_methods.rb +0 -40
- data/lib/pokotarou/additional_variables/additional_variables.rb +0 -33
- data/lib/pokotarou/additional_variables/def_variable.rb +0 -3
- data/lib/pokotarou/arguments/arguments.rb +0 -24
- data/lib/pokotarou/arguments/def_args.rb +0 -1
- data/lib/pokotarou/array_operation.rb +0 -13
- data/lib/pokotarou/converter.rb +0 -23
- data/lib/pokotarou/data_register.rb +0 -230
- data/lib/pokotarou/data_structure.rb +0 -187
- data/lib/pokotarou/expression_parser.rb +0 -233
- data/lib/pokotarou/file_loader.rb +0 -16
- data/lib/pokotarou/option.rb +0 -46
- data/lib/pokotarou/pokotarou_handler.rb +0 -37
- data/lib/pokotarou/seeder.rb +0 -29
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
require "pokotarou/additional_methods.rb"
|
|
2
|
-
require "pokotarou/additional_variables/additional_variables.rb"
|
|
3
|
-
require "pokotarou/arguments/arguments.rb"
|
|
4
|
-
require "pokotarou/p_tool.rb"
|
|
5
|
-
|
|
6
|
-
def load_filepath
|
|
7
|
-
require AdditionalVariables.filepath
|
|
8
|
-
require Arguments.filepath
|
|
9
|
-
AdditionalMethods.filepathes.each do |filepath|; require filepath end
|
|
10
|
-
AdditionalMethods.filepathes_from_yml.each do |filepath|; require filepath end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class ParseError < StandardError; end
|
|
14
|
-
FOREIGN_KEY_SYMBOL = "F|"
|
|
15
|
-
COLUMN_SYMBOL = "C|"
|
|
16
|
-
|
|
17
|
-
class ExpressionParser
|
|
18
|
-
class << self
|
|
19
|
-
|
|
20
|
-
def parse config_val, maked = nil, maked_col = nil
|
|
21
|
-
begin
|
|
22
|
-
case
|
|
23
|
-
# Array
|
|
24
|
-
when is_array?(config_val)
|
|
25
|
-
array_procees(config_val)
|
|
26
|
-
|
|
27
|
-
# ForeignKey
|
|
28
|
-
when is_foreign_key?(config_val)
|
|
29
|
-
foreign_key_process(config_val, maked_col)
|
|
30
|
-
|
|
31
|
-
# Column
|
|
32
|
-
when is_column_symbol?(config_val)
|
|
33
|
-
column_symbol_process(config_val, maked_col)
|
|
34
|
-
|
|
35
|
-
# Expression
|
|
36
|
-
when is_expression?(config_val)
|
|
37
|
-
expression_process(config_val, maked, maked_col)
|
|
38
|
-
|
|
39
|
-
# Integer
|
|
40
|
-
when is_integer?(config_val)
|
|
41
|
-
integer_process(config_val)
|
|
42
|
-
|
|
43
|
-
# NeedUpdate
|
|
44
|
-
when is_need_update?(config_val)
|
|
45
|
-
need_update_process(config_val, maked, maked_col)
|
|
46
|
-
|
|
47
|
-
# Nil
|
|
48
|
-
when is_nil?(config_val)
|
|
49
|
-
nil_process(config_val)
|
|
50
|
-
|
|
51
|
-
# Other
|
|
52
|
-
else
|
|
53
|
-
nothing_apply_process(config_val)
|
|
54
|
-
end
|
|
55
|
-
rescue => e
|
|
56
|
-
output_error(e)
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
private
|
|
61
|
-
def array_procees val
|
|
62
|
-
return val
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def foreign_key_process val, maked_col
|
|
66
|
-
# remove 'F|'
|
|
67
|
-
str_model = val.sub(FOREIGN_KEY_SYMBOL, "")
|
|
68
|
-
model = eval(str_model)
|
|
69
|
-
return model.pluck(:id)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def column_symbol_process val, maked_col
|
|
73
|
-
# remove 'C|'
|
|
74
|
-
str_model, column = val.sub(COLUMN_SYMBOL, "").split("|")
|
|
75
|
-
model = eval(str_model)
|
|
76
|
-
elemnts = model.pluck(column.to_sym)
|
|
77
|
-
return elemnts.concat(maked_col[str_model.to_sym][column.to_sym])
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def expression_process val, maked, maked_col
|
|
81
|
-
# remove '<>'
|
|
82
|
-
expression = val.strip[1..-2]
|
|
83
|
-
load_filepath()
|
|
84
|
-
return self.parse(eval(expression), maked, maked_col)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def integer_process val
|
|
88
|
-
nothing_apply_process(val)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def need_update_process val, maked, maked_col
|
|
92
|
-
return self.parse(val[:NeedUpdate], maked, maked_col)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def nil_process val
|
|
96
|
-
nothing_apply_process(val)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def nothing_apply_process val
|
|
100
|
-
# for escape \\
|
|
101
|
-
val.instance_of?(String) ? val.tr("\\","") : val
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def output_error e
|
|
105
|
-
raise ParseError.new("Failed Expression parse:#{e.message}")
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# for seed data
|
|
111
|
-
class SeedExpressionParser < ExpressionParser
|
|
112
|
-
class << self
|
|
113
|
-
private
|
|
114
|
-
def nothing_apply_process val
|
|
115
|
-
# for escape \\
|
|
116
|
-
val.instance_of?(String) ? [val.tr("\\","")] : [val]
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def output_error e
|
|
120
|
-
raise ParseError.new("Failed Seed Expression parse:#{e.message}")
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
# for return variables
|
|
126
|
-
class ReturnExpressionParser < ExpressionParser
|
|
127
|
-
class << self
|
|
128
|
-
private
|
|
129
|
-
def output_error e
|
|
130
|
-
ParseError.new("Failed Const Expression parse:#{e.message}")
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def foreign_key_process val, _
|
|
134
|
-
# remove 'F|'
|
|
135
|
-
str_model = val.sub(FOREIGN_KEY_SYMBOL, "")
|
|
136
|
-
model = eval(str_model)
|
|
137
|
-
return model.pluck(:id)
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def column_symbol_process val, _
|
|
141
|
-
# remove 'C|'
|
|
142
|
-
str_model, column = val.sub(COLUMN_SYMBOL, "").split("|")
|
|
143
|
-
model = eval(str_model)
|
|
144
|
-
return model.pluck(column.to_sym)
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# for loop data
|
|
150
|
-
class LoopExpressionParser < ExpressionParser
|
|
151
|
-
class << self
|
|
152
|
-
private
|
|
153
|
-
def array_procees val
|
|
154
|
-
val.size
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def foreign_key_process val, maked_col
|
|
158
|
-
# remove 'F|'
|
|
159
|
-
str_model = val.sub(FOREIGN_KEY_SYMBOL, "")
|
|
160
|
-
model = eval(str_model)
|
|
161
|
-
return model.pluck(:id).size
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def integer_process val
|
|
165
|
-
val
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def nil_process _
|
|
169
|
-
1
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
def output_error e
|
|
173
|
-
ParseError.new("Failed Loop Expression parse: #{e.message}")
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
# for const variables
|
|
179
|
-
class ConstParser < ExpressionParser
|
|
180
|
-
class << self
|
|
181
|
-
private
|
|
182
|
-
def expression_process val, _, _
|
|
183
|
-
# remove '<>'
|
|
184
|
-
expression = val.strip[1..-2]
|
|
185
|
-
load_filepath()
|
|
186
|
-
return self.parse(eval(expression))
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
def nothing_apply_process val
|
|
190
|
-
# for escape \\
|
|
191
|
-
val.instance_of?(String) ? val.tr("\\","") : val
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
def output_error
|
|
195
|
-
ParseError.new("Failed Const Expression parse: #{e.message}")
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
FOREIGN_KEY_REGEXP = /^F\|[A-Z][:A-Za-z0-9]*$/
|
|
201
|
-
def is_foreign_key? val
|
|
202
|
-
return false unless val.kind_of?(String)
|
|
203
|
-
FOREIGN_KEY_REGEXP =~ val
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
COLUMN_REGEXP = /^C\|[A-Z][:A-Za-z0-9]*\|[a-z][:a-z0-9]*$/
|
|
207
|
-
def is_column_symbol? val
|
|
208
|
-
return false unless val.kind_of?(String)
|
|
209
|
-
COLUMN_REGEXP =~ val
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
EXPRESSION_REGEXP = /^\s*<.*>\s*$/
|
|
213
|
-
def is_expression? val
|
|
214
|
-
return false unless val.kind_of?(String)
|
|
215
|
-
EXPRESSION_REGEXP =~ val
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
def is_array? val
|
|
219
|
-
val.instance_of?(Array)
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
def is_integer? val
|
|
223
|
-
val.instance_of?(Integer)
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
def is_need_update? val
|
|
227
|
-
return false unless val.kind_of?(Hash)
|
|
228
|
-
val.has_key?(:NeedUpdate)
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
def is_nil? val
|
|
232
|
-
val.nil?
|
|
233
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
class FileLoader
|
|
2
|
-
class << self
|
|
3
|
-
# load data with the use of indicated filepath
|
|
4
|
-
def load filepath
|
|
5
|
-
end
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
class YmlLoader < FileLoader
|
|
10
|
-
class << self
|
|
11
|
-
def load filepath
|
|
12
|
-
# convert 'str_key' to 'symbol_key'
|
|
13
|
-
YAML.load_file(filepath).deep_symbolize_keys!
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
data/lib/pokotarou/option.rb
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
class Option
|
|
2
|
-
class << self
|
|
3
|
-
def gen option
|
|
4
|
-
# shape option data
|
|
5
|
-
# [option1, option2] => { select: [option2], add: [option1] }
|
|
6
|
-
# [] => { select: [], add: [] }
|
|
7
|
-
option.nil? ? { select: [], add: [] } : separate(option)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def apply arr, size, option_conf, cnt = 0
|
|
11
|
-
selected_val = select(option_conf[:select], arr, size, cnt)
|
|
12
|
-
|
|
13
|
-
add(option_conf[:add], selected_val, cnt)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def separate option
|
|
19
|
-
# separate option to 'select' and 'add'
|
|
20
|
-
# { select = >[], add => [] }
|
|
21
|
-
select_filter = ->(name){ ["rotate", "random"].include?(name) }
|
|
22
|
-
add_filter = ->(name){ ["add_id", "sequence"].include?(name) }
|
|
23
|
-
|
|
24
|
-
{
|
|
25
|
-
select: option.find{|s| select_filter.call(s)},
|
|
26
|
-
add: option.find{|s| add_filter.call(s)}
|
|
27
|
-
}
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def select option, arr, size, cnt
|
|
31
|
-
return arr.sample if option == "random"
|
|
32
|
-
|
|
33
|
-
# default return rotate
|
|
34
|
-
ArrayOperation.get_rotated_val(arr, size, cnt)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def add option, val, cnt
|
|
38
|
-
# if val is nil, return nil
|
|
39
|
-
return nil if val.nil?
|
|
40
|
-
# not use '<<' to avoid destructive effect
|
|
41
|
-
return "#{val}_#{cnt}" if option == "add_id" || option == "sequence"
|
|
42
|
-
|
|
43
|
-
val
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
class PokotarouHandler
|
|
2
|
-
def initialize data
|
|
3
|
-
@data = data
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
def delete_block sym_block
|
|
7
|
-
@data.delete(sym_block)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def delete_model sym_block, sym_class
|
|
11
|
-
@data[sym_block].delete(sym_class)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def delete_col sym_block, sym_class, sym_col
|
|
15
|
-
exists_content = ->(key){ @data[sym_block][sym_class][key].present? }
|
|
16
|
-
|
|
17
|
-
@data[sym_block][sym_class][:col].delete(sym_col) if exists_content.call(:col)
|
|
18
|
-
@data[sym_block][sym_class][:option].delete(sym_col) if exists_content.call(:option)
|
|
19
|
-
@data[sym_block][sym_class][:convert].delete(sym_col) if exists_content.call(:convert)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def change_loop sym_block, sym_class, n
|
|
23
|
-
@data[sym_block][sym_class][:loop] = n
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def change_seed sym_block, sym_class, sym_col, arr
|
|
27
|
-
@data[sym_block][sym_class][:col][sym_col] = arr
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def get_data
|
|
31
|
-
@data.deep_dup
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def set_data data
|
|
35
|
-
@data = data
|
|
36
|
-
end
|
|
37
|
-
end
|
data/lib/pokotarou/seeder.rb
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
class Seeder
|
|
2
|
-
class << self
|
|
3
|
-
def gen config_data, key
|
|
4
|
-
n = config_data[:loop]
|
|
5
|
-
type = config_data[:type][key]
|
|
6
|
-
enum = config_data[:enum][key]
|
|
7
|
-
|
|
8
|
-
return enum if enum.present?
|
|
9
|
-
return make_array(n, ->(){ rand(100) }) if type == "integer"
|
|
10
|
-
return make_array(n, ->(){ rand(0.0..100.0) }) if type == "float"
|
|
11
|
-
return make_array(n, ->(){ rand(0.0..1_000_000_000.0) }) if type == "decimal"
|
|
12
|
-
return make_array(n, ->(){ SecureRandom.hex(20) }) if type == "string"
|
|
13
|
-
return make_array(n, ->(){ SecureRandom.hex(200) }) if ["text", "binary"].include?(type)
|
|
14
|
-
return make_array(n, ->(){ [true, false].sample }) if type == "boolean"
|
|
15
|
-
return make_string_array(n, enum) if type == "string"
|
|
16
|
-
return make_datetime_array() if ["datetime", "date", "time"].include?(type)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def make_array n, proc
|
|
22
|
-
Array.new(n).map{ proc.call() }
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def make_datetime_array
|
|
26
|
-
[Time.now.to_s(:db)]
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|