pokotarou 1.1.6 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pokotarou.rb +146 -72
- 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 +43 -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 +58 -0
- data/lib/pokotarou/registration_config_maker/model_option_setter.rb +65 -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 +25 -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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb37e93ab913cfc45d6bb0c06cbfec3149ac957e0592ef12d62f1ad6d3b0146e
|
4
|
+
data.tar.gz: c67cccf940b65008a991684a9603a99395aca02a9137613331680dc23612b841
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 870208b9d5b2449ccd6bc1884bf0a78596da211d261deccba8353919fec4a617925cbcdeaf2330949d34c07370e89b24ad8649eef3c28aa8fe0f41b5602bab3c
|
7
|
+
data.tar.gz: 406ad8070133722c71dcebf8b2df12f2471563b0e0ad15f4647d41a62025c20e85a32ba2334fee1951966e6b77fb8815e23f668e4f5320c92cfb57d26f6f3e87
|
data/lib/pokotarou.rb
CHANGED
@@ -1,103 +1,177 @@
|
|
1
|
-
Dir[File.expand_path('../pokotarou', __FILE__) << '/*.rb'].each do |file|
|
2
|
-
require file
|
3
|
-
end
|
4
|
-
|
5
1
|
require "activerecord-import"
|
2
|
+
require "pokotarou/registration_config_maker/main.rb"
|
3
|
+
require "pokotarou/seed_data_register/main.rb"
|
4
|
+
require "pokotarou/parser/const_parser.rb"
|
6
5
|
|
7
6
|
module Pokotarou
|
8
|
-
class
|
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
|
-
|
7
|
+
class Operater
|
8
|
+
class NotFoundLoader < StandardError; end
|
9
|
+
class << self
|
10
|
+
def execute input
|
11
|
+
AdditionalMethods::Main.init()
|
12
|
+
|
13
|
+
# if input is filepath, generate config_data
|
14
|
+
return_val =
|
15
|
+
if input.kind_of?(String)
|
16
|
+
SeedDataRegister::Main.register(gen_config(input))
|
17
|
+
else
|
18
|
+
SeedDataRegister::Main.register(input)
|
19
|
+
end
|
20
|
+
|
21
|
+
AdditionalMethods::Main.remove_filepathes_from_yml()
|
22
|
+
|
23
|
+
return_val
|
24
|
+
end
|
25
|
+
|
26
|
+
def pipeline_execute input_arr
|
27
|
+
AdditionalMethods::Main.init()
|
28
|
+
|
29
|
+
return_vals = []
|
30
|
+
input_arr.each do |e|
|
31
|
+
handler = gen_handler_with_cache(e[:filepath])
|
32
|
+
|
33
|
+
if e[:change_data].present?
|
34
|
+
e[:change_data].each do |block, config|
|
35
|
+
config.each do |model, seed|
|
36
|
+
seed.each do |col_name, val|
|
37
|
+
handler.change_seed(block, model, col_name, val)
|
38
|
+
end
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
|
+
|
43
|
+
e[:args] ||= {}
|
44
|
+
e[:args][:passed_return_val] = return_vals.last
|
45
|
+
set_args(e[:args])
|
46
|
+
|
47
|
+
return_vals << Pokotarou.execute(handler.get_data())
|
48
|
+
AdditionalMethods::Main.remove_filepathes_from_yml()
|
42
49
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
AdditionalMethods.
|
50
|
+
|
51
|
+
return_vals
|
52
|
+
end
|
53
|
+
|
54
|
+
def import filepath
|
55
|
+
AdditionalMethods::Main.init()
|
56
|
+
AdditionalMethods::Main.import(filepath)
|
57
|
+
end
|
58
|
+
|
59
|
+
def set_args hash
|
60
|
+
AdditionalArguments::Main.import(hash)
|
61
|
+
end
|
62
|
+
|
63
|
+
def reset
|
64
|
+
AdditionalMethods::Main.remove()
|
65
|
+
AdditionalArguments::Main.remove()
|
66
|
+
AdditionalVariables::Main.remove()
|
67
|
+
@handler_chache = {}
|
68
|
+
end
|
69
|
+
|
70
|
+
def gen_handler filepath
|
71
|
+
AdditionalMethods::Main.init()
|
72
|
+
|
73
|
+
PokotarouHandler.new(gen_config(filepath))
|
74
|
+
end
|
75
|
+
|
76
|
+
def gen_handler_with_cache filepath
|
77
|
+
AdditionalMethods::Main.init()
|
78
|
+
|
79
|
+
@handler_cache ||= {}
|
80
|
+
@handler_cache[filepath] ||= PokotarouHandler.new(gen_config(filepath))
|
81
|
+
|
82
|
+
@handler_cache[filepath].deep_dup
|
50
83
|
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def gen_config filepath
|
88
|
+
contents = YAML.load_file(filepath).deep_symbolize_keys!
|
89
|
+
AdditionalVariables::Main.set_const(contents)
|
90
|
+
RegistrationConfigMaker::Main.gen(contents)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
51
96
|
|
52
|
-
|
97
|
+
module Pokotarou
|
98
|
+
class << self
|
99
|
+
def execute input
|
100
|
+
Operater.execute(input)
|
101
|
+
end
|
102
|
+
|
103
|
+
def pipeline_execute input_arr
|
104
|
+
Operater.pipeline_execute(input_arr)
|
53
105
|
end
|
54
106
|
|
55
107
|
def import filepath
|
56
|
-
|
108
|
+
Operater.import(filepath)
|
57
109
|
end
|
58
110
|
|
59
111
|
def set_args hash
|
60
|
-
|
112
|
+
Operater.set_args(hash)
|
61
113
|
end
|
62
114
|
|
63
115
|
def reset
|
64
|
-
|
65
|
-
Arguments.remove()
|
66
|
-
AdditionalVariables.remove()
|
67
|
-
@handler_chache = {}
|
116
|
+
Operater.reset()
|
68
117
|
end
|
69
118
|
|
70
119
|
def gen_handler filepath
|
71
|
-
|
120
|
+
Operater.gen_handler(filepath)
|
72
121
|
end
|
73
122
|
|
74
123
|
def gen_handler_with_cache filepath
|
75
|
-
|
76
|
-
@handler_cache[filepath] ||= PokotarouHandler.new(gen_config(filepath))
|
77
|
-
|
78
|
-
@handler_cache[filepath].deep_dup
|
124
|
+
Operater.gen_handler_with_cache(filepath)
|
79
125
|
end
|
126
|
+
end
|
127
|
+
end
|
80
128
|
|
81
|
-
|
129
|
+
class PokotarouHandler
|
130
|
+
def initialize data
|
131
|
+
@data = data
|
132
|
+
end
|
82
133
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
DataStructure.gen(contents)
|
87
|
-
end
|
134
|
+
def make
|
135
|
+
::Pokotarou::Operater.execute(get_data())
|
136
|
+
end
|
88
137
|
|
89
|
-
|
90
|
-
|
91
|
-
|
138
|
+
def delete_block sym_block
|
139
|
+
@data.delete(sym_block)
|
140
|
+
end
|
92
141
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
return YmlLoader.load(filepath)
|
97
|
-
else
|
98
|
-
raise NotFoundLoader.new("not found loader")
|
99
|
-
end
|
100
|
-
end
|
142
|
+
def delete_model sym_block, sym_class
|
143
|
+
@data[sym_block].delete(sym_class)
|
144
|
+
end
|
101
145
|
|
146
|
+
def delete_col sym_block, sym_class, sym_col
|
147
|
+
exists_content = ->(key){ @data[sym_block][sym_class][key].present? }
|
148
|
+
|
149
|
+
@data[sym_block][sym_class][:col].delete(sym_col) if exists_content.call(:col)
|
150
|
+
@data[sym_block][sym_class][:option].delete(sym_col) if exists_content.call(:option)
|
151
|
+
@data[sym_block][sym_class][:convert].delete(sym_col) if exists_content.call(:convert)
|
102
152
|
end
|
103
|
-
|
153
|
+
|
154
|
+
def change_loop sym_block, sym_class, n
|
155
|
+
@data[sym_block][sym_class][:loop] = n
|
156
|
+
end
|
157
|
+
|
158
|
+
def change_seed sym_block, sym_class, sym_col, arr
|
159
|
+
@data[sym_block][sym_class][:col][sym_col] = arr
|
160
|
+
end
|
161
|
+
|
162
|
+
def get_data
|
163
|
+
@data.deep_dup
|
164
|
+
end
|
165
|
+
|
166
|
+
def set_data data
|
167
|
+
@data = data
|
168
|
+
end
|
169
|
+
|
170
|
+
def set_randomincrement sym_block, sym_class, status
|
171
|
+
@data[sym_block][sym_class][:randomincrement] = status
|
172
|
+
end
|
173
|
+
|
174
|
+
def set_autoincrement sym_block, sym_class, status
|
175
|
+
@data[sym_block][sym_class][:autoincrement] = status
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Pokotarou
|
2
|
+
class MisMatchArgType < StandardError; end
|
3
|
+
class AdditionalArguments
|
4
|
+
module Main
|
5
|
+
class << self
|
6
|
+
@args = nil
|
7
|
+
attr_reader :args
|
8
|
+
|
9
|
+
def import hash_data
|
10
|
+
unless hash_data.kind_of?(Hash)
|
11
|
+
raise MisMatchArgType.new("Please use Hash for args")
|
12
|
+
end
|
13
|
+
|
14
|
+
@args = hash_data
|
15
|
+
end
|
16
|
+
|
17
|
+
def remove
|
18
|
+
@args = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Pokotarou
|
2
|
+
module ::Pokotarou::AdditionalMethods
|
3
|
+
module Main
|
4
|
+
class << self
|
5
|
+
attr_reader :filepathes
|
6
|
+
attr_reader :filepathes_from_yml
|
7
|
+
|
8
|
+
@filepathes = []
|
9
|
+
@filepathes_from_yml = []
|
10
|
+
|
11
|
+
def init
|
12
|
+
@filepathes ||= []
|
13
|
+
@filepathes_from_yml = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def import filepath
|
17
|
+
add(@filepathes, filepath)
|
18
|
+
end
|
19
|
+
|
20
|
+
def import_from_yml filepath
|
21
|
+
add(@filepathes_from_yml, filepath)
|
22
|
+
end
|
23
|
+
|
24
|
+
def remove
|
25
|
+
@filepathes = []
|
26
|
+
@filepathes_from_yml = []
|
27
|
+
end
|
28
|
+
|
29
|
+
def remove_filepathes_from_yml
|
30
|
+
@filepathes_from_yml = []
|
31
|
+
end
|
32
|
+
|
33
|
+
def load
|
34
|
+
@filepathes.each do |filepath|; require filepath end
|
35
|
+
@filepathes_from_yml.each do |filepath|; require filepath end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def add filepath_arr, filepath
|
40
|
+
if filepath.instance_of?(Array)
|
41
|
+
filepath_arr.concat(filepath)
|
42
|
+
else
|
43
|
+
filepath_arr.push(filepath)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Pokotarou
|
2
|
+
class AdditionalVariables
|
3
|
+
module Main
|
4
|
+
class << self
|
5
|
+
CONST_KEY = :"const'"
|
6
|
+
@const = {}
|
7
|
+
attr_reader :const
|
8
|
+
|
9
|
+
def set_const data
|
10
|
+
return {} unless data.has_key?(CONST_KEY)
|
11
|
+
@const = data[CONST_KEY]
|
12
|
+
|
13
|
+
# parse expression configlation
|
14
|
+
@const.each do |key, val|
|
15
|
+
@const[key] = ConstParser.parse(val)
|
16
|
+
end
|
17
|
+
|
18
|
+
data.delete(CONST_KEY)
|
19
|
+
end
|
20
|
+
|
21
|
+
def remove
|
22
|
+
@const = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "pokotarou/parser/parser.rb"
|
2
|
+
|
3
|
+
# for const variables
|
4
|
+
module Pokotarou
|
5
|
+
class ConstParser < ExpressionParser
|
6
|
+
class << self
|
7
|
+
private
|
8
|
+
def expression_process val, _, _
|
9
|
+
# remove '<>'
|
10
|
+
expression = val.strip[1..-2]
|
11
|
+
::Pokotarou::AdditionalMethods::Main.load
|
12
|
+
return self.parse(eval(expression))
|
13
|
+
end
|
14
|
+
|
15
|
+
def nothing_apply_process val
|
16
|
+
# for escape \\
|
17
|
+
val.instance_of?(String) ? val.tr("\\","") : val
|
18
|
+
end
|
19
|
+
|
20
|
+
def output_error
|
21
|
+
ParseError.new("Failed Const Expression parse: #{e.message}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "pokotarou/parser/parser.rb"
|
2
|
+
|
3
|
+
# for loop data
|
4
|
+
module Pokotarou
|
5
|
+
class LoopExpressionParser < ExpressionParser
|
6
|
+
class << self
|
7
|
+
private
|
8
|
+
def array_procees val
|
9
|
+
val.size
|
10
|
+
end
|
11
|
+
|
12
|
+
def foreign_key_process val, maked_col
|
13
|
+
# remove 'F|'
|
14
|
+
str_model = val.sub(FOREIGN_KEY_SYMBOL, "")
|
15
|
+
model = eval(str_model)
|
16
|
+
return model.pluck(:id).size
|
17
|
+
end
|
18
|
+
|
19
|
+
def integer_process val
|
20
|
+
val
|
21
|
+
end
|
22
|
+
|
23
|
+
def nil_process _
|
24
|
+
1
|
25
|
+
end
|
26
|
+
|
27
|
+
def output_error e
|
28
|
+
ParseError.new("Failed Loop Expression parse: #{e.message}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "pokotarou/additional_variables/main.rb"
|
2
|
+
require "pokotarou/additional_methods/main.rb"
|
3
|
+
require "pokotarou/additional_arguments/main.rb"
|
4
|
+
require "pokotarou/parser/parser_domain.rb"
|
5
|
+
require "pokotarou/p_tool.rb"
|
6
|
+
|
7
|
+
|
8
|
+
module Pokotarou
|
9
|
+
class ParseError < StandardError; end
|
10
|
+
FOREIGN_KEY_SYMBOL = "F|"
|
11
|
+
COLUMN_SYMBOL = "C|"
|
12
|
+
|
13
|
+
class ExpressionParser
|
14
|
+
class << self
|
15
|
+
|
16
|
+
def args; ::Pokotarou::AdditionalArguments::Main.args end
|
17
|
+
def const; ::Pokotarou::AdditionalVariables::Main.const end
|
18
|
+
|
19
|
+
def parse config_val, maked = nil, maked_col = nil
|
20
|
+
begin
|
21
|
+
case
|
22
|
+
# Array
|
23
|
+
when ParserDomain.is_array?(config_val)
|
24
|
+
array_procees(config_val)
|
25
|
+
|
26
|
+
# ForeignKey
|
27
|
+
when ParserDomain.is_foreign_key?(config_val)
|
28
|
+
foreign_key_process(config_val, maked_col)
|
29
|
+
|
30
|
+
# Column
|
31
|
+
when ParserDomain.is_column_symbol?(config_val)
|
32
|
+
column_symbol_process(config_val, maked_col)
|
33
|
+
|
34
|
+
# Expression
|
35
|
+
when ParserDomain.is_expression?(config_val)
|
36
|
+
expression_process(config_val, maked, maked_col)
|
37
|
+
|
38
|
+
# Integer
|
39
|
+
when ParserDomain.is_integer?(config_val)
|
40
|
+
integer_process(config_val)
|
41
|
+
|
42
|
+
# NeedUpdate
|
43
|
+
when ParserDomain.is_need_update?(config_val)
|
44
|
+
need_update_process(config_val, maked, maked_col)
|
45
|
+
|
46
|
+
# Nil
|
47
|
+
when ParserDomain.is_nil?(config_val)
|
48
|
+
nil_process(config_val)
|
49
|
+
|
50
|
+
# Other
|
51
|
+
else
|
52
|
+
nothing_apply_process(config_val)
|
53
|
+
end
|
54
|
+
rescue => e
|
55
|
+
output_error(e)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def array_procees val
|
61
|
+
return val
|
62
|
+
end
|
63
|
+
|
64
|
+
def foreign_key_process val, maked_col
|
65
|
+
# remove 'F|'
|
66
|
+
str_model = val.sub(FOREIGN_KEY_SYMBOL, "")
|
67
|
+
model = eval(str_model)
|
68
|
+
return model.pluck(:id)
|
69
|
+
end
|
70
|
+
|
71
|
+
def column_symbol_process val, maked_col
|
72
|
+
# remove 'C|'
|
73
|
+
str_model, column = val.sub(COLUMN_SYMBOL, "").split("|")
|
74
|
+
model = eval(str_model)
|
75
|
+
elemnts = model.pluck(column.to_sym)
|
76
|
+
return elemnts.concat(maked_col[str_model.to_sym][column.to_sym])
|
77
|
+
end
|
78
|
+
|
79
|
+
def expression_process val, maked, maked_col
|
80
|
+
# remove '<>'
|
81
|
+
expression = val.strip[1..-2]
|
82
|
+
::Pokotarou::AdditionalMethods::Main.load
|
83
|
+
return self.parse(eval(expression), maked, maked_col)
|
84
|
+
end
|
85
|
+
|
86
|
+
def integer_process val
|
87
|
+
nothing_apply_process(val)
|
88
|
+
end
|
89
|
+
|
90
|
+
def need_update_process val, maked, maked_col
|
91
|
+
return self.parse(val[:NeedUpdate], maked, maked_col)
|
92
|
+
end
|
93
|
+
|
94
|
+
def nil_process val
|
95
|
+
nothing_apply_process(val)
|
96
|
+
end
|
97
|
+
|
98
|
+
def nothing_apply_process val
|
99
|
+
# for escape \\
|
100
|
+
val.instance_of?(String) ? val.tr("\\","") : val
|
101
|
+
end
|
102
|
+
|
103
|
+
def output_error e
|
104
|
+
raise ParseError.new("Failed Expression parse:#{e.message}")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|