pokotarou 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +2 -2
- data/lib/pokotarou/converter.rb +23 -0
- data/lib/pokotarou/data_register.rb +22 -10
- data/lib/pokotarou/my_mthods.rb +1 -2
- data/lib/pokotarou/option.rb +4 -4
- data/lib/pokotarou/query_builder.rb +0 -1
- data/lib/pokotarou/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 62fc987dc55f5258ed2d6a3a8efa366b245795bd380b4178bc769d500ec46338
|
|
4
|
+
data.tar.gz: 265f6f6918e1b92b0852971c7b925ba77b883f83065ecd2152204e06505b639e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10ede458b68376974383c29abcb0932c50c721b1115b5818ebc7aadd5cbf4fb6faa45c54037bf6d6c87ea128d9f89f1e1e2fedbeeb7fb31377a9cb1cc1638bab
|
|
7
|
+
data.tar.gz: ff000b11427a3b70d9a5ffc3066245b763115af51c2e8a736c0c8a4f7f9d56384355289cb74e24bb1642163577ba61dc21cf2a3dbcc52dc96888c3f40a95db67
|
data/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
1
|
+

|
|
2
|
+
[](https://badge.fury.io/rb/pokotarou)
|
|
3
3
|
[](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 =
|
|
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
|
-
#
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
data/lib/pokotarou/my_mthods.rb
CHANGED
|
@@ -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 ]
|
data/lib/pokotarou/option.rb
CHANGED
|
@@ -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
|
data/lib/pokotarou/version.rb
CHANGED
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.
|
|
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-
|
|
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
|
|
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
|