pokotarou 0.1.2 → 0.1.3

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: 2405129bdaf545e80c102a188d1feca1c39462c0ef4f8a59df4f66eef228c8f4
4
- data.tar.gz: 75d205d49492a61ec5d621e23043ec31fbfd397ec08f2b2775b0f64746cb4d81
3
+ metadata.gz: 7ac5ca9e6a97f214d20ea830f738f3b444ab696dd83005d0e469bc7f42f2d7d0
4
+ data.tar.gz: 8e58ee4c95f0465de660f5c188e9f3b46d3311a4391b0ec1076a855d8d2bb927
5
5
  SHA512:
6
- metadata.gz: dedda38c93623417cd069c56caa32e335c28e3c05c809533a3adb2cd4904f3ef5d86cd2d309587188693120bce3e523cc766fa70dd80ce1d155f585cd7058de0
7
- data.tar.gz: b4c8c1a7f6a1587b5357b3d6c1ced595406c42516acf4db3c3db9657dad7d26f31c7897f586c3517320875a464c09dd88e7537f74d363cc2146d05ad2f95a345
6
+ metadata.gz: 01761775a3d8204d369de8aab3e7bcc52554e96ba89b1aa164b6c25a11a090f99d90f4c9a37fc0426143c0ff24ee8e409adc8b735ddafca0b8f5ebf35d400c0d
7
+ data.tar.gz: 608db2c1580ea6151b370e6cb8fb0c97e9f7b902232f6bd73cec988674cb52d7f4e20189092bdc926937d1694307bcae6e03ea825778ab5d37184d8bea0a0aca
data/README.md CHANGED
@@ -13,7 +13,6 @@ You don't have to write a program for seeder
13
13
 
14
14
  ### Fast speed
15
15
  If it is the following table, 10,000 records can regist in 0.4s on average
16
- Also, If you enable 'optimize option', 10,000 records can regist in 0.23s on average
17
16
 
18
17
  |Field|Type|NULL|
19
18
  |:---|:---|:---|
@@ -320,17 +319,6 @@ Default:
320
319
  id: [100, 101, 102]
321
320
  ```
322
321
 
323
- #### Optimize
324
-
325
- If you enable 'optimize', Pokotarou Run a query builder, but disable validation
326
-
327
- ```
328
- Default:
329
- Pref:
330
- loop: 3
331
- optimaize: true
332
- ```
333
-
334
322
  #### Pokotarou Handler
335
323
 
336
324
  if you use Pokotarou handler, can update pokotarou's parameter
@@ -378,7 +366,7 @@ Default:
378
366
  Pref:
379
367
  loop: 3
380
368
  col:
381
- name: ["北海道", "青森県", "岩手県"]
369
+ name: ["Hokkaido", "Aomori", "Iwate"]
382
370
  convert:
383
371
  name: ["empty(0..0)", "nil(1..2)"]
384
372
  ```
@@ -392,4 +380,4 @@ Default:
392
380
  | empty | convert val to empty |
393
381
  | nil | convert val to nil |
394
382
  | big_text | convert val to big_text("text" * 50) |
395
- | br_text | convert val to br_text("text\n" * 5) |
383
+ | br_text | convert val to br_text("text\n" * 5) |
@@ -0,0 +1,13 @@
1
+ class NothingDataError < StandardError; end
2
+ class ArrayOperation
3
+ class << self
4
+ # return rotated val in passed array
5
+ def get_rotated_val array, size, cnt
6
+ raise NothingDataError.new("Nothing seed data") if array.nil?
7
+ raise NothingDataError.new("Seed data is empty") if size.zero?
8
+ x = (size + cnt) / size
9
+
10
+ array[ size + cnt - size * x ]
11
+ end
12
+ end
13
+ end
@@ -165,7 +165,7 @@ class DataRegister
165
165
  end
166
166
 
167
167
  def get_seed arr, size, cnt
168
- get_rotated_val(arr, size, cnt)
168
+ ArrayOperation.get_rotated_val(arr, size, cnt)
169
169
  end
170
170
 
171
171
  def get_seed_with_option arr, size, option, cnt
@@ -11,8 +11,6 @@ class ExpressionParser
11
11
  case
12
12
  when config_val.instance_of?(Array)
13
13
  return config_val
14
- when config_val.nil?
15
- return nil
16
14
  when is_foreign_key?(config_val)
17
15
  # remove 'F|'
18
16
  str_model = config_val.sub(FOREIGN_KEY_SYMBOL, "")
@@ -9,6 +9,7 @@ class Option
9
9
 
10
10
  def apply arr, size, option_conf, cnt = 0
11
11
  selected_val = select(option_conf[:select], arr, size, cnt)
12
+
12
13
  add(option_conf[:add], selected_val, cnt)
13
14
  end
14
15
 
@@ -28,11 +29,14 @@ class Option
28
29
 
29
30
  def select option, arr, size, cnt
30
31
  return arr.sample if option == "random"
32
+
31
33
  # default return rotate
32
- get_rotated_val(arr, size, cnt)
34
+ ArrayOperation.get_rotated_val(arr, size, cnt)
33
35
  end
34
36
 
35
37
  def add option, val, cnt
38
+ # if val is nil, return nil
39
+ return nil if val.nil?
36
40
  # use '+', not use '<<' to avoid destructive effect
37
41
  return val + "_#{cnt}" if option == "add_id"
38
42
 
@@ -3,14 +3,30 @@ class PokotarouHandler
3
3
  @data = data
4
4
  end
5
5
 
6
+ def delete_block sym_block
7
+ @data.delete(sym_block)
8
+ end
9
+
6
10
  def delete_model sym_block, sym_class
7
11
  @data[sym_block].delete(sym_class)
8
12
  end
9
13
 
14
+ def delete_col sym_block, sym_class, sym_col
15
+ exists_content = ->(key){ @data[sym_block][sym_class][key].present? }
16
+
17
+ @data[sym_block][sym_class][:col].delete(sym_col) if exists_content.call(:col)
18
+ @data[sym_block][sym_class][:option].delete(sym_col) if exists_content.call(:option)
19
+ @data[sym_block][sym_class][:convert].delete(sym_col) if exists_content.call(:convert)
20
+ end
21
+
10
22
  def change_loop sym_block, sym_class, n
11
23
  @data[sym_block][sym_class][:loop] = n
12
24
  end
13
25
 
26
+ def change_col sym_block, sym_class, sym_col, arr
27
+ @data[sym_block][sym_class][:col][sym_col] = arr
28
+ end
29
+
14
30
  def get_data
15
31
  @data
16
32
  end
@@ -1,3 +1,3 @@
1
1
  module Pokotarou
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
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: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kashiwara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-03 00:00:00.000000000 Z
11
+ date: 2019-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -50,12 +50,12 @@ files:
50
50
  - Rakefile
51
51
  - lib/pokotarou.rb
52
52
  - lib/pokotarou/additional_methods.rb
53
+ - lib/pokotarou/array_operation.rb
53
54
  - lib/pokotarou/converter.rb
54
55
  - lib/pokotarou/data_register.rb
55
56
  - lib/pokotarou/data_structure.rb
56
57
  - lib/pokotarou/expression_parser.rb
57
58
  - lib/pokotarou/loader.rb
58
- - lib/pokotarou/my_mthods.rb
59
59
  - lib/pokotarou/option.rb
60
60
  - lib/pokotarou/pokotarou_handler.rb
61
61
  - lib/pokotarou/query_builder.rb
@@ -1,9 +0,0 @@
1
- class NothingDataError < StandardError; end
2
-
3
- # return rotated val in passed array
4
- def get_rotated_val array, size, cnt
5
- raise NothingDataError.new("Nothing seed data") if array.nil?
6
- raise NothingDataError.new("Seed data is empty") if size.zero?
7
- x = (size + cnt) / size
8
- array[ size + cnt - size * x ]
9
- end