dynamic-active-model 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dynamic-active-model/explorer.rb +1 -1
- data/lib/dynamic-active-model/factory.rb +13 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ff2c766e425b76a6fec1c64609a82046b2404f63d8fccdf0979961f254a70b7
|
4
|
+
data.tar.gz: cfadab872a7c3420e2f3ef76b7c2e368f69c429897af1403c126e95aa3840fa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c7220fd1e3113bafb6c84d10295bd27ad3b544e690575da9b4e146031c0bdc21a424ec116c02e5ab4cd07255b6046df76f33c97fce6cebeaba062a201324089
|
7
|
+
data.tar.gz: c8df523ff92c66f5394d1c498e4dc258382ee3af300e01fab0d5fbfb943f7d46b5d20456407953ffa08bd932a599c9695d32b20cce3799db2bcb9993eb33f7a9
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module DynamicActiveModel
|
4
|
-
# DynamicActiveModel::
|
4
|
+
# DynamicActiveModel::Explorer creates models and relationships
|
5
5
|
module Explorer
|
6
6
|
def self.explore(base_module, connection_options, skip_tables = [], relationships = {})
|
7
7
|
database = create_models!(base_module, connection_options, skip_tables)
|
@@ -13,6 +13,11 @@ module DynamicActiveModel
|
|
13
13
|
|
14
14
|
def create(table_name, class_name = nil)
|
15
15
|
class_name ||= generate_class_name(table_name)
|
16
|
+
create!(table_name, class_name) unless @base_module.const_defined?(class_name)
|
17
|
+
@base_module.const_get(class_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create!(table_name, class_name)
|
16
21
|
kls = Class.new(base_class) do
|
17
22
|
self.table_name = table_name
|
18
23
|
end
|
@@ -26,14 +31,16 @@ module DynamicActiveModel
|
|
26
31
|
begin
|
27
32
|
require 'active_record'
|
28
33
|
|
29
|
-
|
30
|
-
|
34
|
+
unless @base_module.const_defined?(@base_class_name)
|
35
|
+
new_base_class = Class.new(ActiveRecord::Base) do
|
36
|
+
self.abstract_class = true
|
37
|
+
end
|
38
|
+
@base_module.const_set(@base_class_name, new_base_class)
|
31
39
|
end
|
32
|
-
@base_module.const_set(@base_class_name, kls)
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
@base_module.const_get(@base_class_name).tap do |kls|
|
42
|
+
kls.establish_connection @connection_options
|
43
|
+
end
|
37
44
|
end
|
38
45
|
end
|
39
46
|
# rubocop:enable MethodLength
|