Skip to content

Commit

Permalink
Rename Diverdown -> DiverDown
Browse files Browse the repository at this point in the history
  • Loading branch information
alpaca-tc committed Mar 28, 2024
1 parent e642851 commit 0b1178d
Show file tree
Hide file tree
Showing 49 changed files with 304 additions and 304 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

# Specify your gem's dependencies in diverdown.gemspec
# Specify your gem's dependencies in diver_down.gemspec
gemspec

gem "rake", "~> 13.0"
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
diverdown (0.1.0)
diver_down (0.1.0)
activesupport
msgpack
rackup
Expand Down Expand Up @@ -94,7 +94,7 @@ PLATFORMS
ruby

DEPENDENCIES
diverdown!
diver_down!
eventmachine
puma
rack-proxy
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Diverdown
# DiverDown

`divertdown` is a tool that dynamically analyzes application dependencies and creates a dependency map.
This tool was created to analyze Ruby applications for use in large-scale refactoring such as moduler monolith.
Expand All @@ -10,7 +10,7 @@ The results of the analysis can be viewed in a browser, allowing you to deepen y
Add this line to your application's Gemfile:

```ruby
gem 'diverdown'
gem 'diver_down'
```

And then execute:
Expand All @@ -24,11 +24,11 @@ Or install it yourself as:
## Usage

```ruby
tracer = Diverdown::Trace::Tracer.new(
tracer = DiverDown::Trace::Tracer.new(
# @param target_files [Array<String>, Set<String>, nil] If nil, all files are targeted but slow.
# List of target files to be analyzed. Usually, gem and other files are excluded and specified.
target_files: Dir["app/**/*.rb"],
# @param module_set [Array<String>, Diverdown::Trace::ModuleSet] List of modules to be analyzed.
# @param module_set [Array<String>, DiverDown::Trace::ModuleSet] List of modules to be analyzed.
# When analyzing a your Rails application, set all classes/modules under app/.
module_set: [
'User',
Expand All @@ -38,7 +38,7 @@ tracer = Diverdown::Trace::Tracer.new(
],
# @param filter_method_id_path [#call, nil] The analysis result outputs the absolute path of the caller. To convert to a relative path, define the conversion logic manually.
filter_method_id_path: -> (path) { path.remove(Rails.root.to_s) },
# @param module_finder [#call, nil] Specify the logic to determine which module the source found. diverdown promote moduler monolithization, so such an option exists.
# @param module_finder [#call, nil] Specify the logic to determine which module the source found. diver_down promote moduler monolithization, so such an option exists.
module_finder: -> (source) { 'OrderSystem' if source.source == 'Order' },
)
```
Expand All @@ -47,7 +47,7 @@ tracer = Diverdown::Trace::Tracer.new(

After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.

### Development Diverdown::Web
### Development DiverDown::Web

```
# Start vite
Expand All @@ -61,12 +61,12 @@ $ DIVERDOWN_DIR=/path/to/definitions_dir bundle exec puma

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/alpaca-tc/diverdown. 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/alpaca-tc/diverdown/blob/main/CODE_OF_CONDUCT.md).
Bug reports and pull requests are welcome on GitHub at https://github.com/alpaca-tc/diver_down. 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/alpaca-tc/diver_down/blob/main/CODE_OF_CONDUCT.md).

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Code of Conduct

Everyone interacting in the Diverdown project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/alpaca-tc/diverdown/blob/main/CODE_OF_CONDUCT.md).
Everyone interacting in the DiverDown project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/alpaca-tc/diver_down/blob/main/CODE_OF_CONDUCT.md).
8 changes: 4 additions & 4 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require 'diverdown'
require 'diverdown/web'
require 'diver_down'
require 'diver_down/web'
require 'rack/reloader'

use Rack::Reloader
use Diverdown::Web::DevServerMiddleware, host: 'localhost', port: 5173 # Proxy to vite(pnpm run dev)
run Diverdown::Web.new(definition_dir: ENV.fetch('DIVERDOWN_DIR'))
use DiverDown::Web::DevServerMiddleware, host: 'localhost', port: 5173 # Proxy to vite(pnpm run dev)
run DiverDown::Web.new(definition_dir: ENV.fetch('DIVERDOWN_DIR'))
8 changes: 4 additions & 4 deletions diver_down.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

require_relative 'lib/diverdown/version'
require_relative 'lib/diver_down/version'

Gem::Specification.new do |spec|
spec.name = 'diverdown'
spec.version = Diverdown::VERSION
spec.name = 'diver_down'
spec.version = DiverDown::VERSION
spec.authors = ['alpaca-tc']
spec.email = ['[email protected]']

spec.summary = 'Tool to dynamically analyze applications and create dependency maps'
spec.description = ''
spec.homepage = 'https://github.com/alpaca-tc/diverdown'
spec.homepage = 'https://github.com/alpaca-tc/diver_down'
spec.license = 'MIT'
spec.required_ruby_version = '>= 3.2.0'

Expand Down
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<title>diverdown</title>
<title>diver_down</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="module" src="/main.tsx"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions lib/diver_down-trace.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

require 'diverdown'
require 'diverdown/trace'
require 'diver_down'
require 'diver_down/trace'
2 changes: 1 addition & 1 deletion lib/diver_down-web.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require 'diverdown/web'
require 'diver_down/web'
12 changes: 6 additions & 6 deletions lib/diver_down.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

require 'msgpack'
require_relative 'diverdown/version'
require_relative 'diver_down/version'

module Diverdown
module DiverDown
class Error < StandardError; end

DELIMITER = ','

require 'diverdown/definition'
require 'diverdown/definition_store'
require 'diverdown/indented_string_io'
require 'diverdown/helper'
require 'diver_down/definition'
require 'diver_down/definition_store'
require 'diver_down/indented_string_io'
require 'diver_down/helper'
end
30 changes: 15 additions & 15 deletions lib/diver_down/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

require 'securerandom'

module Diverdown
module DiverDown
class Definition
require 'diverdown/definition/source'
require 'diverdown/definition/dependency'
require 'diverdown/definition/modulee'
require 'diverdown/definition/method_id'
require 'diver_down/definition/source'
require 'diver_down/definition/dependency'
require 'diver_down/definition/modulee'
require 'diver_down/definition/method_id'

# @param hash [Hash]
# @return [Diverdown::Definition]
# @return [DiverDown::Definition]
def self.from_hash(hash)
new(
title: hash[:title] || '',
definition_group: hash[:definition_group],
sources: (hash[:sources] || []).map do |source_hash|
Diverdown::Definition::Source.from_hash(source_hash)
DiverDown::Definition::Source.from_hash(source_hash)
end
)
end

# @param definition_group [String, nil]
# @param title [String]
# @param definitions [Array<Diverdown::Definition>]
# @param definitions [Array<DiverDown::Definition>]
def self.combine(definition_group:, title:, definitions: [])
all_sources = definitions.flat_map(&:sources)

sources = all_sources.group_by(&:source_name).map do |_, same_sources|
Diverdown::Definition::Source.combine(*same_sources)
DiverDown::Definition::Source.combine(*same_sources)
end

new(
Expand All @@ -41,26 +41,26 @@ def self.combine(definition_group:, title:, definitions: [])
attr_reader :definition_group, :title

# @param title [String]
# @param sources [Array<Diverdown::Definition::Source>]
# @param sources [Array<DiverDown::Definition::Source>]
def initialize(definition_group: nil, title: '', sources: [])
@definition_group = definition_group
@title = title
@source_map = sources.map { [_1.source_name, _1] }.to_h
end

# @param source_name [String]
# @return [Diverdown::Definition::Source]
# @return [DiverDown::Definition::Source]
def find_or_build_source(source_name)
@source_map[source_name] ||= Diverdown::Definition::Source.new(source_name:)
@source_map[source_name] ||= DiverDown::Definition::Source.new(source_name:)
end

# @param source_name [String]
# @return [Diverdown::Definition::Source, nil]
# @return [DiverDown::Definition::Source, nil]
def source(source_name)
@source_map[source_name]
end

# @return [Array<Diverdown::Definition::Source>]
# @return [Array<DiverDown::Definition::Source>]
def sources
@source_map.values.sort
end
Expand All @@ -79,7 +79,7 @@ def to_msgpack
MessagePack.pack(to_h)
end

# @param other [Object, Diverdown::Definition::Source]
# @param other [Object, DiverDown::Definition::Source]
# @return [Boolean]
def ==(other)
other.is_a?(self.class) &&
Expand Down
22 changes: 11 additions & 11 deletions lib/diver_down/definition/dependency.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

module Diverdown
module DiverDown
class Definition
class Dependency
include Comparable

# @param hash [Hash]
# @return [Diverdown::Definition::Dependency]
# @return [DiverDown::Definition::Dependency]
def self.from_hash(hash)
method_ids = (hash[:method_ids] || []).map do
Diverdown::Definition::MethodId.new(**_1)
DiverDown::Definition::MethodId.new(**_1)
end

new(
Expand All @@ -18,8 +18,8 @@ def self.from_hash(hash)
)
end

# @param dependencies [Array<Diverdown::Definition::Dependency>]
# @return [Array<Diverdown::Definition::Dependency>]
# @param dependencies [Array<DiverDown::Definition::Dependency>]
# @return [Array<DiverDown::Definition::Dependency>]
def self.combine(*dependencies)
dependencies.group_by(&:source_name).map do |source_name, same_source_dependencies|
new_dependency = new(source_name:)
Expand All @@ -38,7 +38,7 @@ def self.combine(*dependencies)
attr_reader :source_name

# @param source_name [String]
# @param method_ids [Array<Diverdown::Definition::MethodId>]
# @param method_ids [Array<DiverDown::Definition::MethodId>]
def initialize(source_name:, method_ids: [])
@source_name = source_name
@method_id_map = {
Expand All @@ -53,19 +53,19 @@ def initialize(source_name:, method_ids: [])

# @param name [String]
# @param context ['instance', 'class']
# @return [Diverdown::Definition::MethodId]
# @return [DiverDown::Definition::MethodId]
def find_or_build_method_id(name:, context:)
@method_id_map[context.to_s][name.to_s] ||= Diverdown::Definition::MethodId.new(name:, context:)
@method_id_map[context.to_s][name.to_s] ||= DiverDown::Definition::MethodId.new(name:, context:)
end

# @param name [String, Symbol]
# @param context ['instance', 'class']
# @return [Diverdown::Definition::MethodId, nil]
# @return [DiverDown::Definition::MethodId, nil]
def method_id(name:, context:)
@method_id_map[context.to_s][name.to_s]
end

# @return [Array<Diverdown::Definition::MethodId>]
# @return [Array<DiverDown::Definition::MethodId>]
def method_ids
(@method_id_map['class'].values + @method_id_map['instance'].values).sort
end
Expand All @@ -83,7 +83,7 @@ def <=>(other)
source_name <=> other.source_name
end

# @param other [Object, Diverdown::Definition::Source]
# @param other [Object, DiverDown::Definition::Source]
# @return [Boolean]
def ==(other)
other.is_a?(self.class) &&
Expand Down
6 changes: 3 additions & 3 deletions lib/diver_down/definition/method_id.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module Diverdown
module DiverDown
class Definition
class MethodId
VALID_CONTEXT = %w[instance class].freeze
Expand Down Expand Up @@ -48,13 +48,13 @@ def hash
[self.class, name, context, paths].hash
end

# @param other [Diverdown::Definition::MethodId]
# @param other [DiverDown::Definition::MethodId]
# @return [Integer]
def <=>(other)
[name, context] <=> [other.name, other.context]
end

# @param other [Object, Diverdown::Definition::Source]
# @param other [Object, DiverDown::Definition::Source]
# @return [Boolean]
def ==(other)
other.is_a?(self.class) &&
Expand Down
4 changes: 2 additions & 2 deletions lib/diver_down/definition/modulee.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module Diverdown
module DiverDown
class Definition
# not typo. like "klass"
class Modulee
Expand All @@ -25,7 +25,7 @@ def <=>(other)
module_name <=> other.module_name
end

# @param other [Object, Diverdown::Definition::Source]
# @param other [Object, DiverDown::Definition::Source]
# @return [Boolean]
def ==(other)
other.is_a?(self.class) &&
Expand Down
Loading

0 comments on commit 0b1178d

Please sign in to comment.