sql_enum 0.1.10 → 0.1.11
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/lib/active_record/fixtures_override.rb +79 -0
- data/lib/sql_enum/version.rb +1 -1
- data/lib/sql_enum.rb +1 -0
- metadata +3 -3
- data/lib/array.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0391b2647bafa76738ca6e50034303599631547
|
4
|
+
data.tar.gz: 9486b8ef30b7f6c6d10e0519ed5ee5bc0a363e3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e7191b04a08c7baa32dbf5810549548375a16fa9bb0bd3a0aeba4ddff5a1c14e21e407420112eea5d800c98b8a04e232a098b97bf770c891580feb6846be43d
|
7
|
+
data.tar.gz: aadfd52951701ac331b88d24c6a9acae220cb19916a3670c5db9cdf336013c1e2979098d39f58fe42c08966cc016eee690f82f5532cbddca731a0e6b1295b04b
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'active_record/fixtures'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class FixtureSet
|
5
|
+
def table_rows
|
6
|
+
now = config.default_timezone == :utc ? Time.now.utc : Time.now
|
7
|
+
|
8
|
+
# allow a standard key to be used for doing defaults in YAML
|
9
|
+
fixtures.delete('DEFAULTS')
|
10
|
+
|
11
|
+
# track any join tables we need to insert later
|
12
|
+
rows = Hash.new { |h,table| h[table] = [] }
|
13
|
+
|
14
|
+
rows[table_name] = fixtures.map do |label, fixture|
|
15
|
+
row = fixture.to_hash
|
16
|
+
|
17
|
+
if model_class
|
18
|
+
# fill in timestamp columns if they aren't specified and the model is set to record_timestamps
|
19
|
+
if model_class.record_timestamps
|
20
|
+
timestamp_column_names.each do |c_name|
|
21
|
+
row[c_name] = now unless row.key?(c_name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# interpolate the fixture label
|
26
|
+
row.each do |key, value|
|
27
|
+
row[key] = value.gsub("$LABEL", label.to_s) if value.is_a?(String)
|
28
|
+
end
|
29
|
+
|
30
|
+
# generate a primary key if necessary
|
31
|
+
if has_primary_key_column? && !row.include?(primary_key_name)
|
32
|
+
row[primary_key_name] = ActiveRecord::FixtureSet.identify(label, primary_key_type)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Resolve enums
|
36
|
+
# model_class.defined_enums.each do |name, values|
|
37
|
+
# if row.include?(name)
|
38
|
+
# row[name] = values.fetch(row[name], row[name])
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
# If STI is used, find the correct subclass for association reflection
|
43
|
+
reflection_class =
|
44
|
+
if row.include?(inheritance_column_name)
|
45
|
+
row[inheritance_column_name].constantize rescue model_class
|
46
|
+
else
|
47
|
+
model_class
|
48
|
+
end
|
49
|
+
|
50
|
+
reflection_class._reflections.each_value do |association|
|
51
|
+
case association.macro
|
52
|
+
when :belongs_to
|
53
|
+
# Do not replace association name with association foreign key if they are named the same
|
54
|
+
fk_name = (association.options[:foreign_key] || "#{association.name}_id").to_s
|
55
|
+
|
56
|
+
if association.name.to_s != fk_name && value = row.delete(association.name.to_s)
|
57
|
+
if association.polymorphic? && value.sub!(/\s*\(([^\)]*)\)\s*$/, "")
|
58
|
+
# support polymorphic belongs_to as "label (Type)"
|
59
|
+
row[association.foreign_type] = $1
|
60
|
+
end
|
61
|
+
|
62
|
+
fk_type = reflection_class.type_for_attribute(fk_name).type
|
63
|
+
row[fk_name] = ActiveRecord::FixtureSet.identify(value, fk_type)
|
64
|
+
end
|
65
|
+
when :has_many
|
66
|
+
if association.options[:through]
|
67
|
+
add_join_records(rows, row, HasManyThroughProxy.new(association))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
row
|
74
|
+
end
|
75
|
+
rows
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
data/lib/sql_enum/version.rb
CHANGED
data/lib/sql_enum.rb
CHANGED
@@ -23,6 +23,7 @@ end
|
|
23
23
|
require_relative 'active_record/enum/enum_type'
|
24
24
|
require_relative 'active_record/type/enum'
|
25
25
|
require_relative 'active_record/enum_override'
|
26
|
+
require_relative 'active_record/fixtures_override'
|
26
27
|
require_relative 'active_record/connection_adapters/mysql2'
|
27
28
|
require_relative 'active_record/connection_adapters/abstract_mysql'
|
28
29
|
require_relative 'active_record/connection_adapters/mysql/column_methods'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fletcher Fowler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -89,8 +89,8 @@ files:
|
|
89
89
|
- lib/active_record/connection_adapters/mysql2.rb
|
90
90
|
- lib/active_record/enum/enum_type.rb
|
91
91
|
- lib/active_record/enum_override.rb
|
92
|
+
- lib/active_record/fixtures_override.rb
|
92
93
|
- lib/active_record/type/enum.rb
|
93
|
-
- lib/array.rb
|
94
94
|
- lib/sql_enum.rb
|
95
95
|
- lib/sql_enum/version.rb
|
96
96
|
- sql_enum.gemspec
|