snapbot 0.1.1 → 0.2.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: bb7768e6e3ac46cacf84d569a0d8026062418160d39c5ae1e214875ac0f4b26d
|
4
|
+
data.tar.gz: 50467bc231c453c7c81129181f90c21759f5acb2f121fbaf07bfd5313dcaea80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0331b6031f3fe4e3ee09aef66a1030bfec968f5df8c7308c2dd09933e0c63cfad55e54dab10e7bf0e9dc568216d34bbd3f8ac32c5bd6e524750ad676fbb49988
|
7
|
+
data.tar.gz: 06757de1f42e455f6b8565661426bba4a94e609d567a5d2a2c6d8cdb8be8e5aed4b16e97334a009d34bda3b400707b2796a9a4b88b507a407b58e1ca8df2a798
|
data/.rubocop.yml
CHANGED
@@ -2,11 +2,19 @@ AllCops:
|
|
2
2
|
TargetRubyVersion: 2.6
|
3
3
|
SuggestExtensions: false
|
4
4
|
|
5
|
+
Metrics/AbcSize:
|
6
|
+
Exclude:
|
7
|
+
- spec/support/fixture_database.rb
|
8
|
+
|
5
9
|
Metrics/BlockLength:
|
6
10
|
Exclude:
|
7
11
|
- spec/**/*_spec.rb
|
8
12
|
- snapbot.gemspec
|
9
13
|
|
14
|
+
Metrics/MethodLength:
|
15
|
+
Exclude:
|
16
|
+
- spec/support/fixture_database.rb
|
17
|
+
|
10
18
|
Style/StderrPuts:
|
11
19
|
Exclude:
|
12
20
|
- lib/snapbot/diagram/renderer.rb
|
@@ -40,7 +40,7 @@ module Snapbot
|
|
40
40
|
def collect_lets(example)
|
41
41
|
@lets_by_value = RSpec::Lets.new(example).collect.each_with_object({}) do |sym, lets_by_value|
|
42
42
|
value = example.send(sym) unless @ignore_lets.include?(sym)
|
43
|
-
lets_by_value[value] = sym if value.is_a?(
|
43
|
+
lets_by_value[value] = sym if value.is_a?(reflector.base_activerecord_class)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
data/lib/snapbot/reflector.rb
CHANGED
@@ -5,17 +5,29 @@ require "active_record"
|
|
5
5
|
module Snapbot
|
6
6
|
# Reflect models and instances in a way that's useful for generating a diagram
|
7
7
|
class Reflector
|
8
|
-
|
8
|
+
def base_activerecord_class
|
9
|
+
defined?(ApplicationRecord) ? ApplicationRecord : ActiveRecord::Base
|
10
|
+
end
|
9
11
|
|
10
12
|
def models(only_with_records: true)
|
11
13
|
@models ||= begin
|
12
14
|
Rails.application.eager_load! if defined?(Rails)
|
13
|
-
|
14
|
-
c
|
15
|
+
base_activerecord_class.descendants.reject do |c|
|
16
|
+
activerecord_ignore?(c) || (only_with_records && c.count.zero?)
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
21
|
+
ACTIVERECORD_IGNORE = [
|
22
|
+
/^Schema$/,
|
23
|
+
/^HABTM_/,
|
24
|
+
/^ActiveRecord::InternalMetadata$/,
|
25
|
+
/^ActiveRecord::SchemaMigration$/
|
26
|
+
].freeze
|
27
|
+
def activerecord_ignore?(klass)
|
28
|
+
ACTIVERECORD_IGNORE.any? { |r| klass.name =~ r }
|
29
|
+
end
|
30
|
+
|
19
31
|
def instances
|
20
32
|
@instances ||= models.each_with_object([]) do |klass, array|
|
21
33
|
array << klass.all
|
@@ -41,7 +53,8 @@ module Snapbot
|
|
41
53
|
def reflect_associations(instance)
|
42
54
|
(
|
43
55
|
instance.class.reflect_on_all_associations(:has_many).reject { |a| a.name == :schemas } +
|
44
|
-
instance.class.reflect_on_all_associations(:has_one)
|
56
|
+
instance.class.reflect_on_all_associations(:has_one) +
|
57
|
+
instance.class.reflect_on_all_associations(:has_and_belongs_to_many)
|
45
58
|
).flatten
|
46
59
|
end
|
47
60
|
|
data/lib/snapbot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snapbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Garner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: binding_of_caller
|