pokotarou 1.1.7 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pokotarou.rb +146 -73
  3. data/lib/pokotarou/additional_arguments/main.rb +24 -0
  4. data/lib/pokotarou/additional_methods/main.rb +49 -0
  5. data/lib/pokotarou/additional_variables/main.rb +28 -0
  6. data/lib/pokotarou/parser/const_parser.rb +25 -0
  7. data/lib/pokotarou/parser/loop_expression_parser.rb +32 -0
  8. data/lib/pokotarou/parser/parser.rb +108 -0
  9. data/lib/pokotarou/parser/parser_domain.rb +40 -0
  10. data/lib/pokotarou/parser/return_expression_parser..rb +27 -0
  11. data/lib/pokotarou/parser/seed_data_expression_parser.rb +18 -0
  12. data/lib/pokotarou/registration_config_maker/column_domain.rb +17 -0
  13. data/lib/pokotarou/registration_config_maker/config_domain.rb +48 -0
  14. data/lib/pokotarou/registration_config_maker/grouping_option_setter.rb +28 -0
  15. data/lib/pokotarou/registration_config_maker/import_option_setter.rb +13 -0
  16. data/lib/pokotarou/registration_config_maker/main.rb +65 -0
  17. data/lib/pokotarou/registration_config_maker/model_option_setter.rb +65 -0
  18. data/lib/pokotarou/registration_config_maker/preset_option_setter.rb +45 -0
  19. data/lib/pokotarou/registration_config_maker/template_option_setter.rb +63 -0
  20. data/lib/pokotarou/registration_config_updater/array_utils.rb +15 -0
  21. data/lib/pokotarou/registration_config_updater/convert_config.rb +28 -0
  22. data/lib/pokotarou/registration_config_updater/default_value_maker.rb +32 -0
  23. data/lib/pokotarou/registration_config_updater/main.rb +170 -0
  24. data/lib/pokotarou/registration_config_updater/option_config.rb +53 -0
  25. data/lib/pokotarou/seed_data_register/main.rb +81 -0
  26. data/lib/pokotarou/version.rb +1 -1
  27. metadata +26 -17
  28. data/lib/pokotarou/additional_methods.rb +0 -40
  29. data/lib/pokotarou/additional_variables/additional_variables.rb +0 -33
  30. data/lib/pokotarou/additional_variables/def_variable.rb +0 -3
  31. data/lib/pokotarou/arguments/arguments.rb +0 -24
  32. data/lib/pokotarou/arguments/def_args.rb +0 -1
  33. data/lib/pokotarou/array_operation.rb +0 -13
  34. data/lib/pokotarou/converter.rb +0 -23
  35. data/lib/pokotarou/data_register.rb +0 -230
  36. data/lib/pokotarou/data_structure.rb +0 -187
  37. data/lib/pokotarou/expression_parser.rb +0 -233
  38. data/lib/pokotarou/file_loader.rb +0 -16
  39. data/lib/pokotarou/option.rb +0 -46
  40. data/lib/pokotarou/pokotarou_handler.rb +0 -37
  41. data/lib/pokotarou/seeder.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ba6e2645cf94bcf9be0f58eed852f3a72aaa781a0c7cd3464bae15198d06995
4
- data.tar.gz: 7e0a7526bf12d795d141a5ab1c5adf798011c397a1c6a5897e7562da5d96385a
3
+ metadata.gz: 12597f8db907a8280e94b6007de1bdd0b77e63501a3123f202e6fec7786c7bcd
4
+ data.tar.gz: 15072090ef575f4e34eba0e403c04552f22046a3ca1cc3effbe4d5cf4d8625e1
5
5
  SHA512:
6
- metadata.gz: 5d60e710e9da88f544e396ee0bf8bd2fdbfd9f71691eb326c6f38caccef07d07c7424b5804936432947ad7d5c4b2d787e8ce98f3d1e4fada1f161ce465be46ef
7
- data.tar.gz: 127ec4685eedae5f3dfa6f0b19d82c3d64aa8ef2fe16f8c14450e434d891796ffc9059d42c30bb5f5550dbd5994951d5bb4a18e1f9f2db440c05280eb95cea80
6
+ metadata.gz: ff32c23a477fc3c4a618c6dce3eff767e413b63c37ec8a21dc83c6bc65d41b62c4c37109ab4faa0e96086b00eb48b673ca79184d1f764fe94b6c39bf1c9b6102
7
+ data.tar.gz: 84d896e8fc5418a08ce555aaf40fe327ee245d9e081a76ebb632789eb10c5dee6669d876bd7eeea7fbdfac2b734c4d4fcb47738cd06f46ea90ac9f5a26c8d30a
data/lib/pokotarou.rb CHANGED
@@ -1,104 +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 NotFoundLoader < StandardError; end
9
-
10
- class << self
11
- def execute input
12
- AdditionalMethods.init()
13
-
14
- # if input is filepath, generate config_data
15
- return_val =
16
- if input.kind_of?(String)
17
- DataRegister.register(gen_config(input))
18
- else
19
- DataRegister.register(input)
20
- end
21
-
22
- AdditionalMethods.remove_filepathes_from_yml()
23
-
24
- return_val
25
- end
26
-
27
- def pipeline_execute input_arr
28
- AdditionalMethods.init()
29
-
30
- return_vals = []
31
- input_arr.each do |e|
32
- handler = gen_handler_with_cache(e[:filepath])
33
-
34
- if e[:change_data].present?
35
- e[:change_data].each do |block, config|
36
- config.each do |model, seed|
37
- seed.each do |col_name, val|
38
- handler.change_seed(block, model, col_name, val)
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
- e[:args] ||= {}
45
- e[:args][:passed_return_val] = return_vals.last
46
- set_args(e[:args])
47
-
48
- return_vals << Pokotarou.execute(handler.get_data())
49
- AdditionalMethods.remove_filepathes_from_yml()
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
- return_vals
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
- AdditionalMethods.init()
57
- AdditionalMethods.import(filepath)
108
+ Operater.import(filepath)
58
109
  end
59
110
 
60
111
  def set_args hash
61
- Arguments.import(hash)
112
+ Operater.set_args(hash)
62
113
  end
63
114
 
64
115
  def reset
65
- AdditionalMethods.remove()
66
- Arguments.remove()
67
- AdditionalVariables.remove()
68
- @handler_chache = {}
116
+ Operater.reset()
69
117
  end
70
118
 
71
119
  def gen_handler filepath
72
- PokotarouHandler.new(gen_config(filepath))
120
+ Operater.gen_handler(filepath)
73
121
  end
74
122
 
75
123
  def gen_handler_with_cache filepath
76
- @handler_cache ||= {}
77
- @handler_cache[filepath] ||= PokotarouHandler.new(gen_config(filepath))
78
-
79
- @handler_cache[filepath].deep_dup
124
+ Operater.gen_handler_with_cache(filepath)
80
125
  end
126
+ end
127
+ end
81
128
 
82
- private
129
+ class PokotarouHandler
130
+ def initialize data
131
+ @data = data
132
+ end
83
133
 
84
- def gen_config filepath
85
- contents = load_file(filepath)
86
- set_const_val_config(contents)
87
- DataStructure.gen(contents)
88
- end
134
+ def make
135
+ ::Pokotarou::Operater.execute(get_data())
136
+ end
89
137
 
90
- def set_const_val_config contents
91
- AdditionalVariables.set_const(contents)
92
- end
138
+ def delete_block sym_block
139
+ @data.delete(sym_block)
140
+ end
93
141
 
94
- def load_file filepath
95
- case File.extname(filepath)
96
- when ".yml"
97
- return YmlLoader.load(filepath)
98
- else
99
- raise NotFoundLoader.new("not found loader")
100
- end
101
- end
142
+ def delete_model sym_block, sym_class
143
+ @data[sym_block].delete(sym_class)
144
+ end
102
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)
103
152
  end
104
- end
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