pokotarou 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +59 -6
- data/lib/pokotarou.rb +14 -8
- data/lib/pokotarou/data_structure.rb +11 -8
- data/lib/pokotarou/pokotarou_handler.rb +17 -0
- data/lib/pokotarou/seeder.rb +1 -2
- data/lib/pokotarou/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2405129bdaf545e80c102a188d1feca1c39462c0ef4f8a59df4f66eef228c8f4
|
4
|
+
data.tar.gz: 75d205d49492a61ec5d621e23043ec31fbfd397ec08f2b2775b0f64746cb4d81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dedda38c93623417cd069c56caa32e335c28e3c05c809533a3adb2cd4904f3ef5d86cd2d309587188693120bce3e523cc766fa70dd80ce1d155f585cd7058de0
|
7
|
+
data.tar.gz: b4c8c1a7f6a1587b5357b3d6c1ced595406c42516acf4db3c3db9657dad7d26f31c7897f586c3517320875a464c09dd88e7537f74d363cc2146d05ad2f95a345
|
data/README.md
CHANGED
@@ -331,12 +331,65 @@ Default:
|
|
331
331
|
optimaize: true
|
332
332
|
```
|
333
333
|
|
334
|
-
####
|
334
|
+
#### Pokotarou Handler
|
335
335
|
|
336
|
-
|
336
|
+
if you use Pokotarou handler, can update pokotarou's parameter
|
337
337
|
|
338
|
+
In the following example, the number of loops is changed
|
339
|
+
|
340
|
+
```
|
341
|
+
handler = Pokotarou.gen_handler("ConfigrationFilePath")
|
342
|
+
# change loop number
|
343
|
+
handler.change_loop(:Default, :Pref, 6)
|
344
|
+
Pokotarou.execute(handler.get_data)
|
345
|
+
```
|
346
|
+
|
347
|
+
In the following example, delete class in parameter
|
348
|
+
|
349
|
+
```
|
350
|
+
handler = Pokotarou.gen_handler("ConfigrationFilePath")
|
351
|
+
# delete class in parameter
|
352
|
+
handler.delete(:Default, :Member)
|
353
|
+
Pokotarou.execute(handler.get_data)
|
354
|
+
```
|
355
|
+
|
356
|
+
#### Convert seed data
|
357
|
+
|
358
|
+
You can convert seed data
|
359
|
+
|
360
|
+
```
|
361
|
+
Default:
|
362
|
+
Pref:
|
363
|
+
loop: 3
|
364
|
+
col:
|
365
|
+
name: ["Hokkaido", "Aomori", "Iwate"]
|
366
|
+
convert:
|
367
|
+
name: ["nil(0..2)"]
|
338
368
|
```
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
```
|
369
|
+
|
370
|
+
```
|
371
|
+
[nil, nil, nil]
|
372
|
+
```
|
373
|
+
|
374
|
+
complex version
|
375
|
+
|
376
|
+
```
|
377
|
+
Default:
|
378
|
+
Pref:
|
379
|
+
loop: 3
|
380
|
+
col:
|
381
|
+
name: ["北海道", "青森県", "岩手県"]
|
382
|
+
convert:
|
383
|
+
name: ["empty(0..0)", "nil(1..2)"]
|
384
|
+
```
|
385
|
+
|
386
|
+
```
|
387
|
+
["", nil, nil]
|
388
|
+
```
|
389
|
+
|
390
|
+
|convert |description |
|
391
|
+
|:---------|------------------------------------------|
|
392
|
+
| empty | convert val to empty |
|
393
|
+
| nil | convert val to nil |
|
394
|
+
| big_text | convert val to big_text("text" * 50) |
|
395
|
+
| br_text | convert val to br_text("text\n" * 5) |
|
data/lib/pokotarou.rb
CHANGED
@@ -7,8 +7,13 @@ module Pokotarou
|
|
7
7
|
class NotFoundLoader < StandardError; end
|
8
8
|
|
9
9
|
class << self
|
10
|
-
def execute
|
11
|
-
|
10
|
+
def execute input
|
11
|
+
# if input is filepath, generate config_data
|
12
|
+
if input.kind_of?(String)
|
13
|
+
DataRegister.regist(gen_config(input))
|
14
|
+
else
|
15
|
+
DataRegister.regist(input)
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
def import filepath
|
@@ -19,16 +24,17 @@ module Pokotarou
|
|
19
24
|
AdditionalMethods.remove()
|
20
25
|
end
|
21
26
|
|
22
|
-
def
|
23
|
-
|
24
|
-
DataStructure.gen(contents)
|
27
|
+
def gen_handler filepath
|
28
|
+
PokotarouHandler.new(gen_config(filepath))
|
25
29
|
end
|
26
30
|
|
27
|
-
|
28
|
-
|
31
|
+
private
|
32
|
+
|
33
|
+
def gen_config filepath
|
34
|
+
contents = load_file(filepath)
|
35
|
+
DataStructure.gen(contents)
|
29
36
|
end
|
30
37
|
|
31
|
-
private
|
32
38
|
|
33
39
|
def load_file filepath
|
34
40
|
case File.extname(filepath)
|
@@ -27,11 +27,11 @@ class DataStructure
|
|
27
27
|
def set_col_type config_data, str_model
|
28
28
|
model = eval(str_model)
|
29
29
|
foreign_key_data = get_foreign_key_data(model)
|
30
|
-
|
31
|
-
config_data[:col] ||= Hash.new
|
30
|
+
|
31
|
+
config_data[:col] ||= Hash.new
|
32
32
|
model.columns.each do |e|
|
33
33
|
symbol_col_name = e.name.to_sym
|
34
|
-
|
34
|
+
|
35
35
|
unless exists_seed_data?(config_data, symbol_col_name)
|
36
36
|
# prepare setting to run default seed
|
37
37
|
# set nil to seed data
|
@@ -44,7 +44,7 @@ class DataStructure
|
|
44
44
|
# set enum info
|
45
45
|
config_data[:enum] ||= Hash.new
|
46
46
|
if is_enum?(e.sql_type.to_s)
|
47
|
-
config_data[:enum][symbol_col_name] =
|
47
|
+
config_data[:enum][symbol_col_name] =
|
48
48
|
e.sql_type.to_s[5..-2].tr("'", "").split(",")
|
49
49
|
end
|
50
50
|
|
@@ -54,7 +54,7 @@ class DataStructure
|
|
54
54
|
config_data[:foreign_key][symbol_col_name] = foreign_key_data[symbol_col_name]
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -62,7 +62,10 @@ class DataStructure
|
|
62
62
|
associations = model.reflect_on_all_associations(:belongs_to)
|
63
63
|
return { } if associations.empty?
|
64
64
|
associations.reduce(Hash.new)do |acc, r|
|
65
|
-
|
65
|
+
model = r.name.to_s.camelize
|
66
|
+
if Object.const_defined?(model.to_sym)
|
67
|
+
acc[r.foreign_key.to_sym] = eval(model)
|
68
|
+
end
|
66
69
|
|
67
70
|
acc
|
68
71
|
end
|
@@ -75,11 +78,11 @@ class DataStructure
|
|
75
78
|
def exists_seed_data? config_data ,symbol_col_name
|
76
79
|
config_data[:col].has_key?(symbol_col_name)
|
77
80
|
end
|
78
|
-
|
81
|
+
|
79
82
|
ENUM = /^enum(\s*.)*$/
|
80
83
|
def is_enum? val
|
81
84
|
return false unless val.kind_of?(String)
|
82
|
-
ENUM =~ val
|
85
|
+
ENUM =~ val
|
83
86
|
end
|
84
87
|
end
|
85
88
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class PokotarouHandler
|
2
|
+
def initialize data
|
3
|
+
@data = data
|
4
|
+
end
|
5
|
+
|
6
|
+
def delete_model sym_block, sym_class
|
7
|
+
@data[sym_block].delete(sym_class)
|
8
|
+
end
|
9
|
+
|
10
|
+
def change_loop sym_block, sym_class, n
|
11
|
+
@data[sym_block][sym_class][:loop] = n
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_data
|
15
|
+
@data
|
16
|
+
end
|
17
|
+
end
|
data/lib/pokotarou/seeder.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
class Seeder
|
2
2
|
class << self
|
3
|
-
MAX_LOOP = 100
|
4
3
|
def gen config_data, key
|
5
|
-
n = config_data[:loop]
|
4
|
+
n = config_data[:loop]
|
6
5
|
type = config_data[:type][key]
|
7
6
|
enum = config_data[:enum][key]
|
8
7
|
foreign_key = config_data[:foreign_key][key]
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kashiwara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/pokotarou/loader.rb
|
58
58
|
- lib/pokotarou/my_mthods.rb
|
59
59
|
- lib/pokotarou/option.rb
|
60
|
+
- lib/pokotarou/pokotarou_handler.rb
|
60
61
|
- lib/pokotarou/query_builder.rb
|
61
62
|
- lib/pokotarou/seeder.rb
|
62
63
|
- lib/pokotarou/version.rb
|