pokotarou 1.2.0 → 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 +21 -38
- 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 +24 -15
- 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 -233
- 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/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,31 +1,30 @@
|
|
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
7
|
class Operater
|
9
8
|
class NotFoundLoader < StandardError; end
|
10
9
|
class << self
|
11
10
|
def execute input
|
12
|
-
|
11
|
+
AdditionalMethods::Main.init()
|
13
12
|
|
14
13
|
# if input is filepath, generate config_data
|
15
14
|
return_val =
|
16
15
|
if input.kind_of?(String)
|
17
|
-
|
16
|
+
SeedDataRegister::Main.register(gen_config(input))
|
18
17
|
else
|
19
|
-
|
18
|
+
SeedDataRegister::Main.register(input)
|
20
19
|
end
|
21
20
|
|
22
|
-
AdditionalMethods.remove_filepathes_from_yml()
|
21
|
+
AdditionalMethods::Main.remove_filepathes_from_yml()
|
23
22
|
|
24
23
|
return_val
|
25
24
|
end
|
26
25
|
|
27
26
|
def pipeline_execute input_arr
|
28
|
-
|
27
|
+
AdditionalMethods::Main.init()
|
29
28
|
|
30
29
|
return_vals = []
|
31
30
|
input_arr.each do |e|
|
@@ -46,37 +45,36 @@ module Pokotarou
|
|
46
45
|
set_args(e[:args])
|
47
46
|
|
48
47
|
return_vals << Pokotarou.execute(handler.get_data())
|
49
|
-
AdditionalMethods.remove_filepathes_from_yml()
|
48
|
+
AdditionalMethods::Main.remove_filepathes_from_yml()
|
50
49
|
end
|
51
50
|
|
52
51
|
return_vals
|
53
52
|
end
|
54
53
|
|
55
54
|
def import filepath
|
56
|
-
|
57
|
-
|
58
|
-
AdditionalMethods.import(filepath)
|
55
|
+
AdditionalMethods::Main.init()
|
56
|
+
AdditionalMethods::Main.import(filepath)
|
59
57
|
end
|
60
58
|
|
61
59
|
def set_args hash
|
62
|
-
|
60
|
+
AdditionalArguments::Main.import(hash)
|
63
61
|
end
|
64
62
|
|
65
63
|
def reset
|
66
|
-
AdditionalMethods.remove()
|
67
|
-
|
68
|
-
AdditionalVariables.remove()
|
64
|
+
AdditionalMethods::Main.remove()
|
65
|
+
AdditionalArguments::Main.remove()
|
66
|
+
AdditionalVariables::Main.remove()
|
69
67
|
@handler_chache = {}
|
70
68
|
end
|
71
69
|
|
72
70
|
def gen_handler filepath
|
73
|
-
|
71
|
+
AdditionalMethods::Main.init()
|
74
72
|
|
75
73
|
PokotarouHandler.new(gen_config(filepath))
|
76
74
|
end
|
77
75
|
|
78
76
|
def gen_handler_with_cache filepath
|
79
|
-
|
77
|
+
AdditionalMethods::Main.init()
|
80
78
|
|
81
79
|
@handler_cache ||= {}
|
82
80
|
@handler_cache[filepath] ||= PokotarouHandler.new(gen_config(filepath))
|
@@ -85,28 +83,13 @@ module Pokotarou
|
|
85
83
|
end
|
86
84
|
|
87
85
|
private
|
88
|
-
def init_proc
|
89
|
-
AdditionalMethods.init()
|
90
|
-
end
|
91
86
|
|
92
87
|
def gen_config filepath
|
93
|
-
contents = load_file(filepath)
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
def set_const_val_config contents
|
99
|
-
AdditionalVariables.set_const(contents)
|
100
|
-
end
|
101
|
-
|
102
|
-
def load_file filepath
|
103
|
-
case File.extname(filepath)
|
104
|
-
when ".yml"
|
105
|
-
return YmlLoader.load(filepath)
|
106
|
-
else
|
107
|
-
raise NotFoundLoader.new("not found loader")
|
108
|
-
end
|
88
|
+
contents = YAML.load_file(filepath).deep_symbolize_keys!
|
89
|
+
AdditionalVariables::Main.set_const(contents)
|
90
|
+
RegistrationConfigMaker::Main.gen(contents)
|
109
91
|
end
|
92
|
+
|
110
93
|
end
|
111
94
|
end
|
112
95
|
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
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Pokotarou
|
2
|
+
class ParserDomain
|
3
|
+
class << self
|
4
|
+
FOREIGN_KEY_REGEXP = /^F\|[A-Z][:A-Za-z0-9]*$/
|
5
|
+
def is_foreign_key? val
|
6
|
+
return false unless val.kind_of?(String)
|
7
|
+
FOREIGN_KEY_REGEXP =~ val
|
8
|
+
end
|
9
|
+
|
10
|
+
COLUMN_REGEXP = /^C\|[A-Z][:A-Za-z0-9]*\|[a-z][:a-z0-9]*$/
|
11
|
+
def is_column_symbol? val
|
12
|
+
return false unless val.kind_of?(String)
|
13
|
+
COLUMN_REGEXP =~ val
|
14
|
+
end
|
15
|
+
|
16
|
+
EXPRESSION_REGEXP = /^\s*<.*>\s*$/
|
17
|
+
def is_expression? val
|
18
|
+
return false unless val.kind_of?(String)
|
19
|
+
EXPRESSION_REGEXP =~ val
|
20
|
+
end
|
21
|
+
|
22
|
+
def is_array? val
|
23
|
+
val.instance_of?(Array)
|
24
|
+
end
|
25
|
+
|
26
|
+
def is_integer? val
|
27
|
+
val.instance_of?(Integer)
|
28
|
+
end
|
29
|
+
|
30
|
+
def is_need_update? val
|
31
|
+
return false unless val.kind_of?(Hash)
|
32
|
+
val.has_key?(:NeedUpdate)
|
33
|
+
end
|
34
|
+
|
35
|
+
def is_nil? val
|
36
|
+
val.nil?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "pokotarou/parser/parser.rb"
|
2
|
+
|
3
|
+
# for return variables
|
4
|
+
module Pokotarou
|
5
|
+
class ReturnExpressionParser < ExpressionParser
|
6
|
+
class << self
|
7
|
+
private
|
8
|
+
def output_error e
|
9
|
+
ParseError.new("Failed Const Expression parse:#{e.message}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def foreign_key_process val, _
|
13
|
+
# remove 'F|'
|
14
|
+
str_model = val.sub(FOREIGN_KEY_SYMBOL, "")
|
15
|
+
model = eval(str_model)
|
16
|
+
return model.pluck(:id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def column_symbol_process val, _
|
20
|
+
# remove 'C|'
|
21
|
+
str_model, column = val.sub(COLUMN_SYMBOL, "").split("|")
|
22
|
+
model = eval(str_model)
|
23
|
+
return model.pluck(column.to_sym)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|