dynamic-active-model 0.15.0 → 0.16.0
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e8e20f58fe5d7cae0b4c699388d39ba803f2a4bcf69f46cf4e38ce1ca0df8fd
|
|
4
|
+
data.tar.gz: 0c6a79166d4d62c99d61450883296aee87531f9d2e854bc71cf08587e130c881
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 63cac3e28e12282b2dce7821ed2436ae1092df5622f8ba401ba709f4161d500837ae75a62ef2d76eff65dd56d4d57a2b95b282a05de59e7bab63e4be83deb5cf
|
|
7
|
+
data.tar.gz: 978019763203fa5d993c2efff7f1102862707db324649649edbc8aa2a7556e8aa8a7befb3ed2fefebf86f4babcf4db54b852df5a8fa8cb13f9e7c092e0a84cff
|
|
@@ -36,7 +36,8 @@ module DynamicActiveModel
|
|
|
36
36
|
@foreign_keys = {}
|
|
37
37
|
database.models.each do |model|
|
|
38
38
|
@foreign_keys[model.table_name] = ForeignKey.new(model)
|
|
39
|
-
|
|
39
|
+
# through the schema cache, so a Rails schema cache dump spares one query per table
|
|
40
|
+
@table_indexes[model.table_name] = model.connection.schema_cache.indexes(model.table_name)
|
|
40
41
|
@join_tables << model if join_table?(model)
|
|
41
42
|
end
|
|
42
43
|
end
|
|
@@ -62,19 +62,12 @@ module DynamicActiveModel
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
# Sets or gets the database connection options
|
|
65
|
-
# @param options [Hash, String, nil]
|
|
66
|
-
#
|
|
65
|
+
# @param options [Hash, Symbol, String, nil] Anything establish_connection accepts:
|
|
66
|
+
# a config hash, or a Symbol naming a database.yml entry for the current
|
|
67
|
+
# environment. A String database.yml name is deprecated.
|
|
68
|
+
# @return [Hash, Symbol] The current connection options
|
|
67
69
|
def connection_options(options = nil)
|
|
68
|
-
if options.is_a?(String)
|
|
69
|
-
name = options
|
|
70
|
-
options = ActiveRecord::Base
|
|
71
|
-
.configurations
|
|
72
|
-
.configs_for(
|
|
73
|
-
env_name: ::Rails.env,
|
|
74
|
-
name: name
|
|
75
|
-
)
|
|
76
|
-
.configuration_hash
|
|
77
|
-
end
|
|
70
|
+
options = deprecated_named_configuration(options) if options.is_a?(String)
|
|
78
71
|
|
|
79
72
|
update_config(:connection_options, options) if options
|
|
80
73
|
|
|
@@ -180,6 +173,19 @@ module DynamicActiveModel
|
|
|
180
173
|
|
|
181
174
|
private
|
|
182
175
|
|
|
176
|
+
# Resolves a database.yml name given as a String, warning that it's deprecated
|
|
177
|
+
# @param name [String]
|
|
178
|
+
# @return [Hash] The named configuration for the current Rails environment
|
|
179
|
+
def deprecated_named_configuration(name)
|
|
180
|
+
DynamicActiveModel.deprecator.warn(
|
|
181
|
+
"connection_options with a database.yml name as a String (#{name.inspect}) is deprecated; " \
|
|
182
|
+
"pass a Symbol instead (connection_options #{name.to_sym.inspect}), " \
|
|
183
|
+
'or use dynamic-active-model-rails in a Rails app',
|
|
184
|
+
caller_locations(2) # point at the caller of connection_options
|
|
185
|
+
)
|
|
186
|
+
ActiveRecord::Base.configurations.configs_for(env_name: ::Rails.env, name: name).configuration_hash
|
|
187
|
+
end
|
|
188
|
+
|
|
183
189
|
# Stores a single configuration value
|
|
184
190
|
# @param key [Symbol] Configuration key
|
|
185
191
|
# @param value [Object] Configuration value
|
data/lib/dynamic-active-model.rb
CHANGED
|
@@ -46,6 +46,16 @@ module DynamicActiveModel
|
|
|
46
46
|
# Manages the setup process and configuration
|
|
47
47
|
autoload :Setup, 'dynamic-active-model/setup'
|
|
48
48
|
|
|
49
|
+
# Deprecation warnings for this gem; dynamic-active-model-rails registers it in
|
|
50
|
+
# Rails.application.deprecators so the app's deprecation settings apply
|
|
51
|
+
# @return [ActiveSupport::Deprecation]
|
|
52
|
+
def self.deprecator
|
|
53
|
+
@deprecator ||= begin
|
|
54
|
+
require 'active_support/deprecation'
|
|
55
|
+
ActiveSupport::Deprecation.new('1.0', 'dynamic-active-model')
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
49
59
|
# Base class for errors raised by DynamicActiveModel
|
|
50
60
|
class Error < StandardError; end
|
|
51
61
|
|