revocare 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +3 -2
- data/lib/revocare/callback_data.rb +14 -2
- data/lib/revocare/data_writer.rb +27 -7
- data/lib/revocare/version.rb +1 -1
- data/lib/revocare.rb +1 -0
- data/revocare.gemspec +1 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f929fa681bc6b0ada88fd4ff25836596e9994e1559b14bfc5c4f529a6beff99
|
4
|
+
data.tar.gz: ae32cfc85a2bdca4d5dd23eb21dbc4184cbdf2fe1e5c9ae459695c33cd3e99fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5678ed93ba7a0e5f691f0bf2d0cce4f7c68733a9d8ed13e569dce1b314ea70c5426da08fca50ddb3fc5d77e76d641e8ea8cdfe7cc2d07f350950c3f39e4cf72b
|
7
|
+
data.tar.gz: bc95dbf169d33c8de843ab0585a58630694cf2fa1d796041cd44c895dbe506e3cb76d6b1a1db4530122c6474dccf938e81ce2fce51ff871478e27b42fa1f2dda
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
# `revocare`
|
2
2
|
|
3
|
+
## [0.1.1]
|
4
|
+
- Make each callback name and chain node unique as to not share nodes between models
|
5
|
+
- Properly order callback methods in which they will be executed
|
6
|
+
- Add sort order, instance method identifier, and symbol notation to diagram labels for better readability
|
7
|
+
- Show validation type and attributes instead of stringified class name
|
8
|
+
|
3
9
|
## [0.1.0]
|
4
10
|
- Initial release
|
data/Gemfile.lock
CHANGED
@@ -46,11 +46,12 @@ module Revocare
|
|
46
46
|
model.__callbacks.each do |_key, callback_chain|
|
47
47
|
callback_chain.each do |callback|
|
48
48
|
type = [callback.kind, callback.name].join("_")
|
49
|
+
methods = extract_methods(callback.filter)
|
49
50
|
callbacks_acc[type] ||= []
|
50
|
-
callbacks_acc[type]
|
51
|
+
callbacks_acc[type] += methods
|
51
52
|
end
|
52
53
|
end
|
53
|
-
end
|
54
|
+
end.transform_values(&:reverse)
|
54
55
|
end
|
55
56
|
|
56
57
|
def format_callbacks(callbacks)
|
@@ -61,5 +62,16 @@ module Revocare
|
|
61
62
|
}
|
62
63
|
end
|
63
64
|
end
|
65
|
+
|
66
|
+
def extract_methods(callback_filter)
|
67
|
+
if callback_filter.is_a?(ActiveModel::Validator)
|
68
|
+
name = callback_filter.class.name.demodulize.underscore
|
69
|
+
callback_filter.attributes.map do |attr|
|
70
|
+
[name, attr].join(":")
|
71
|
+
end
|
72
|
+
else
|
73
|
+
[callback_filter.to_s]
|
74
|
+
end
|
75
|
+
end
|
64
76
|
end
|
65
77
|
end
|
data/lib/revocare/data_writer.rb
CHANGED
@@ -10,6 +10,7 @@ module Revocare
|
|
10
10
|
DEFAULT_FILENAME = "callbacks.pdf"
|
11
11
|
|
12
12
|
def initialize(data:, format: DEFAULT_FORMAT)
|
13
|
+
@graph = GraphViz.new(:G, type: :digraph)
|
13
14
|
@data = data
|
14
15
|
@format = format
|
15
16
|
validate_format!
|
@@ -31,14 +32,16 @@ module Revocare
|
|
31
32
|
extension = File.extname(filename).tr(".", "").to_sym
|
32
33
|
|
33
34
|
if format == GRAPHVIZ_FORMAT
|
34
|
-
|
35
|
+
data.each_with_index do |model_data, index|
|
36
|
+
model_node = add_model_node(model_data[:model])
|
37
|
+
model_data[:callbacks].each do |callback|
|
38
|
+
name, chain = callback.values_at(:callback_name, :callback_chain)
|
39
|
+
name_node = add_callback_node(name, index)
|
40
|
+
method_nodes = chain.each_with_index.map do |method, order|
|
41
|
+
add_callback_chain_node(method, index, order)
|
42
|
+
end
|
35
43
|
|
36
|
-
data.each do |model_data|
|
37
|
-
model_node = graph.add_node(model_data[:model])
|
38
|
-
model_data[:callbacks].each do |c|
|
39
|
-
name_node = graph.add_node(c[:callback_name])
|
40
44
|
graph.add_edge(model_node, name_node)
|
41
|
-
method_nodes = c[:callback_chain].map(&graph.method(:add_node))
|
42
45
|
graph.add_edges(name_node, method_nodes)
|
43
46
|
end
|
44
47
|
end
|
@@ -49,12 +52,29 @@ module Revocare
|
|
49
52
|
|
50
53
|
private
|
51
54
|
|
52
|
-
attr_reader :data
|
55
|
+
attr_reader :data, :graph
|
53
56
|
|
54
57
|
def validate_format!
|
55
58
|
if !SUPPORTED_FORMATS.include?(@format)
|
56
59
|
raise ArgumentError, "Data format is not supported"
|
57
60
|
end
|
58
61
|
end
|
62
|
+
|
63
|
+
def add_model_node(name)
|
64
|
+
add_node(name, nil, :box)
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_callback_node(name, index)
|
68
|
+
add_node(":#{name}", index, :diamond)
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_callback_chain_node(name, index, order)
|
72
|
+
label = "#{order + 1}) ##{name}"
|
73
|
+
add_node(name, index, :ellipse, label)
|
74
|
+
end
|
75
|
+
|
76
|
+
def add_node(name, index, shape, label = nil)
|
77
|
+
graph.add_node("#{name}#{index}", label: label || name, shape: shape)
|
78
|
+
end
|
59
79
|
end
|
60
80
|
end
|
data/lib/revocare/version.rb
CHANGED
data/lib/revocare.rb
CHANGED
data/revocare.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
30
|
spec.add_runtime_dependency "activerecord", ">= 5.2", "< 7.1"
|
31
|
+
spec.add_runtime_dependency "activesupport", ">= 5.2", "< 7.1"
|
31
32
|
spec.add_runtime_dependency "ruby-graphviz", "~> 1.2"
|
32
33
|
|
33
34
|
spec.add_development_dependency "activerecord"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: revocare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Ewing
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -30,6 +30,26 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '7.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '5.2'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '7.1'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '5.2'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '7.1'
|
33
53
|
- !ruby/object:Gem::Dependency
|
34
54
|
name: ruby-graphviz
|
35
55
|
requirement: !ruby/object:Gem::Requirement
|