pokotarou 1.1.5 → 1.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffa801fd4bb62051c3a7859bba742c5b4814a320b20a2069f3eefccb48754b92
4
- data.tar.gz: 5890e97baf6bd9994a4cb34830c9ecb5b36be6380e1198f76b70819cd8f1c9df
3
+ metadata.gz: f260f6c90328001a3c729c61542b44c05074d7c411956d5664252503fbac7823
4
+ data.tar.gz: 87fe8c2c794c6d005ec1a6d55f92c15ceb955ffea329459c7817eb08a785f9fb
5
5
  SHA512:
6
- metadata.gz: 600a0fca3e8584d1f498a016583a4e4341facefb465bdfd5362082fc1cdc485fa0ba3f61e31f045c299722a95ac83fa633c8ed1a7a8f2784d630f132e4344ea6
7
- data.tar.gz: c54bb8913a8d29e8604cd9d7e2b8e18495398dd1dd452ba208d4d38a831d6a2b456a08d8f618762e45b42c5c3ee36a713b7e2609fff4b7ad28d4772df6d3838c
6
+ metadata.gz: be2671c30d814129c9dd1e813bdff9c807555ca1ca57edaeea5a5dd23d770ce52d341314fb2a8d4d3f07926e4e95d36e6a457be0ba08345ac29c27ba96010560
7
+ data.tar.gz: d3f264b79c5fc9e8e6c910e819a2fb9b43bb477934bb2686a8abbd60f56750abd7297662c65abcc3f549d038029ccfef008b91a6995df7a3e0167c131daf8b51
@@ -1,14 +1,40 @@
1
1
  module AdditionalMethods
2
2
  class << self
3
- @filepath = nil
4
- attr_reader :filepath
3
+ attr_reader :filepathes
4
+ attr_reader :filepathes_from_yml
5
+
6
+ @filepathes = []
7
+ @filepathes_from_yml = []
8
+
9
+ def init
10
+ @filepathes ||= []
11
+ @filepathes_from_yml = []
12
+ end
5
13
 
6
14
  def import filepath
7
- @filepath = filepath
15
+ add(@filepathes, filepath)
16
+ end
17
+
18
+ def import_from_yml filepath
19
+ add(@filepathes_from_yml, filepath)
8
20
  end
9
21
 
10
22
  def remove
11
- @filepath = nil
23
+ @filepathes = []
24
+ @filepathes_from_yml = []
25
+ end
26
+
27
+ def remove_filepathes_from_yml
28
+ @filepathes_from_yml = []
29
+ end
30
+
31
+ private
32
+ def add filepath_arr, filepath
33
+ if filepath.instance_of?(Array)
34
+ filepath_arr.concat(filepath)
35
+ else
36
+ filepath_arr.push(filepath)
37
+ end
12
38
  end
13
39
  end
14
40
  end
@@ -1,24 +1,33 @@
1
1
  module AdditionalVariables
2
2
  class << self
3
3
  CONST_KEY = :"const'"
4
- @const = nil
4
+ @const = {}
5
5
  attr_reader :const
6
-
7
- def import data
8
- return unless data.has_key?(CONST_KEY)
6
+
7
+ def set_const data
8
+ set_const_variables(data)
9
+ end
10
+
11
+ def remove
12
+ @const = {}
13
+ end
14
+
15
+ def filepath
16
+ "pokotarou/additional_variables/def_variable.rb"
17
+ end
18
+
19
+ private
20
+ def set_const_variables data
21
+ return {} unless data.has_key?(CONST_KEY)
9
22
  @const = data[CONST_KEY]
10
23
 
11
24
  # parse expression configlation
12
25
  @const.each do |key, val|
13
- @const[key] = ConstExpressionParser.parse(val)
26
+ @const[key] = ConstParser.parse(val)
14
27
  end
15
28
 
16
29
  data.delete(CONST_KEY)
17
30
  end
18
31
 
19
- def filepath
20
- "pokotarou/additional_variables/def_const.rb"
21
- end
22
-
23
32
  end
24
33
  end
@@ -0,0 +1,3 @@
1
+ def const; AdditionalVariables.const end
2
+
3
+ def let; AdditionalVariables.let end
@@ -1,12 +1,14 @@
1
- class RegistError < StandardError; end
1
+ require "pokotarou/additional_variables/additional_variables.rb"
2
+
3
+ class RegisterError < StandardError; end
2
4
  class SeedError < StandardError; end
3
5
 
4
6
  class DataRegister
5
7
  class << self
6
8
  def register data
7
9
  # init maked to accumulate maded data
8
- maked = {}
9
- maked_col = {}
10
+ maked = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) }
11
+ maked_col = Hash.new { |h,k| h[k] = {} }
10
12
  # init model_data to cache data of model
11
13
  model_cache = {}
12
14
  ActiveRecord::Base.transaction do
@@ -56,7 +58,7 @@ class DataRegister
56
58
  print "\e[0m"
57
59
  puts ""
58
60
 
59
- raise RegistError.new
61
+ raise RegisterError.new
60
62
  end
61
63
  end
62
64
  end
@@ -155,6 +157,13 @@ class DataRegister
155
157
  end
156
158
  end
157
159
 
160
+ def update_let_key let, maked, maked_col
161
+ let.each do |key, val|
162
+ # TODO: run only maked_col or make key
163
+ AdditionalVariables.let[key] = ExpressionParser.parse(val, maked, maked_col)
164
+ end
165
+ end
166
+
158
167
  def apply_autoincrement? autoincrement_flg
159
168
  # default true
160
169
  return true if autoincrement_flg.nil?
@@ -199,17 +208,12 @@ class DataRegister
199
208
 
200
209
  def update_maked_data maked, sym_block, sym_model, col, seed
201
210
  # maked: { key: Model, value: {key: col1, val: [col1_element, col1_element]} }
202
- maked[sym_block] ||= {}
203
- maked[sym_block][sym_model] ||= {}
204
211
  maked[sym_block][sym_model][col] = seed
205
212
  end
206
213
 
207
214
  def update_maked_col maked_col, sym_model, column, vals
208
- maked_col[sym_model] ||= {}
209
215
  maked_col[sym_model][column] ||= []
210
216
  maked_col[sym_model][column].concat(vals)
211
-
212
- maked_col
213
217
  end
214
218
 
215
219
  def output_log log
@@ -1,7 +1,10 @@
1
+ require "pokotarou/additional_methods.rb"
2
+
1
3
  class DataStructure
2
4
  class << self
3
5
  def gen data
4
6
  execute_template_option_setting(data)
7
+ execute_import_setting(data)
5
8
  # return data structure bellow
6
9
  # [{ block_name => { model_name => { column_configration }}}, ...]
7
10
  data.reduce({}) do |acc, r|
@@ -17,6 +20,12 @@ class DataStructure
17
20
 
18
21
  private
19
22
 
23
+ def execute_import_setting data
24
+ return unless data.has_key?(:"import'")
25
+ AdditionalMethods.import_from_yml(data[:"import'"])
26
+ data.delete(:"import'")
27
+ end
28
+
20
29
  def execute_template_option_setting data
21
30
  return unless data.has_key?(:"template'")
22
31
  templates = data[:"template'"]
@@ -1,12 +1,22 @@
1
1
  require "pokotarou/additional_methods.rb"
2
2
  require "pokotarou/additional_variables/additional_variables.rb"
3
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
+
4
13
  class ParseError < StandardError; end
5
14
  FOREIGN_KEY_SYMBOL = "F|"
6
15
  COLUMN_SYMBOL = "C|"
7
16
 
8
17
  class ExpressionParser
9
18
  class << self
19
+
10
20
  def parse config_val, maked = nil, maked_col = nil
11
21
  begin
12
22
  case
@@ -29,6 +39,10 @@ class ExpressionParser
29
39
  # Integer
30
40
  when is_integer?(config_val)
31
41
  integer_process(config_val)
42
+
43
+ # NeedUpdate
44
+ when is_need_update?(config_val)
45
+ need_update_process(config_val, maked, maked_col)
32
46
 
33
47
  # Nil
34
48
  when is_nil?(config_val)
@@ -66,9 +80,7 @@ class ExpressionParser
66
80
  def expression_process val, maked, maked_col
67
81
  # remove '<>'
68
82
  expression = val.strip[1..-2]
69
- require AdditionalVariables.filepath if AdditionalVariables.const.present?
70
- require AdditionalMethods.filepath if AdditionalMethods.filepath.present?
71
- require Arguments.filepath if Arguments.filepath.present?
83
+ load_filepath()
72
84
  return self.parse(eval(expression), maked, maked_col)
73
85
  end
74
86
 
@@ -76,6 +88,10 @@ class ExpressionParser
76
88
  nothing_apply_process(val)
77
89
  end
78
90
 
91
+ def need_update_process val, maked, maked_col
92
+ return self.parse(val[:NeedUpdate], maked, maked_col)
93
+ end
94
+
79
95
  def nil_process val
80
96
  nothing_apply_process(val)
81
97
  end
@@ -160,14 +176,13 @@ class LoopExpressionParser < ExpressionParser
160
176
  end
161
177
 
162
178
  # for const variables
163
- class ConstExpressionParser < ExpressionParser
179
+ class ConstParser < ExpressionParser
164
180
  class << self
165
181
  private
166
182
  def expression_process val, _, _
167
183
  # remove '<>'
168
184
  expression = val.strip[1..-2]
169
- require AdditionalMethods.filepath if AdditionalMethods.filepath.present?
170
- require Arguments.filepath if Arguments.filepath.present?
185
+ load_filepath()
171
186
  return self.parse(eval(expression))
172
187
  end
173
188
 
@@ -208,6 +223,11 @@ def is_integer? val
208
223
  val.instance_of?(Integer)
209
224
  end
210
225
 
226
+ def is_need_update? val
227
+ return false unless val.kind_of?(Hash)
228
+ val.has_key?(:NeedUpdate)
229
+ end
230
+
211
231
  def is_nil? val
212
232
  val.nil?
213
233
  end
@@ -0,0 +1,38 @@
1
+ module Ptool
2
+ class << self
3
+ def gen_br_text
4
+ ["text\ntext"]
5
+ end
6
+
7
+ def gen_created_at n = 7, datetime_str = DateTime.now.to_s, with_random_time = false
8
+ datetime = DateTime.parse(datetime_str)
9
+ n.times.reduce([]) do |acc, index|
10
+ hours_num = 0
11
+ minutes_num = 0
12
+ hours_num, minutes_num = get_random_time() if with_random_time
13
+
14
+ acc.push(datetime + index.day + hours_num.hours + minutes_num.minutes)
15
+
16
+ acc
17
+ end
18
+ end
19
+
20
+ def gen_updated_at created_arr, with_random_time = false
21
+ created_arr.each.reduce([]) do |acc, created_datetime|
22
+ hours_num = 5
23
+ minutes_num = 10
24
+ hours_num, minutes_num = get_random_time() if with_random_time
25
+
26
+ acc.push(created_datetime + hours_num.hours + minutes_num.minutes)
27
+
28
+ acc
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def get_random_time
35
+ [ rand(24) + 1, second_num = rand(59) + 1]
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module Pokotarou
2
- VERSION = '1.1.5'
2
+ VERSION = '1.1.6'
3
3
  end
data/lib/pokotarou.rb CHANGED
@@ -9,15 +9,24 @@ module Pokotarou
9
9
 
10
10
  class << self
11
11
  def execute input
12
+ AdditionalMethods.init()
13
+
12
14
  # if input is filepath, generate config_data
13
- if input.kind_of?(String)
14
- DataRegister.register(gen_config(input))
15
- else
16
- DataRegister.register(input)
17
- end
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
18
25
  end
19
26
 
20
27
  def pipeline_execute input_arr
28
+ AdditionalMethods.init()
29
+
21
30
  return_vals = []
22
31
  input_arr.each do |e|
23
32
  handler = gen_handler_with_cache(e[:filepath])
@@ -37,6 +46,7 @@ module Pokotarou
37
46
  set_args(e[:args])
38
47
 
39
48
  return_vals << Pokotarou.execute(handler.get_data())
49
+ AdditionalMethods.remove_filepathes_from_yml()
40
50
  end
41
51
 
42
52
  return_vals
@@ -53,6 +63,7 @@ module Pokotarou
53
63
  def reset
54
64
  AdditionalMethods.remove()
55
65
  Arguments.remove()
66
+ AdditionalVariables.remove()
56
67
  @handler_chache = {}
57
68
  end
58
69
 
@@ -76,7 +87,7 @@ module Pokotarou
76
87
  end
77
88
 
78
89
  def set_const_val_config contents
79
- AdditionalVariables.import(contents)
90
+ AdditionalVariables.set_const(contents)
80
91
  end
81
92
 
82
93
  def load_file filepath
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pokotarou
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kashiwara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-15 00:00:00.000000000 Z
11
+ date: 2020-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -51,7 +51,7 @@ files:
51
51
  - lib/pokotarou.rb
52
52
  - lib/pokotarou/additional_methods.rb
53
53
  - lib/pokotarou/additional_variables/additional_variables.rb
54
- - lib/pokotarou/additional_variables/def_const.rb
54
+ - lib/pokotarou/additional_variables/def_variable.rb
55
55
  - lib/pokotarou/arguments/arguments.rb
56
56
  - lib/pokotarou/arguments/def_args.rb
57
57
  - lib/pokotarou/array_operation.rb
@@ -61,6 +61,7 @@ files:
61
61
  - lib/pokotarou/expression_parser.rb
62
62
  - lib/pokotarou/file_loader.rb
63
63
  - lib/pokotarou/option.rb
64
+ - lib/pokotarou/p_tool.rb
64
65
  - lib/pokotarou/pokotarou_handler.rb
65
66
  - lib/pokotarou/seeder.rb
66
67
  - lib/pokotarou/version.rb
@@ -1 +0,0 @@
1
- def const; AdditionalVariables.const end