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.
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
@@ -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
@@ -0,0 +1,18 @@
1
+ require "pokotarou/parser/parser.rb"
2
+
3
+ # for seed data
4
+ module Pokotarou
5
+ class SeedExpressionParser < ExpressionParser
6
+ class << self
7
+ private
8
+ def nothing_apply_process val
9
+ # for escape \\
10
+ val.instance_of?(String) ? [val.tr("\\","")] : [val]
11
+ end
12
+
13
+ def output_error e
14
+ raise ParseError.new("Failed Seed Expression parse:#{e.message}")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module Pokotarou
2
+ module RegistrationConfigMaker
3
+ class ColumnDomain
4
+ class << self
5
+ def is_foreign_key? col_name_sym, foreign_key_dict
6
+ return foreign_key_dict[col_name_sym].present?
7
+ end
8
+
9
+ ENUM_REGEX = /^enum(\s*.)*$/
10
+ def is_enum? sql_type
11
+ return false unless sql_type.kind_of?(String)
12
+ return ENUM_REGEX =~ sql_type
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,48 @@
1
+ module Pokotarou
2
+ module RegistrationConfigMaker
3
+ class ConfigDomain
4
+ class << self
5
+ def has_dush_import_syntax? all_content
6
+ return false if all_content.blank?
7
+ return all_content.has_key?(:"import'")
8
+ end
9
+
10
+ def has_dush_template_syntax? all_content
11
+ return false if all_content.blank?
12
+ return all_content.has_key?(:"template'")
13
+ end
14
+
15
+ def has_dush_template_path_syntax? all_content
16
+ return false if all_content.blank?
17
+ return all_content.has_key?(:"template_path'")
18
+ end
19
+
20
+ def has_dush_preset_path_syntax? all_content
21
+ return false if all_content.blank?
22
+ return all_content.has_key?(:"preset_path'")
23
+ end
24
+
25
+ def has_grouping_syntax? model_content
26
+ return false if model_content.blank?
27
+ return model_content.has_key?(:grouping)
28
+ end
29
+
30
+ def has_template_syntax? model_content
31
+ return false if model_content.blank?
32
+ return model_content.has_key?(:template)
33
+ end
34
+
35
+ def has_seed_data_syntax? col_config, col_name_sym
36
+ return false if col_config.blank?
37
+ return col_config.has_key?(col_name_sym)
38
+ end
39
+
40
+ DUSH_OPTION_REGEX = /^.*\'$/
41
+ def is_dush_syntax? syntax
42
+ return false unless syntax.kind_of?(String)
43
+ return DUSH_OPTION_REGEX =~ syntax
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,28 @@
1
+ module Pokotarou
2
+ module RegistrationConfigMaker
3
+ class GroupingOptionSetter
4
+ class << self
5
+ def set seed_config
6
+ seed_config[:grouping].each do |grouping_key, cols|
7
+ set_grouping_data(:col, seed_config, grouping_key, cols)
8
+ set_grouping_data(:option, seed_config, grouping_key, cols)
9
+ set_grouping_data(:convert, seed_config, grouping_key, cols)
10
+ end
11
+
12
+ seed_config.delete(:grouping)
13
+ end
14
+
15
+ private
16
+ def set_grouping_data config_name, seed_config, grouping_key, cols
17
+ return if seed_config[config_name].blank?
18
+ return unless seed_config[config_name].has_key?(grouping_key)
19
+ cols.each do |e|
20
+ seed_config[config_name][e.to_sym] = seed_config[config_name][grouping_key]
21
+ end
22
+
23
+ seed_config[config_name].delete(grouping_key)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ require "pokotarou/additional_methods/main"
2
+ module Pokotarou
3
+ module RegistrationConfigMaker
4
+ class ImportOptionSetter
5
+ class << self
6
+ def set all_content
7
+ ::Pokotarou::AdditionalMethods::Main.import_from_yml(all_content[:"import'"])
8
+ all_content.delete(:"import'")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,65 @@
1
+ require "pokotarou/registration_config_maker/column_domain.rb"
2
+ require "pokotarou/registration_config_maker/config_domain.rb"
3
+ require "pokotarou/registration_config_maker/import_option_setter.rb"
4
+ require "pokotarou/registration_config_maker/template_option_setter.rb"
5
+ require "pokotarou/registration_config_maker/grouping_option_setter.rb"
6
+ require "pokotarou/registration_config_maker/model_option_setter.rb"
7
+ require "pokotarou/registration_config_maker/preset_option_setter.rb"
8
+
9
+ module Pokotarou
10
+ module RegistrationConfigMaker
11
+ class Main
12
+ class << self
13
+ def gen all_content
14
+ set_header_config(all_content)
15
+ all_content.reduce({}) do |acc, block_content|
16
+ block_name = block_content.first
17
+ block_config = block_content.second
18
+
19
+ if ConfigDomain.is_dush_syntax?(block_name.to_s)
20
+ acc[block_name] = block_config
21
+ else
22
+ set_model_config_to_acc(acc, block_content)
23
+ end
24
+
25
+ acc
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def set_header_config all_content
32
+ set_template_option(all_content)
33
+ set_preset_option(all_content)
34
+ set_import_option(all_content)
35
+ end
36
+
37
+ def set_import_option all_content
38
+ return unless ConfigDomain.has_dush_import_syntax?(all_content)
39
+ ImportOptionSetter.set(all_content)
40
+ end
41
+
42
+ def set_preset_option all_content
43
+ return all_content unless ConfigDomain.has_dush_preset_path_syntax?(all_content)
44
+ PresetOptionSetter.set(all_content)
45
+ end
46
+
47
+ def set_template_option all_content
48
+ return if !ConfigDomain.has_dush_template_syntax?(all_content) && !ConfigDomain.has_dush_template_path_syntax?(all_content)
49
+ TemplateOptionSetter.set(all_content)
50
+ end
51
+
52
+ def set_model_config_to_acc acc, block_content
53
+ set_grouping_option(block_content.second)
54
+ ModelOptionSetter.set(acc, block_content)
55
+ end
56
+
57
+ def set_grouping_option block_content
58
+ block_content.each do |_, model_content|
59
+ GroupingOptionSetter.set(model_content) if ConfigDomain.has_grouping_syntax?(model_content)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,65 @@
1
+ module Pokotarou
2
+ module RegistrationConfigMaker
3
+ class ModelOptionSetter
4
+ class << self
5
+ def set acc, block_content
6
+ block_name = block_content.first
7
+ block_config = block_content.second
8
+ acc[block_name] = {}
9
+
10
+ block_config.each do |model_content|
11
+ model_name = model_content.first
12
+ model_config = model_content.second
13
+ set_column_type(model_config, model_name)
14
+ acc[block_name][model_name] = model_config
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def set_column_type model_config, model_name
21
+ model = eval(model_name.to_s)
22
+ foreign_key_data = get_foreign_key_data(model)
23
+
24
+ model_config[:col] ||= {}
25
+ model.columns.each do |e|
26
+ symbol_col_name = e.name.to_sym
27
+
28
+ next if ConfigDomain.has_seed_data_syntax?(model_config[:col], symbol_col_name)
29
+
30
+ # set foreign_key info
31
+ if ColumnDomain.is_foreign_key?(symbol_col_name, foreign_key_data)
32
+ # don't set :type val for don't run default seeder
33
+ # use F function for set foreign key
34
+ model_config[:col][symbol_col_name] = "F|#{foreign_key_data[symbol_col_name].to_s}"
35
+ else
36
+ model_config[:type] ||= {}
37
+ model_config[:type][symbol_col_name] = e.type.to_s
38
+ end
39
+
40
+ # set enum info
41
+ model_config[:enum] ||= {}
42
+ if ColumnDomain.is_enum?(e.sql_type.to_s)
43
+ model_config[:enum][symbol_col_name] = e.sql_type.to_s[5..-2].tr("'", "").split(",")
44
+ end
45
+
46
+ end
47
+ end
48
+
49
+ def get_foreign_key_data model
50
+ relations = model.reflect_on_all_associations(:belongs_to)
51
+ return {} if relations.empty?
52
+ relations.reduce({})do |acc, r|
53
+
54
+ relation_model = r.name.to_s.camelize
55
+ if Object.const_defined?(relation_model.to_sym)
56
+ acc[r.foreign_key.to_sym] = eval(relation_model)
57
+ end
58
+
59
+ acc
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,45 @@
1
+ require "pokotarou/registration_config_maker/config_domain.rb"
2
+ module Pokotarou
3
+ module RegistrationConfigMaker
4
+ class PresetOptionSetter
5
+ class << self
6
+ def set all_content
7
+ preset_content = {}
8
+
9
+ all_content[:"preset_path'"].each do |path|
10
+ YAML.load_file(path).deep_symbolize_keys!.each do |preset|
11
+ preset_content[preset.first] = preset.second
12
+ end
13
+ end
14
+
15
+ # 使用済みのKeyなので削除
16
+ all_content.delete(:"preset_path'")
17
+
18
+ # hashの順番を更新するために一度全てのKeyを消す
19
+ tmp = {}
20
+ all_content.each do |config|
21
+ key = config.first
22
+ value = config.second
23
+ tmp[key] = value
24
+
25
+ all_content.delete(key)
26
+ end
27
+
28
+ # presetを先に展開する必要があるので、再代入して順番を変更する
29
+ merge(all_content, preset_content)
30
+ merge(all_content, tmp)
31
+ end
32
+
33
+ private
34
+ def merge all_content, merge_hash
35
+ merge_hash.each do |config|
36
+ key = config.first
37
+ value = config.second
38
+ all_content[key] = value
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,63 @@
1
+ require "pokotarou/registration_config_maker/config_domain.rb"
2
+ module Pokotarou
3
+ module RegistrationConfigMaker
4
+ class TemplateOptionSetter
5
+ class << self
6
+ def set all_content
7
+ templates = fetch_template_option(all_content)
8
+
9
+ all_content.each do |key, block_content|
10
+ next if ConfigDomain.is_dush_syntax?(key.to_s)
11
+ set_template_option(block_content, templates)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def fetch_template_option all_content
18
+ templates = ConfigDomain.has_dush_template_syntax?(all_content) ? all_content.delete(:"template'") : {}
19
+
20
+ if ConfigDomain.has_dush_template_path_syntax?(all_content)
21
+ merge_template_from_template_path(all_content, templates)
22
+ end
23
+
24
+ return templates
25
+ end
26
+
27
+ def merge_template_from_template_path all_content, templates
28
+ template_path = all_content.delete(:"template_path'")
29
+ template_path.each do |e|
30
+ YAML.load_file(e).deep_symbolize_keys!.each do |loaded_template|
31
+ templates[loaded_template.first] = loaded_template.second
32
+ end
33
+ end
34
+ end
35
+
36
+ def set_template_option block_content, templates
37
+ block_content.each do |key, model_content|
38
+ next unless ConfigDomain.has_template_syntax?(model_content)
39
+ template_copy = get_template_copy(model_content[:template], templates)
40
+ deep_overwrite(model_content, template_copy)
41
+ # update config all_config
42
+ block_content[key] = template_copy
43
+ end
44
+ end
45
+
46
+ def get_template_copy template_name, templates
47
+ return templates[template_name.to_sym].deep_dup
48
+ end
49
+
50
+ def deep_overwrite source, destination
51
+ source.each do |key, val|
52
+ if val.kind_of?(Hash)
53
+ destination[key] ||= {}
54
+ deep_overwrite(val, destination[key])
55
+ else
56
+ destination[key] = val
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end