pokotarou 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -4
- data/lib/pokotarou/data_register.rb +1 -15
- data/lib/pokotarou/expression_parser.rb +1 -2
- data/lib/pokotarou/{loader.rb → file_loader.rb} +0 -0
- data/lib/pokotarou/seeder.rb +1 -1
- data/lib/pokotarou/version.rb +1 -1
- metadata +4 -5
- data/lib/pokotarou/query_builder.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e745ff3535e86963bfd04eb386677ce231ff8de9464eb8661429d8f96debedf9
|
4
|
+
data.tar.gz: ec1da372cf523be34c7f82b51d8218d662da33a4bae792cd0e68aed335944a98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e302fa4f5684a222ad33be467776dc5b6d005d6ee1a6d726bd3b5bd26e828e856f1cc1c696476f6c58dfa34a70fd16e7c66d0cd0b023150bba8d11fa456c1d7
|
7
|
+
data.tar.gz: 4f194deab82400ddbfb817245b4d4051c060ef847aa2ff6f5dda5b3d5eb5d4699ad29c3e76cdb3e20596d437271444a5d26884cc785bdc0fcfbb55273ee362c0
|
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
![s_PokotarouLogo](https://user-images.githubusercontent.com/52961642/
|
1
|
+
![s_PokotarouLogo](https://user-images.githubusercontent.com/52961642/62843884-46f6c700-bcf8-11e9-8267-b9fad8f34085.png)
|
2
|
+
|
3
|
+
|
2
4
|
[![Gem Version](https://badge.fury.io/rb/pokotarou.svg)](https://badge.fury.io/rb/pokotarou)
|
3
|
-
[![Build Status](https://travis-ci.org/
|
5
|
+
[![Build Status](https://travis-ci.org/Kashiwara0205/Pokotarou.svg?branch=master)](https://travis-ci.org/Kashiwara0205/Pokotarou)
|
4
6
|
|
5
7
|
Pokotarou is convenient seeder of 'Ruby on Rails'
|
6
|
-
|
8
|
+
In MySql, operation has been confirmed
|
7
9
|
|
8
10
|
## Features
|
9
11
|
|
@@ -375,6 +377,7 @@ In the following example, seed data is changed
|
|
375
377
|
```
|
376
378
|
|
377
379
|
<b>Delete Operation</b>
|
380
|
+
|
378
381
|
In the following example, delete block config
|
379
382
|
|
380
383
|
```ruby
|
@@ -443,4 +446,4 @@ Default:
|
|
443
446
|
|
444
447
|
```ruby
|
445
448
|
["", nil, nil]
|
446
|
-
```
|
449
|
+
```
|
@@ -21,18 +21,6 @@ class DataRegister
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
def execute model, config_data, table_name, col_arr, seed_arr
|
25
|
-
# optimize is more faster than activerecord-import
|
26
|
-
# however, sql.conf setting is necessary to use
|
27
|
-
if config_data[:optimize]
|
28
|
-
# seed_arr.transpose: [[col1_element, col2_element], [col1_element, col2_element]...]
|
29
|
-
insert_query = QueryBuilder.insert(table_name, col_arr, seed_arr.transpose)
|
30
|
-
ActiveRecord::Base.connection.execute(insert_query)
|
31
|
-
else
|
32
|
-
model.import(col_arr, seed_arr.transpose, validate: config_data[:validate], timestamps: false)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
24
|
def regist_models sym_block, model_data, maked, model_cache
|
37
25
|
model_data.each do |e|
|
38
26
|
str_model = e.first.to_s
|
@@ -53,9 +41,7 @@ class DataRegister
|
|
53
41
|
|
54
42
|
output_log(config_data[:log])
|
55
43
|
begin
|
56
|
-
|
57
|
-
execute(model_cache[str_model][:model],
|
58
|
-
config_data, model_cache[str_model][:table_name], col_arr, seed_arr)
|
44
|
+
model_cache[str_model][:model].import(col_arr, seed_arr.transpose, validate: config_data[:validate], timestamps: false)
|
59
45
|
rescue => e
|
60
46
|
raise RegistError.new("
|
61
47
|
block: #{sym_block}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "pokotarou/additional_methods.rb"
|
2
2
|
class ParseError < StandardError; end
|
3
|
+
FOREIGN_KEY_SYMBOL = "F|"
|
3
4
|
|
4
5
|
# for seed data
|
5
6
|
class ExpressionParser
|
6
7
|
class << self
|
7
|
-
FOREIGN_KEY_SYMBOL = "F|"
|
8
8
|
def parse config_val, maked
|
9
9
|
begin
|
10
10
|
require AdditionalMethods.filepath if AdditionalMethods.filepath.present?
|
@@ -38,7 +38,6 @@ end
|
|
38
38
|
# for loop data
|
39
39
|
class LoopExpressionParser
|
40
40
|
class << self
|
41
|
-
FOREIGN_KEY_SYMBOL = "F|"
|
42
41
|
def parse config_val, maked
|
43
42
|
begin
|
44
43
|
require AdditionalMethods.filepath if AdditionalMethods.filepath.present?
|
File without changes
|
data/lib/pokotarou/seeder.rb
CHANGED
@@ -13,7 +13,7 @@ class Seeder
|
|
13
13
|
return make_array(n, ->(){ rand(0.0..1_000_000_000.0) }) if type == "decimal"
|
14
14
|
return make_array(n, ->(){ SecureRandom.hex(20) }) if type == "string"
|
15
15
|
return make_array(n, ->(){ SecureRandom.hex(300) }) if ["text", "binary"].include?(type)
|
16
|
-
return make_array(n, ->(){ [
|
16
|
+
return make_array(n, ->(){ [true, false].sample }) if type == "boolean"
|
17
17
|
return make_string_array(n, enum) if type == "string"
|
18
18
|
return make_datetime_array() if ["string", "datetime", "date", "time"].include?(type)
|
19
19
|
end
|
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.5
|
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-
|
11
|
+
date: 2019-08-17 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:
|
41
|
+
description: Pokotarou is convenient seeder of 'Ruby on Rails'
|
42
42
|
email:
|
43
43
|
- tamatebako0205@gmail.com
|
44
44
|
executables: []
|
@@ -55,10 +55,9 @@ files:
|
|
55
55
|
- lib/pokotarou/data_register.rb
|
56
56
|
- lib/pokotarou/data_structure.rb
|
57
57
|
- lib/pokotarou/expression_parser.rb
|
58
|
-
- lib/pokotarou/
|
58
|
+
- lib/pokotarou/file_loader.rb
|
59
59
|
- lib/pokotarou/option.rb
|
60
60
|
- lib/pokotarou/pokotarou_handler.rb
|
61
|
-
- lib/pokotarou/query_builder.rb
|
62
61
|
- lib/pokotarou/seeder.rb
|
63
62
|
- lib/pokotarou/version.rb
|
64
63
|
- lib/tasks/pokotarou_tasks.rake
|
@@ -1,43 +0,0 @@
|
|
1
|
-
class QueryBuilder
|
2
|
-
class << self
|
3
|
-
|
4
|
-
# build insert query
|
5
|
-
def insert table_name, col_arr, seed_arr
|
6
|
-
col_str = convert_col_to_sql_str(col_arr)
|
7
|
-
seed_str = convert_seed_to_sql_str(seed_arr)
|
8
|
-
|
9
|
-
"INSERT INTO #{table_name} #{col_str} VALUES#{seed_str}"
|
10
|
-
end
|
11
|
-
|
12
|
-
def convert_to_sql_str arr
|
13
|
-
arr_str =
|
14
|
-
arr.reduce("(") do |acc, r|
|
15
|
-
acc << add_double_quote(r.to_s) << ","
|
16
|
-
end
|
17
|
-
# remove ' , ' and add ' ) '
|
18
|
-
arr_str.chop << ")"
|
19
|
-
end
|
20
|
-
|
21
|
-
def convert_seed_to_sql_str seed_arr
|
22
|
-
seed_str =
|
23
|
-
seed_arr.reduce("") do |acc, r|
|
24
|
-
acc << convert_to_sql_str(r) << ","
|
25
|
-
end
|
26
|
-
# remove ' , '
|
27
|
-
seed_str.chop
|
28
|
-
end
|
29
|
-
|
30
|
-
def convert_col_to_sql_str col_arr
|
31
|
-
col_str =
|
32
|
-
col_arr.reduce("(") do |acc, r|
|
33
|
-
acc << r.to_s << ","
|
34
|
-
end
|
35
|
-
# remove ' , ' and add ' ) '
|
36
|
-
col_str.chop << ")"
|
37
|
-
end
|
38
|
-
|
39
|
-
def add_double_quote str
|
40
|
-
"\"" << str << "\""
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|