evil-seed 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +0 -7
- data/evil-seed.gemspec +1 -1
- data/lib/evil_seed/anonymizer.rb +2 -2
- data/lib/evil_seed/record_dumper.rb +3 -22
- data/lib/evil_seed/relation_dumper.rb +3 -3
- data/lib/evil_seed/version.rb +1 -1
- metadata +4 -5
- data/gemfiles/activerecord_4_2.gemfile +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49f3bab8298bfc4a918791ff92abb7d60d63f7a8d14bbb37b353bfa59fe33818
|
4
|
+
data.tar.gz: f11da93930102998a035b1ea83e1bc3c382ad829d43490a6ef7263af27d8e7c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f446f6c8634d9385d75f8ccdf7e2a76cdfea9b17886759ca63993a70044bc15e77f111442e9d323c4c158907c7751ee927c778b3c58e43c06f81bef737e26ff6
|
7
|
+
data.tar.gz: 604448e710c92999cffe29a6e137a4cee328f3f8bec5b2c44fa5c3ee3fb9b1393c87b104c2826e8792f4724cec34bfd576bd55e588dfc8bdd50eb63c991e0a56
|
data/Appraisals
CHANGED
data/evil-seed.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
|
28
28
|
spec.required_ruby_version = '>= 2.0'
|
29
29
|
|
30
|
-
spec.add_dependency 'activerecord', '>=
|
30
|
+
spec.add_dependency 'activerecord', '>= 5.0'
|
31
31
|
|
32
32
|
spec.add_development_dependency 'rake', '~> 12.0'
|
33
33
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
data/lib/evil_seed/anonymizer.rb
CHANGED
@@ -33,13 +33,13 @@ module EvilSeed
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def respond_to_missing?(attribute_name)
|
36
|
-
@model_class.
|
36
|
+
@model_class.column_names.include?(attribute_name.to_s) || super
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
41
|
def method_missing(attribute_name, &block)
|
42
|
-
return super unless @model_class.
|
42
|
+
return super unless @model_class.column_names.include?(attribute_name.to_s)
|
43
43
|
@changers[attribute_name.to_s] = block
|
44
44
|
end
|
45
45
|
end
|
@@ -53,7 +53,7 @@ module EvilSeed
|
|
53
53
|
def insert_statement
|
54
54
|
connection = model_class.connection
|
55
55
|
table_name = connection.quote_table_name(model_class.table_name)
|
56
|
-
columns = model_class.
|
56
|
+
columns = model_class.column_names.map { |c| connection.quote_column_name(c) }.join(', ')
|
57
57
|
"INSERT INTO #{table_name} (#{columns}) VALUES\n"
|
58
58
|
end
|
59
59
|
|
@@ -73,27 +73,8 @@ module EvilSeed
|
|
73
73
|
|
74
74
|
def prepare(attributes)
|
75
75
|
attributes.map do |key, value|
|
76
|
-
model_class.
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
# Handles ActiveRecord API differences between AR 4.2 and 5.0
|
81
|
-
def attribute_types
|
82
|
-
return @attribute_types if defined?(@attribute_types)
|
83
|
-
@attribute_types = if model_class.respond_to?(:attribute_types)
|
84
|
-
model_class.attribute_types
|
85
|
-
else
|
86
|
-
model_class.column_types
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Handles ActiveRecord API differences between AR 4.2 and 5.0
|
91
|
-
# Casts a value from the ruby type to a type that the database knows how to understand.
|
92
|
-
def serialize(type, value)
|
93
|
-
if type.respond_to?(:serialize)
|
94
|
-
type.serialize(value)
|
95
|
-
else
|
96
|
-
type.type_cast_for_database(value)
|
76
|
+
type = model_class.attribute_types[key]
|
77
|
+
model_class.connection.quote(type.serialize(value))
|
97
78
|
end
|
98
79
|
end
|
99
80
|
end
|
@@ -124,8 +124,8 @@ module EvilSeed
|
|
124
124
|
# @param relation [ActiveRecord::Relation]
|
125
125
|
# @return [Array<Hash{String => String, Integer, Float, Boolean, nil}>]
|
126
126
|
def fetch_attributes(relation)
|
127
|
-
relation.pluck(*model_class.
|
128
|
-
Hash[model_class.
|
127
|
+
relation.pluck(*model_class.column_names).map do |row|
|
128
|
+
Hash[model_class.column_names.zip(row)]
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -146,7 +146,7 @@ module EvilSeed
|
|
146
146
|
next false if reflection.options[:polymorphic] # TODO: Add support for polymorphic belongs_to
|
147
147
|
excluded = root.excluded?("#{association_path}.#{reflection.name}") || reflection.name == inverse_reflection
|
148
148
|
if excluded
|
149
|
-
nullify_columns << reflection.foreign_key if model_class.
|
149
|
+
nullify_columns << reflection.foreign_key if model_class.column_names.include?(reflection.foreign_key)
|
150
150
|
else
|
151
151
|
foreign_keys[reflection.name] = reflection.foreign_key
|
152
152
|
table_names[reflection.name] = reflection.table_name
|
data/lib/evil_seed/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evil-seed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Novikov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '5.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '5.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -172,7 +172,6 @@ files:
|
|
172
172
|
- bin/setup
|
173
173
|
- evil-seed.gemspec
|
174
174
|
- gemfiles/.bundle/config
|
175
|
-
- gemfiles/activerecord_4_2.gemfile
|
176
175
|
- gemfiles/activerecord_5_0.gemfile
|
177
176
|
- gemfiles/activerecord_5_1.gemfile
|
178
177
|
- gemfiles/activerecord_5_2.gemfile
|