revocare 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f2b42e4bf37a6ecf4e245bc0dabdf675a9ea7237d27d1c810c048b47f65c56c7
4
+ data.tar.gz: 2b4a998e3b47c0df9219a506e2345b592ff5e2c863dc9ce6183c159437c832b5
5
+ SHA512:
6
+ metadata.gz: 97bf8e3a739e1502efe39bb2b241b520f2c86055bebe9dd494aa86ce942dd31d9d119c5fe31e83670b22c95228349704f71385566bcb82aa83436aeea909f110
7
+ data.tar.gz: f7c6efa686dc23c788ab015ef47d8b07d38b860de55cb93f78cc6a9f1a9954ff8e223d603421d30f7d55f6f266d6d7865461255fdc60d604d0a5f2fc09c31a27
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,50 @@
1
+ AllCops:
2
+ SuggestExtensions: false
3
+ NewCops: enable
4
+
5
+ Gemspec/RequireMFA:
6
+ Enabled: false
7
+
8
+ Layout/MultilineMethodCallIndentation:
9
+ Enabled: false
10
+
11
+ Metrics/AbcSize:
12
+ Enabled: false
13
+
14
+ Metrics/BlockLength:
15
+ Exclude:
16
+ - revocare.gemspec
17
+ - spec/**/*.rb
18
+
19
+ Metrics/MethodLength:
20
+ Enabled: false
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Style/IfUnlessModifier:
26
+ Enabled: false
27
+
28
+ Style/GuardClause:
29
+ Enabled: false
30
+
31
+ Style/NegatedIf:
32
+ Enabled: false
33
+
34
+ Style/Next:
35
+ Enabled: false
36
+
37
+ Style/RegexpLiteral:
38
+ Enabled: false
39
+
40
+ Style/StringLiterals:
41
+ EnforcedStyle: double_quotes
42
+
43
+ Style/TrailingCommaInHashLiteral:
44
+ Enabled: false
45
+
46
+ Style/TrailingCommaInArrayLiteral:
47
+ Enabled: false
48
+
49
+ Style/WordArray:
50
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # `revocare`
2
+
3
+ ## [0.1.0]
4
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tewing10@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in revocare.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,233 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ revocare (0.1.0)
5
+ activerecord (>= 5.2.0, < 7.1)
6
+ ruby-graphviz (~> 1.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (7.0.4)
12
+ actionpack (= 7.0.4)
13
+ activesupport (= 7.0.4)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (7.0.4)
17
+ actionpack (= 7.0.4)
18
+ activejob (= 7.0.4)
19
+ activerecord (= 7.0.4)
20
+ activestorage (= 7.0.4)
21
+ activesupport (= 7.0.4)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.0.4)
27
+ actionpack (= 7.0.4)
28
+ actionview (= 7.0.4)
29
+ activejob (= 7.0.4)
30
+ activesupport (= 7.0.4)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
35
+ rails-dom-testing (~> 2.0)
36
+ actionpack (7.0.4)
37
+ actionview (= 7.0.4)
38
+ activesupport (= 7.0.4)
39
+ rack (~> 2.0, >= 2.2.0)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
+ actiontext (7.0.4)
44
+ actionpack (= 7.0.4)
45
+ activerecord (= 7.0.4)
46
+ activestorage (= 7.0.4)
47
+ activesupport (= 7.0.4)
48
+ globalid (>= 0.6.0)
49
+ nokogiri (>= 1.8.5)
50
+ actionview (7.0.4)
51
+ activesupport (= 7.0.4)
52
+ builder (~> 3.1)
53
+ erubi (~> 1.4)
54
+ rails-dom-testing (~> 2.0)
55
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
+ activejob (7.0.4)
57
+ activesupport (= 7.0.4)
58
+ globalid (>= 0.3.6)
59
+ activemodel (7.0.4)
60
+ activesupport (= 7.0.4)
61
+ activerecord (7.0.4)
62
+ activemodel (= 7.0.4)
63
+ activesupport (= 7.0.4)
64
+ activestorage (7.0.4)
65
+ actionpack (= 7.0.4)
66
+ activejob (= 7.0.4)
67
+ activerecord (= 7.0.4)
68
+ activesupport (= 7.0.4)
69
+ marcel (~> 1.0)
70
+ mini_mime (>= 1.1.0)
71
+ activesupport (7.0.4)
72
+ concurrent-ruby (~> 1.0, >= 1.0.2)
73
+ i18n (>= 1.6, < 2)
74
+ minitest (>= 5.1)
75
+ tzinfo (~> 2.0)
76
+ ast (2.4.2)
77
+ builder (3.2.4)
78
+ byebug (11.1.3)
79
+ coderay (1.1.3)
80
+ combustion (1.3.7)
81
+ activesupport (>= 3.0.0)
82
+ railties (>= 3.0.0)
83
+ thor (>= 0.14.6)
84
+ concurrent-ruby (1.1.10)
85
+ crass (1.0.6)
86
+ date (3.3.3)
87
+ diff-lcs (1.5.0)
88
+ erubi (1.12.0)
89
+ faker (3.1.0)
90
+ i18n (>= 1.8.11, < 2)
91
+ globalid (1.0.0)
92
+ activesupport (>= 5.0)
93
+ i18n (1.12.0)
94
+ concurrent-ruby (~> 1.0)
95
+ json (2.6.3)
96
+ loofah (2.19.1)
97
+ crass (~> 1.0.2)
98
+ nokogiri (>= 1.5.9)
99
+ mail (2.8.0.1)
100
+ mini_mime (>= 0.1.1)
101
+ net-imap
102
+ net-pop
103
+ net-smtp
104
+ marcel (1.0.2)
105
+ method_source (1.0.0)
106
+ mini_mime (1.1.2)
107
+ minitest (5.17.0)
108
+ net-imap (0.3.4)
109
+ date
110
+ net-protocol
111
+ net-pop (0.1.2)
112
+ net-protocol
113
+ net-protocol (0.2.1)
114
+ timeout
115
+ net-smtp (0.3.3)
116
+ net-protocol
117
+ nio4r (2.5.8)
118
+ nokogiri (1.14.0-x86_64-linux)
119
+ racc (~> 1.4)
120
+ parallel (1.22.1)
121
+ parser (3.2.0.0)
122
+ ast (~> 2.4.1)
123
+ pry (0.14.2)
124
+ coderay (~> 1.1)
125
+ method_source (~> 1.0)
126
+ pry-byebug (3.10.1)
127
+ byebug (~> 11.0)
128
+ pry (>= 0.13, < 0.15)
129
+ racc (1.6.2)
130
+ rack (2.2.5)
131
+ rack-test (2.0.2)
132
+ rack (>= 1.3)
133
+ rails (7.0.4)
134
+ actioncable (= 7.0.4)
135
+ actionmailbox (= 7.0.4)
136
+ actionmailer (= 7.0.4)
137
+ actionpack (= 7.0.4)
138
+ actiontext (= 7.0.4)
139
+ actionview (= 7.0.4)
140
+ activejob (= 7.0.4)
141
+ activemodel (= 7.0.4)
142
+ activerecord (= 7.0.4)
143
+ activestorage (= 7.0.4)
144
+ activesupport (= 7.0.4)
145
+ bundler (>= 1.15.0)
146
+ railties (= 7.0.4)
147
+ rails-dom-testing (2.0.3)
148
+ activesupport (>= 4.2.0)
149
+ nokogiri (>= 1.6)
150
+ rails-html-sanitizer (1.4.4)
151
+ loofah (~> 2.19, >= 2.19.1)
152
+ railties (7.0.4)
153
+ actionpack (= 7.0.4)
154
+ activesupport (= 7.0.4)
155
+ method_source
156
+ rake (>= 12.2)
157
+ thor (~> 1.0)
158
+ zeitwerk (~> 2.5)
159
+ rainbow (3.1.1)
160
+ rake (13.0.6)
161
+ regexp_parser (2.6.1)
162
+ rexml (3.2.5)
163
+ rspec (3.12.0)
164
+ rspec-core (~> 3.12.0)
165
+ rspec-expectations (~> 3.12.0)
166
+ rspec-mocks (~> 3.12.0)
167
+ rspec-core (3.12.0)
168
+ rspec-support (~> 3.12.0)
169
+ rspec-expectations (3.12.2)
170
+ diff-lcs (>= 1.2.0, < 2.0)
171
+ rspec-support (~> 3.12.0)
172
+ rspec-mocks (3.12.2)
173
+ diff-lcs (>= 1.2.0, < 2.0)
174
+ rspec-support (~> 3.12.0)
175
+ rspec-rails (5.1.2)
176
+ actionpack (>= 5.2)
177
+ activesupport (>= 5.2)
178
+ railties (>= 5.2)
179
+ rspec-core (~> 3.10)
180
+ rspec-expectations (~> 3.10)
181
+ rspec-mocks (~> 3.10)
182
+ rspec-support (~> 3.10)
183
+ rspec-support (3.12.0)
184
+ rubocop (1.43.0)
185
+ json (~> 2.3)
186
+ parallel (~> 1.10)
187
+ parser (>= 3.2.0.0)
188
+ rainbow (>= 2.2.2, < 4.0)
189
+ regexp_parser (>= 1.8, < 3.0)
190
+ rexml (>= 3.2.5, < 4.0)
191
+ rubocop-ast (>= 1.24.1, < 2.0)
192
+ ruby-progressbar (~> 1.7)
193
+ unicode-display_width (>= 2.4.0, < 3.0)
194
+ rubocop-ast (1.24.1)
195
+ parser (>= 3.1.1.0)
196
+ rubocop-capybara (2.17.0)
197
+ rubocop (~> 1.41)
198
+ rubocop-rspec (2.18.0)
199
+ rubocop (~> 1.33)
200
+ rubocop-capybara
201
+ ruby-graphviz (1.2.5)
202
+ rexml
203
+ ruby-progressbar (1.11.0)
204
+ sqlite3 (1.6.0-x86_64-linux)
205
+ thor (1.2.1)
206
+ timeout (0.3.1)
207
+ tzinfo (2.0.5)
208
+ concurrent-ruby (~> 1.0)
209
+ unicode-display_width (2.4.2)
210
+ websocket-driver (0.7.5)
211
+ websocket-extensions (>= 0.1.0)
212
+ websocket-extensions (0.1.5)
213
+ zeitwerk (2.6.6)
214
+
215
+ PLATFORMS
216
+ x86_64-linux
217
+
218
+ DEPENDENCIES
219
+ activerecord
220
+ combustion (~> 1.3)
221
+ faker
222
+ pry-byebug
223
+ rails (>= 5.2, < 7.1)
224
+ rake (~> 13.0)
225
+ revocare!
226
+ rspec (~> 3.0)
227
+ rspec-rails
228
+ rubocop (~> 1.21)
229
+ rubocop-rspec
230
+ sqlite3
231
+
232
+ BUNDLED WITH
233
+ 2.3.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Tyler Ewing
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Revocare
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/revocare`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add revocare
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install revocare
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/revocare. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/revocare/blob/master/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the Revocare project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/revocare/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
data/config.ru ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems"
4
+ require "bundler"
5
+
6
+ Bundler.require :default, :development
7
+
8
+ Combustion.initialize! :all
9
+ run Combustion::Application
data/exe/revocare ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ #!/usr/bin/env ruby
4
+
5
+ require "revocare/cli"
6
+
7
+ Revocare::CLI.call
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Revocare
4
+ class CallbackData
5
+ INTERNAL_MODELS = [
6
+ "ActiveRecord::InternalMetadata",
7
+ "ActiveRecord::SchemaMigration",
8
+ ].freeze
9
+
10
+ def self.to_a
11
+ new.to_a
12
+ end
13
+
14
+ def initialize
15
+ @data = []
16
+ end
17
+
18
+ def to_a
19
+ all_models.each do |model|
20
+ callbacks = callbacks_for(model)
21
+
22
+ if callbacks.any?
23
+ data << {
24
+ model: model.name,
25
+ callbacks: format_callbacks(callbacks),
26
+ }
27
+ end
28
+ end
29
+
30
+ data
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :data
36
+
37
+ def all_models
38
+ ::ActiveRecord::Base
39
+ .descendants
40
+ .reject { |model| INTERNAL_MODELS.include?(model&.name) }
41
+ .sort_by(&:name)
42
+ end
43
+
44
+ def callbacks_for(model)
45
+ {}.tap do |callbacks_acc|
46
+ model.__callbacks.each do |_key, callback_chain|
47
+ callback_chain.each do |callback|
48
+ type = [callback.kind, callback.name].join("_")
49
+ callbacks_acc[type] ||= []
50
+ callbacks_acc[type] << callback.filter.to_s
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def format_callbacks(callbacks)
57
+ callbacks.map do |name, chain|
58
+ {
59
+ callback_name: name,
60
+ callback_chain: chain,
61
+ }
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "revocare"
4
+
5
+ module Revocare
6
+ class CLI
7
+ def self.call
8
+ new.call
9
+ end
10
+
11
+ def initialize
12
+ environment_path = "#{Dir.pwd}/config/environment.rb"
13
+ Kernel.require environment_path
14
+
15
+ if Module.const_defined?("Rails")
16
+ Rails.application.eager_load!
17
+
18
+ if Rails.application.config.respond_to?(:eager_load_namespaces)
19
+ Rails.application.config.eager_load_namespaces.each(&:eager_load!)
20
+ end
21
+
22
+ if !Module.const_defined?("ActiveRecord")
23
+ raise "Must use `ActiveRecord`"
24
+ end
25
+ end
26
+ rescue LoadError
27
+ puts "Tried to load Rails environment but could not find it"
28
+ end
29
+
30
+ def call
31
+ data = Revocare::CallbackData.to_a
32
+ writer = Revocare::DataWriter.new(data: data)
33
+ writer.write_to_file
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Revocare
4
+ class DataWriter
5
+ GRAPHVIZ_FORMAT = :graphviz
6
+ DEFAULT_FORMAT = GRAPHVIZ_FORMAT
7
+ SUPPORTED_FORMATS = [
8
+ GRAPHVIZ_FORMAT,
9
+ ].freeze
10
+ DEFAULT_FILENAME = "callbacks.pdf"
11
+
12
+ def initialize(data:, format: DEFAULT_FORMAT)
13
+ @data = data
14
+ @format = format
15
+ validate_format!
16
+ end
17
+
18
+ def format
19
+ if @format == GRAPHVIZ_FORMAT
20
+ if Kernel.system("which dot")
21
+ puts "Graphviz libraries found"
22
+ else
23
+ raise "Graphviz libraries are not present"
24
+ end
25
+ end
26
+
27
+ @format
28
+ end
29
+
30
+ def write_to_file(filename: DEFAULT_FILENAME)
31
+ extension = File.extname(filename).tr(".", "").to_sym
32
+
33
+ if format == GRAPHVIZ_FORMAT
34
+ graph = GraphViz.new(:G, type: :digraph)
35
+
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
+ graph.add_edge(model_node, name_node)
41
+ method_nodes = c[:callback_chain].map(&graph.method(:add_node))
42
+ graph.add_edges(name_node, method_nodes)
43
+ end
44
+ end
45
+
46
+ graph.output(extension => filename)
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ attr_reader :data
53
+
54
+ def validate_format!
55
+ if !SUPPORTED_FORMATS.include?(@format)
56
+ raise ArgumentError, "Data format is not supported"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Revocare
4
+ VERSION = "0.1.0"
5
+ end
data/lib/revocare.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ruby-graphviz"
4
+
5
+ require_relative "revocare/callback_data"
6
+ require_relative "revocare/cli"
7
+ require_relative "revocare/data_writer"
8
+ require_relative "revocare/version"
9
+
10
+ module Revocare
11
+ end
data/revocare.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/revocare/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "revocare"
7
+ spec.version = Revocare::VERSION
8
+ spec.authors = ["Tyler Ewing"]
9
+ spec.email = ["tewing10@gmail.com"]
10
+ spec.summary = "A simple gem for visualizing ActiveRecord callback chains"
11
+ spec.description = "A simple gem for visualizing ActiveRecord callback chains"
12
+ spec.homepage = "https://github.com/zoso10/revocare"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
20
+
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
+ end
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency "activerecord", ">= 5.2", "< 7.1"
31
+ spec.add_runtime_dependency "ruby-graphviz", "~> 1.2"
32
+
33
+ spec.add_development_dependency "activerecord"
34
+ spec.add_development_dependency "combustion", "~> 1.3"
35
+ spec.add_development_dependency "faker"
36
+ spec.add_development_dependency "pry-byebug"
37
+ spec.add_development_dependency "rails", ">= 5.2", "< 7.1"
38
+ spec.add_development_dependency "rspec"
39
+ spec.add_development_dependency "rspec-rails"
40
+ spec.add_development_dependency "rubocop"
41
+ spec.add_development_dependency "rubocop-rspec"
42
+ spec.add_development_dependency "sqlite3"
43
+ end
data/sig/revocare.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Revocare
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,246 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: revocare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Ewing
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '5.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: ruby-graphviz
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.2'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: activerecord
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: combustion
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.3'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.3'
75
+ - !ruby/object:Gem::Dependency
76
+ name: faker
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: pry-byebug
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rails
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '5.2'
110
+ - - "<"
111
+ - !ruby/object:Gem::Version
112
+ version: '7.1'
113
+ type: :development
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '5.2'
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: '7.1'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rspec
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ - !ruby/object:Gem::Dependency
138
+ name: rspec-rails
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ - !ruby/object:Gem::Dependency
152
+ name: rubocop
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ - !ruby/object:Gem::Dependency
166
+ name: rubocop-rspec
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ type: :development
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ - !ruby/object:Gem::Dependency
180
+ name: sqlite3
181
+ requirement: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ type: :development
187
+ prerelease: false
188
+ version_requirements: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ description: A simple gem for visualizing ActiveRecord callback chains
194
+ email:
195
+ - tewing10@gmail.com
196
+ executables:
197
+ - revocare
198
+ extensions: []
199
+ extra_rdoc_files: []
200
+ files:
201
+ - ".rspec"
202
+ - ".rubocop.yml"
203
+ - CHANGELOG.md
204
+ - CODE_OF_CONDUCT.md
205
+ - Gemfile
206
+ - Gemfile.lock
207
+ - LICENSE.txt
208
+ - README.md
209
+ - Rakefile
210
+ - config.ru
211
+ - exe/revocare
212
+ - lib/revocare.rb
213
+ - lib/revocare/callback_data.rb
214
+ - lib/revocare/cli.rb
215
+ - lib/revocare/data_writer.rb
216
+ - lib/revocare/version.rb
217
+ - revocare.gemspec
218
+ - sig/revocare.rbs
219
+ homepage: https://github.com/zoso10/revocare
220
+ licenses:
221
+ - MIT
222
+ metadata:
223
+ allowed_push_host: https://rubygems.org
224
+ homepage_uri: https://github.com/zoso10/revocare
225
+ source_code_uri: https://github.com/zoso10/revocare
226
+ changelog_uri: https://github.com/zoso10/revocare/blob/main/CHANGELOG.md
227
+ post_install_message:
228
+ rdoc_options: []
229
+ require_paths:
230
+ - lib
231
+ required_ruby_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">="
234
+ - !ruby/object:Gem::Version
235
+ version: 2.6.0
236
+ required_rubygems_version: !ruby/object:Gem::Requirement
237
+ requirements:
238
+ - - ">="
239
+ - !ruby/object:Gem::Version
240
+ version: '0'
241
+ requirements: []
242
+ rubygems_version: 3.3.26
243
+ signing_key:
244
+ specification_version: 4
245
+ summary: A simple gem for visualizing ActiveRecord callback chains
246
+ test_files: []