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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db4f6bee0035811fcf98c56f740c9c87a6151f20b30ac1e72605232f480e4766
4
- data.tar.gz: 49e37d2abca94db6fa593fac3732767dcf2b12a37f05b3a5ff82be6c192c3dcf
3
+ metadata.gz: 9ff2c766e425b76a6fec1c64609a82046b2404f63d8fccdf0979961f254a70b7
4
+ data.tar.gz: cfadab872a7c3420e2f3ef76b7c2e368f69c429897af1403c126e95aa3840fa4
5
5
  SHA512:
6
- metadata.gz: 5f6f1486e57a7a869cd700c1bf235b9915173723063291ed6e28a19529f6c4a8f486936e19e764f2d10297e48bf3a9a3301bae7d11a4d1fdba3d29e952504697
7
- data.tar.gz: 7c49634233a7faf0a47f27abed7acaf6b01a0a77c8dd9b86c7147b1d4b23e57680123622d31eee575ce211f184b729a35c64f48e9ec4f55618ca614601cf819b
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::EWplorer creates models and relationships
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
- kls = Class.new(ActiveRecord::Base) do
30
- self.abstract_class = true
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
- kls = @base_module.const_get(@base_class_name)
35
- kls.establish_connection @connection_options
36
- kls
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic-active-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch