damn-legacy 0.0.1

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: b96bf47a973a7f75b2a393a72295e21183a9579438549729fdda111879bc2bd1
4
+ data.tar.gz: 10e299c01511bde3df106260c24218b4f0d55e4d67bf78dab878b639fd67ab00
5
+ SHA512:
6
+ metadata.gz: 0111550b7989e8d2ad925dcd69aea2a13814d7b2f64ee3b20f6f88e7f2d441a5375cb55268967e206bfc37f1975055e19e5681aee49b53a2b70d00cccf9a4140
7
+ data.tar.gz: e0e7e4b0115065c06656e58316bc8566858ec3a19f405ffdadc000ca75ce701d3607807db55db9ed3e52870f159b0345e7beb708b214e7f8397671085e5035a2
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+ Metrics/BlockLength:
15
+ Enabled: false
16
+ Style/Documentation:
17
+ Enabled: false
18
+ Metrics/CyclomaticComplexity:
19
+ Enabled: false
20
+ Metrics/PerceivedComplexity:
21
+ Enabled: false
22
+ Metrics/AbcSize:
23
+ Enabled: false
24
+ Metrics/MethodLength:
25
+ Enabled: false
26
+
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.3
@@ -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 gingray.dev@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,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in damn-legacy.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ gem "pry"
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ damn-legacy (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.5.0)
12
+ method_source (1.0.0)
13
+ parallel (1.21.0)
14
+ parser (3.1.0.0)
15
+ ast (~> 2.4.1)
16
+ pry (0.14.1)
17
+ coderay (~> 1.1)
18
+ method_source (~> 1.0)
19
+ rainbow (3.1.1)
20
+ rake (13.0.6)
21
+ regexp_parser (2.2.0)
22
+ rexml (3.2.5)
23
+ rspec (3.11.0)
24
+ rspec-core (~> 3.11.0)
25
+ rspec-expectations (~> 3.11.0)
26
+ rspec-mocks (~> 3.11.0)
27
+ rspec-core (3.11.0)
28
+ rspec-support (~> 3.11.0)
29
+ rspec-expectations (3.11.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.11.0)
32
+ rspec-mocks (3.11.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.11.0)
35
+ rspec-support (3.11.0)
36
+ rubocop (1.25.1)
37
+ parallel (~> 1.10)
38
+ parser (>= 3.1.0.0)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.8, < 3.0)
41
+ rexml
42
+ rubocop-ast (>= 1.15.1, < 2.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 1.4.0, < 3.0)
45
+ rubocop-ast (1.15.1)
46
+ parser (>= 3.0.1.1)
47
+ ruby-progressbar (1.11.0)
48
+ unicode-display_width (2.1.0)
49
+
50
+ PLATFORMS
51
+ ruby
52
+ x86_64-darwin-19
53
+
54
+ DEPENDENCIES
55
+ damn-legacy!
56
+ pry
57
+ rake (~> 13.0)
58
+ rspec (~> 3.0)
59
+ rubocop (~> 1.21)
60
+
61
+ BUNDLED WITH
62
+ 2.2.33
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 gingray
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,81 @@
1
+ # Damn::Legacy
2
+ Quite a lot of time I have to work with huge legacy code bases. When I face a bug I create small ruby script to put everything I've found or related information.
3
+ I create small DSL to describe "stacktraces" which I create by hand. Main goal of this gem is provide a nice DSL to create this kind of code mind maps.
4
+ I found it useful for few reasons first one all IDE support code navigation it means I can easely jump to real classes and keep context of the task tight in one file.
5
+ Second benefit this DSL can create diagrams currently it's support only [Mermaid.js](https://mermaid-js.github.io/mermaid/#/stateDiagram) state diagram.
6
+ Good thing about it you can easily visualise it and embed in your document to share it with someone for your own knowledge base.
7
+
8
+ I'm trying this thing as POC means if you find it useful it's cool if not whatever :)
9
+
10
+ ```ruby
11
+ Damn::Legacy.turn_on
12
+ Damn::Legacy.store_clean
13
+
14
+ DeductMoney.meth(:prepare).step do
15
+ Mail
16
+ end
17
+
18
+ Payment.meth([call: [validate: [check_balance: [:pay, :fail]]]]).step do
19
+ DeductMoney.meth(:call).step do
20
+ InformUser.meth(:notify).step do
21
+ Mail
22
+ end
23
+ end
24
+ end
25
+
26
+ ```
27
+ Example
28
+
29
+ ```mermaid
30
+ stateDiagram-v2
31
+ DeductMoney --> DeductMoney#prepare
32
+ DeductMoney --> DeductMoney#call
33
+ DeductMoney#prepare --> Mail
34
+ Payment --> Payment#call
35
+ Payment#call --> Payment#call#validate
36
+ Payment#call#validate --> Payment#call#validate#check_balance
37
+ Payment#call#validate#check_balance --> Payment#call#validate#check_balance#pay
38
+ Payment#call#validate#check_balance --> Payment#call#validate#check_balance#fail
39
+ InformUser --> InformUser#notify
40
+ InformUser#notify --> Mail
41
+ DeductMoney#call --> InformUser
42
+ Payment#call#validate#check_balance#pay --> DeductMoney
43
+ Payment#call#validate#check_balance#fail --> DeductMoney
44
+ ```
45
+ ## Installation
46
+
47
+ Add this line to your application's Gemfile:
48
+
49
+ ```ruby
50
+ gem 'damn-legacy'
51
+ ```
52
+
53
+ And then execute:
54
+
55
+ $ bundle install
56
+
57
+ Or install it yourself as:
58
+
59
+ $ gem install damn-legacy
60
+
61
+ ## Usage
62
+
63
+ TODO: Write usage instructions here
64
+
65
+ ## Development
66
+
67
+ 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.
68
+
69
+ 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).
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/damn-legacy. 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]/damn-legacy/blob/master/CODE_OF_CONDUCT.md).
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
78
+
79
+ ## Code of Conduct
80
+
81
+ Everyone interacting in the Damn::Legacy project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/damn-legacy/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "damn/legacy"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Damn
4
+ module Legacy
5
+ module DSL
6
+ def const_missing(name)
7
+ const_set(name, Class.new)
8
+ end
9
+
10
+ def meth(methods, _opts = {})
11
+ Store.instance.add_meth(self, methods)
12
+ end
13
+
14
+ def step(&block)
15
+ raise ArgumentError, "No block provided" unless block_given?
16
+
17
+ val = block.call
18
+ if !val.nil? && !Store.instance.stack.empty? && self == Store.instance.stack.first[1]
19
+ each do |key|
20
+ Store.instance.add(key, val)
21
+ end
22
+ else
23
+ head, = Store.instance.stack.shift
24
+ if head && is_a?(Array)
25
+ each do |key|
26
+ Store.instance.add(key, head)
27
+ end
28
+ end
29
+ end
30
+ self
31
+ end
32
+
33
+ def plot
34
+ Mermaid.call
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "singleton"
4
+ module Damn
5
+ module Legacy
6
+ class Store
7
+ attr_reader :store, :stack
8
+
9
+ include Singleton
10
+ def initialize
11
+ init
12
+ end
13
+
14
+ def add_meth(from, to)
15
+ val = add(from, to)
16
+ stack.unshift([from.to_s, val])
17
+ val
18
+ end
19
+
20
+ def add(from, to)
21
+ return add_array_to_store(from, to, "#") if to.is_a?(Array)
22
+ return add_hash_to_store(from, to, "#") if to.is_a?(Hash)
23
+ return add_sym_to_store(from, to, "#") if to.is_a?(Symbol)
24
+
25
+ add_default_to_store(from, to, "#")
26
+ end
27
+
28
+ def clean
29
+ init
30
+ end
31
+
32
+ private
33
+
34
+ def init
35
+ @store = Hash.new { |h, k| h[k] = [] }
36
+ @stack = []
37
+ end
38
+
39
+ def add_array_to_store(key, value, glue)
40
+ value.map do |m|
41
+ next add_sym_to_store(key, m, glue) if m.is_a?(Symbol)
42
+ next add_array_to_store(key, m, glue) if m.is_a?(Array)
43
+ next add_hash_to_store(key, m, glue) if m.is_a?(Hash)
44
+
45
+ add_default_to_store(key, m, glue)
46
+ end.flatten
47
+ end
48
+
49
+ def add_hash_to_store(key, value, glue)
50
+ value.map do |k, v|
51
+ next_key = "#{key}#{glue}#{k}"
52
+ store[key] << next_key
53
+ next add_sym_to_store(next_key, v, glue) if v.is_a?(Symbol)
54
+ next add_hash_to_store(next_key, v, glue) if v.is_a?(Hash)
55
+ next add_array_to_store(next_key, v, glue) if v.is_a?(Array)
56
+
57
+ add_default_to_store(next_key, v, glue)
58
+ end.flatten
59
+ end
60
+
61
+ def add_sym_to_store(key, value, glue)
62
+ new_value = "#{key}#{glue}#{value}"
63
+ store[key.to_s] << new_value
64
+ [new_value]
65
+ end
66
+
67
+ def add_default_to_store(key, value, _glue)
68
+ new_value = value.to_s
69
+ store[key.to_s] << new_value
70
+ store[new_value]
71
+ [new_value]
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Damn
4
+ module Legacy
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Damn
4
+ module Legacy
5
+ class Mermaid
6
+ attr_reader :store
7
+
8
+ def initialize(store)
9
+ @store = store
10
+ end
11
+
12
+ def self.call
13
+ new(Store.instance.store).call
14
+ end
15
+
16
+ def call
17
+ header = "stateDiagram-v2"
18
+ buffer = []
19
+ store.each do |k, v|
20
+ v.each do |item|
21
+ buffer << "#{k} --> #{item}"
22
+ end
23
+ end
24
+ [header, buffer.join("\n")].join("\n")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "legacy/version"
4
+ require_relative "legacy/dsl"
5
+ require_relative "legacy/store"
6
+ require_relative "legacy/visualizers/mermaid"
7
+
8
+ module Damn
9
+ module Legacy
10
+ class Error < StandardError; end
11
+
12
+ def self.turn_on
13
+ Object.class.prepend(DSL)
14
+ Object.prepend(DSL)
15
+ end
16
+
17
+ def self.store_clean
18
+ Store.instance.clean
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ module Damn
2
+ module Legacy
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: damn-legacy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - gingray
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Tool to help with legacy code and fix bugs
14
+ email:
15
+ - gingray.dev@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".rubocop.yml"
22
+ - ".ruby-version"
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/console
30
+ - bin/setup
31
+ - lib/damn/legacy.rb
32
+ - lib/damn/legacy/dsl.rb
33
+ - lib/damn/legacy/store.rb
34
+ - lib/damn/legacy/version.rb
35
+ - lib/damn/legacy/visualizers/mermaid.rb
36
+ - sig/damn/legacy.rbs
37
+ homepage: https://github.com/gingray/damn-legacy
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ allowed_push_host: https://rubygems.org
42
+ homepage_uri: https://github.com/gingray/damn-legacy
43
+ source_code_uri: https://github.com/gingray/damn-legacy
44
+ changelog_uri: https://github.com/gingray/damn-legacy
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.7.3
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.1.6
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Tool to help with legacy code and fix bugs
64
+ test_files: []