pokotarou 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38bd381d74ed4731fdb2c3af3211af492cea80f5e08f7d0cd42944e2b722aa8c
4
- data.tar.gz: 161e98919c174d0cd170c9401d70d65bc5a2311912e8201618c6fac3c841580b
3
+ metadata.gz: 62fc987dc55f5258ed2d6a3a8efa366b245795bd380b4178bc769d500ec46338
4
+ data.tar.gz: 265f6f6918e1b92b0852971c7b925ba77b883f83065ecd2152204e06505b639e
5
5
  SHA512:
6
- metadata.gz: 5a39ece97d618b6670b69e3db80064b3a499ac315f918293550f807c7a5b8d7360900631bbd32710c05445ff9b780865e7ea621c66f59a5712252d612f145872
7
- data.tar.gz: a3d17bd0d59f04e373ac31039d1399592e43aec29fba8802b509b690f97c00780b228529e01c883276f046162c906059ac7d7e54e1289e50926e6910524a5a92
6
+ metadata.gz: 10ede458b68376974383c29abcb0932c50c721b1115b5818ebc7aadd5cbf4fb6faa45c54037bf6d6c87ea128d9f89f1e1e2fedbeeb7fb31377a9cb1cc1638bab
7
+ data.tar.gz: ff000b11427a3b70d9a5ffc3066245b763115af51c2e8a736c0c8a4f7f9d56384355289cb74e24bb1642163577ba61dc21cf2a3dbcc52dc96888c3f40a95db67
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- ![s_PokotarouLogo](https://user-images.githubusercontent.com/52961642/61586183-ef59b580-aba8-11e9-83b0-19eac7339982.png)
2
-
1
+ ![s_PokotarouLogo](https://user-images.githubusercontent.com/52961642/61586183-ef59b580-aba8-11e9-83b0-19eac7339982.png)
2
+ [![Gem Version](https://badge.fury.io/rb/pokotarou.svg)](https://badge.fury.io/rb/pokotarou)
3
3
  [![Build Status](https://travis-ci.org/Tamatebako0205/Pokotarou.svg?branch=master)](https://travis-ci.org/Tamatebako0205/Pokotarou)
4
4
 
5
5
  Pokotarou is convenient seeder of 'Ruby on Rails' that uses .yml
@@ -0,0 +1,23 @@
1
+ class Converter
2
+ class << self
3
+ PARENTHESES = /\(.*\)/
4
+ def convert arr, config
5
+ return arr if config.nil?
6
+ config.each do |e|
7
+ range = eval(e.slice(PARENTHESES).delete("()"))
8
+ convert_name = e.gsub(PARENTHESES, "")
9
+ arr[range] = get_val(convert_name, range.size)
10
+ end
11
+
12
+ arr
13
+ end
14
+
15
+ def get_val convert_name, size
16
+ return [""] * size if convert_name == "empty"
17
+ return [nil] * size if convert_name == "nil"
18
+ return ["text\n" * 5] * size if convert_name == "br_text"
19
+ return ["text" * 50] * size if convert_name == "big_text"
20
+ end
21
+
22
+ end
23
+ end
@@ -91,9 +91,9 @@ class DataRegister
91
91
 
92
92
  def get_seed_arr model, sym_block, sym_model, config_data, maked
93
93
  options = config_data[:option]
94
+ convert_conf = config_data[:convert]
94
95
  loop_size = config_data[:loop]
95
96
 
96
-
97
97
  if apply_autoincrement?(config_data[:autoincrement])
98
98
  set_autoincrement(config_data, model, loop_size)
99
99
  end
@@ -103,12 +103,22 @@ class DataRegister
103
103
  # set expand expression '<>' and ':' and so on...
104
104
  set_expand_expression(config_data, key, val, maked)
105
105
  expanded_val = config_data[:col][key]
106
+ expanded_val_size = expanded_val.size
107
+
108
+ # apply converter
109
+ if convert_conf.present?
110
+ expanded_val = Converter.convert(expanded_val, convert_conf[key])
111
+ end
112
+
113
+ # get option configration
106
114
  option_conf = options.nil? ? nil : Option.gen(options[key])
115
+
107
116
  # Take count yourself, because .with_index is slow
108
117
  cnt = 0
109
118
  seeds =
110
119
  loop_size.times.map do
111
- seed = option_conf.nil? ? get_seed(expanded_val, cnt) : get_seed_with_option(expanded_val, option_conf, cnt)
120
+ seed =
121
+ option_conf.nil? ? get_seed(expanded_val, expanded_val_size, cnt) : get_seed_with_option(expanded_val, expanded_val_size, option_conf, cnt)
112
122
  cnt += 1
113
123
 
114
124
  seed
@@ -135,10 +145,12 @@ class DataRegister
135
145
 
136
146
  def set_autoincrement config_data, model, loop_size
137
147
  last_record = model.last
138
- # use pluck to optimize(suppress make object)
139
- additions = model.all.pluck(:id).size + loop_size
140
- latest_id = last_record.nil? ? 1 : last_record.id + 1
141
- config_data[:col][:id] = [*latest_id..additions]
148
+ # if id is nothing, get 0
149
+ current_id = last_record.nil? ? 0 : last_record.id
150
+ additions = current_id + loop_size
151
+ next_id = current_id + 1
152
+
153
+ config_data[:col][:id] = [*next_id..additions]
142
154
  end
143
155
 
144
156
  def set_expand_expression config_data, key, val, maked
@@ -152,12 +164,12 @@ class DataRegister
152
164
  LoopExpressionParser.parse(config_data[:loop], maked)
153
165
  end
154
166
 
155
- def get_seed arr, cnt
156
- get_rotated_val(arr, cnt)
167
+ def get_seed arr, size, cnt
168
+ get_rotated_val(arr, size, cnt)
157
169
  end
158
170
 
159
- def get_seed_with_option arr, option, cnt
160
- Option.apply(arr, option, cnt)
171
+ def get_seed_with_option arr, size, option, cnt
172
+ Option.apply(arr, size, option, cnt)
161
173
  end
162
174
 
163
175
  def update_maked_data maked, sym_block, sym_model, col, seed
@@ -1,9 +1,8 @@
1
1
  class NothingDataError < StandardError; end
2
2
 
3
3
  # return rotated val in passed array
4
- def get_rotated_val array, cnt
4
+ def get_rotated_val array, size, cnt
5
5
  raise NothingDataError.new("Nothing seed data") if array.nil?
6
- size = array.size
7
6
  raise NothingDataError.new("Seed data is empty") if size.zero?
8
7
  x = (size + cnt) / size
9
8
  array[ size + cnt - size * x ]
@@ -7,8 +7,8 @@ class Option
7
7
  option.nil? ? { select: [], add: [] } : separate(option)
8
8
  end
9
9
 
10
- def apply arr, option_conf, cnt = 0
11
- selected_val = select(option_conf[:select], arr, cnt)
10
+ def apply arr, size, option_conf, cnt = 0
11
+ selected_val = select(option_conf[:select], arr, size, cnt)
12
12
  add(option_conf[:add], selected_val, cnt)
13
13
  end
14
14
 
@@ -26,10 +26,10 @@ class Option
26
26
  }
27
27
  end
28
28
 
29
- def select option, arr, cnt
29
+ def select option, arr, size, cnt
30
30
  return arr.sample if option == "random"
31
31
  # default return rotate
32
- get_rotated_val(arr, cnt)
32
+ get_rotated_val(arr, size, cnt)
33
33
  end
34
34
 
35
35
  def add option, val, cnt
@@ -36,7 +36,6 @@ class QueryBuilder
36
36
  col_str.chop << ")"
37
37
  end
38
38
 
39
-
40
39
  def add_double_quote str
41
40
  "\"" << str << "\""
42
41
  end
@@ -1,3 +1,3 @@
1
1
  module Pokotarou
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kashiwara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-21 00:00:00.000000000 Z
11
+ date: 2019-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.00'
41
- description: 'Pokotarou is fast seeder of ''Ruby on Rails'' URL: https://github.com/Tamatebako0205/Pokotarou'
41
+ description: 'Pokotarou is convenient seeder of ''Ruby on Rails'' URL: https://github.com/Tamatebako0205/Pokotarou'
42
42
  email:
43
43
  - tamatebako0205@gmail.com
44
44
  executables: []
@@ -50,6 +50,7 @@ files:
50
50
  - Rakefile
51
51
  - lib/pokotarou.rb
52
52
  - lib/pokotarou/additional_methods.rb
53
+ - lib/pokotarou/converter.rb
53
54
  - lib/pokotarou/data_register.rb
54
55
  - lib/pokotarou/data_structure.rb
55
56
  - lib/pokotarou/expression_parser.rb