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: aa9a6b0cbc5334ac7078254f385f9c859c0ea22d7ca4821741bade0b4c32cca6
4
- data.tar.gz: 8e69a33b99977466a92b9772abaa2e2d889a0d7ff200ed81c5effb01581eb014
3
+ metadata.gz: bb7768e6e3ac46cacf84d569a0d8026062418160d39c5ae1e214875ac0f4b26d
4
+ data.tar.gz: 50467bc231c453c7c81129181f90c21759f5acb2f121fbaf07bfd5313dcaea80
5
5
  SHA512:
6
- metadata.gz: 1de519ae9f8e26a44d081682b83ca89d101daf00f5665c7d04a4ed1bb7c8ee701a72b476b45d9d5760ff2621e498d8bbe0ddfb3bde386fc4f188a16cee3c82db
7
- data.tar.gz: 6f549408fbffc23fc5f96f620dc0be49df614b84ce0e5c913fb375422bcec052f36e065a63080f03be3a2992c7f7a519873ab0efcb31bd9610e5b2f2bdf2340e
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
@@ -11,7 +11,7 @@ module Snapbot
11
11
  self.destination = destination
12
12
  end
13
13
 
14
- def equals(other)
14
+ def ==(other)
15
15
  source == other.source && destination == other.destination
16
16
  end
17
17
  end
@@ -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?(Reflector::BASE_ACTIVERECORD_CLASS)
43
+ lets_by_value[value] = sym if value.is_a?(reflector.base_activerecord_class)
44
44
  end
45
45
  end
46
46
 
@@ -16,6 +16,8 @@ module Snapbot
16
16
  def save
17
17
  ensure_graphviz
18
18
  FileUtils.rm(OUTPUT_FILENAME, force: true)
19
+ FileUtils.mkdir_p(File.dirname(OUTPUT_FILENAME))
20
+
19
21
  IO.popen("dot -Tsvg -o #{OUTPUT_FILENAME}", "w") do |pipe|
20
22
  pipe.puts(@dot)
21
23
  end
@@ -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
- BASE_ACTIVERECORD_CLASS = defined?(ApplicationRecord) ? ApplicationRecord : ActiveRecord::Base
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
- BASE_ACTIVERECORD_CLASS.descendants.reject do |c|
14
- c.to_s == "Schema" || (only_with_records && c.count.zero?)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snapbot
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.1
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-08 00:00:00.000000000 Z
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