From 0b1178dd7e7d14f8a0ffdfd9925e470e8eb5b47a Mon Sep 17 00:00:00 2001 From: alpaca-tc Date: Thu, 28 Mar 2024 23:00:15 +0900 Subject: [PATCH] Rename Diverdown -> DiverDown --- Gemfile | 2 +- Gemfile.lock | 4 +- README.md | 16 ++--- config.ru | 8 +-- diver_down.gemspec | 8 +-- frontend/index.html | 2 +- lib/diver_down-trace.rb | 4 +- lib/diver_down-web.rb | 2 +- lib/diver_down.rb | 12 ++-- lib/diver_down/definition.rb | 30 +++++----- lib/diver_down/definition/dependency.rb | 22 +++---- lib/diver_down/definition/method_id.rb | 6 +- lib/diver_down/definition/modulee.rb | 4 +- lib/diver_down/definition/source.rb | 32 +++++----- lib/diver_down/definition_store.rb | 14 ++--- lib/diver_down/helper.rb | 2 +- lib/diver_down/indented_string_io.rb | 2 +- lib/diver_down/trace.rb | 16 ++--- lib/diver_down/trace/call_stack.rb | 2 +- lib/diver_down/trace/module_set.rb | 8 +-- lib/diver_down/trace/redefine_ruby_methods.rb | 2 +- lib/diver_down/trace/tracer.rb | 22 +++---- lib/diver_down/version.rb | 2 +- lib/diver_down/web.rb | 26 ++++----- lib/diver_down/web/action.rb | 18 +++--- lib/diver_down/web/bit_id.rb | 2 +- lib/diver_down/web/concurrency_worker.rb | 2 +- lib/diver_down/web/definition_enumerator.rb | 4 +- lib/diver_down/web/definition_to_dot.rb | 10 ++-- lib/diver_down/web/dev_server_middleware.rb | 2 +- package.json | 4 +- spec/diver_down/definition/dependency_spec.rb | 38 ++++++------ spec/diver_down/definition/method_id_spec.rb | 2 +- spec/diver_down/definition/modulee_spec.rb | 10 ++-- spec/diver_down/definition/source_spec.rb | 52 ++++++++--------- spec/diver_down/definition_spec.rb | 58 +++++++++---------- spec/diver_down/definition_store_spec.rb | 40 ++++++------- spec/diver_down/helper_spec.rb | 2 +- spec/diver_down/indented_string_io_spec.rb | 2 +- spec/diver_down/trace/call_stack_spec.rb | 2 +- spec/diver_down/trace/module_set_spec.rb | 2 +- .../trace/redefine_ruby_methods_spec.rb | 2 +- spec/diver_down/trace/tracer_spec.rb | 4 +- spec/diver_down/web/bit_id_spec.rb | 2 +- .../web/definition_enumerator_spec.rb | 32 +++++----- spec/diver_down/web/definition_to_dot_spec.rb | 10 ++-- spec/diver_down/web_spec.rb | 52 ++++++++--------- spec/diver_down_spec.rb | 2 +- spec/spec_helper.rb | 6 +- 49 files changed, 304 insertions(+), 304 deletions(-) diff --git a/Gemfile b/Gemfile index 0cdc1ef..c00190d 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index a8aa468..7d05a1d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - diverdown (0.1.0) + diver_down (0.1.0) activesupport msgpack rackup @@ -94,7 +94,7 @@ PLATFORMS ruby DEPENDENCIES - diverdown! + diver_down! eventmachine puma rack-proxy diff --git a/README.md b/README.md index 7b67e45..cd04946 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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: @@ -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, Set, 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, Diverdown::Trace::ModuleSet] List of modules to be analyzed. + # @param module_set [Array, DiverDown::Trace::ModuleSet] List of modules to be analyzed. # When analyzing a your Rails application, set all classes/modules under app/. module_set: [ 'User', @@ -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' }, ) ``` @@ -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 @@ -61,7 +61,7 @@ $ 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 @@ -69,4 +69,4 @@ The gem is available as open source under the terms of the [MIT License](https:/ ## 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). diff --git a/config.ru b/config.ru index 51c2ed2..59cfef8 100644 --- a/config.ru +++ b/config.ru @@ -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')) diff --git a/diver_down.gemspec b/diver_down.gemspec index 859926a..3791067 100644 --- a/diver_down.gemspec +++ b/diver_down.gemspec @@ -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 = ['alpaca-tc@alpaca.tc'] 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' diff --git a/frontend/index.html b/frontend/index.html index 345b797..946f8e3 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -2,7 +2,7 @@ - diverdown + diver_down diff --git a/lib/diver_down-trace.rb b/lib/diver_down-trace.rb index a226779..2252afa 100644 --- a/lib/diver_down-trace.rb +++ b/lib/diver_down-trace.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true -require 'diverdown' -require 'diverdown/trace' +require 'diver_down' +require 'diver_down/trace' diff --git a/lib/diver_down-web.rb b/lib/diver_down-web.rb index acc1380..803a86b 100644 --- a/lib/diver_down-web.rb +++ b/lib/diver_down-web.rb @@ -1,3 +1,3 @@ # frozen_string_literal: true -require 'diverdown/web' +require 'diver_down/web' diff --git a/lib/diver_down.rb b/lib/diver_down.rb index a793bdf..75efdc4 100644 --- a/lib/diver_down.rb +++ b/lib/diver_down.rb @@ -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 diff --git a/lib/diver_down/definition.rb b/lib/diver_down/definition.rb index 79aecd7..025558b 100644 --- a/lib/diver_down/definition.rb +++ b/lib/diver_down/definition.rb @@ -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] + # @param definitions [Array] 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( @@ -41,7 +41,7 @@ def self.combine(definition_group:, title:, definitions: []) attr_reader :definition_group, :title # @param title [String] - # @param sources [Array] + # @param sources [Array] def initialize(definition_group: nil, title: '', sources: []) @definition_group = definition_group @title = title @@ -49,18 +49,18 @@ def initialize(definition_group: nil, title: '', sources: []) 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] + # @return [Array] def sources @source_map.values.sort end @@ -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) && diff --git a/lib/diver_down/definition/dependency.rb b/lib/diver_down/definition/dependency.rb index 2d0042a..ebbfdb2 100644 --- a/lib/diver_down/definition/dependency.rb +++ b/lib/diver_down/definition/dependency.rb @@ -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( @@ -18,8 +18,8 @@ def self.from_hash(hash) ) end - # @param dependencies [Array] - # @return [Array] + # @param dependencies [Array] + # @return [Array] def self.combine(*dependencies) dependencies.group_by(&:source_name).map do |source_name, same_source_dependencies| new_dependency = new(source_name:) @@ -38,7 +38,7 @@ def self.combine(*dependencies) attr_reader :source_name # @param source_name [String] - # @param method_ids [Array] + # @param method_ids [Array] def initialize(source_name:, method_ids: []) @source_name = source_name @method_id_map = { @@ -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] + # @return [Array] def method_ids (@method_id_map['class'].values + @method_id_map['instance'].values).sort end @@ -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) && diff --git a/lib/diver_down/definition/method_id.rb b/lib/diver_down/definition/method_id.rb index 9c180e3..bc957d2 100644 --- a/lib/diver_down/definition/method_id.rb +++ b/lib/diver_down/definition/method_id.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Diverdown +module DiverDown class Definition class MethodId VALID_CONTEXT = %w[instance class].freeze @@ -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) && diff --git a/lib/diver_down/definition/modulee.rb b/lib/diver_down/definition/modulee.rb index d0490ca..74e9970 100644 --- a/lib/diver_down/definition/modulee.rb +++ b/lib/diver_down/definition/modulee.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Diverdown +module DiverDown class Definition # not typo. like "klass" class Modulee @@ -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) && diff --git a/lib/diver_down/definition/source.rb b/lib/diver_down/definition/source.rb index ad213f5..5a2212e 100644 --- a/lib/diver_down/definition/source.rb +++ b/lib/diver_down/definition/source.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Diverdown +module DiverDown class Definition class Source include Comparable @@ -9,13 +9,13 @@ class Source def self.from_hash(hash) new( source_name: hash[:source_name], - dependencies: (hash[:dependencies] || []).map { Diverdown::Definition::Dependency.from_hash(_1) }, - modules: (hash[:modules] || []).map { Diverdown::Definition::Modulee.new(**_1) } + dependencies: (hash[:dependencies] || []).map { DiverDown::Definition::Dependency.from_hash(_1) }, + modules: (hash[:modules] || []).map { DiverDown::Definition::Modulee.new(**_1) } ) end - # @param sources [Array] - # @return [Diverdown::Definition::Source] + # @param sources [Array] + # @return [DiverDown::Definition::Source] def self.combine(*sources) raise ArgumentError, 'sources are empty' if sources.empty? @@ -33,7 +33,7 @@ def self.combine(*sources) new( source_name: unique_sources[0], - dependencies: Diverdown::Definition::Dependency.combine(*all_dependencies), + dependencies: DiverDown::Definition::Dependency.combine(*all_dependencies), modules: unique_modules[0] ) end @@ -41,8 +41,8 @@ def self.combine(*sources) attr_reader :source_name, :modules # @param source_name [String] filename of the source file - # @param dependencies [Array] - # @param modules [Array] + # @param dependencies [Array] + # @param modules [Array] def initialize(source_name:, dependencies: [], modules: []) @source_name = source_name @dependency_map = dependencies.map { [_1.source_name, _1] }.to_h @@ -50,28 +50,28 @@ def initialize(source_name:, dependencies: [], modules: []) end # @param source [String] - # @return [Diverdown::Definition::Dependency, nil] return nil if source is self.source + # @return [DiverDown::Definition::Dependency, nil] return nil if source is self.source def find_or_build_dependency(dependency_source_name) return if source_name == dependency_source_name - @dependency_map[dependency_source_name] ||= Diverdown::Definition::Dependency.new(source_name: dependency_source_name) + @dependency_map[dependency_source_name] ||= DiverDown::Definition::Dependency.new(source_name: dependency_source_name) end # @param dependency_source_name [String] - # @return [Diverdown::Definition::Dependency, nil] + # @return [DiverDown::Definition::Dependency, nil] def dependency(dependency_source_name) @dependency_map[dependency_source_name] end # @param module_names [Array] - # @return [Diverdown::Definition::Modulee] + # @return [DiverDown::Definition::Modulee] def set_modules(module_names) @modules = module_names.map do - Diverdown::Definition::Modulee.new(module_name: _1) + DiverDown::Definition::Modulee.new(module_name: _1) end end - # @return [Array] + # @return [Array] def dependencies @dependency_map.values.sort end @@ -85,13 +85,13 @@ def to_h } end - # @param other [Diverdown::Definition::Source] + # @param other [DiverDown::Definition::Source] # @return [Integer] 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) && diff --git a/lib/diver_down/definition_store.rb b/lib/diver_down/definition_store.rb index 0f62acb..cd24827 100644 --- a/lib/diver_down/definition_store.rb +++ b/lib/diver_down/definition_store.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Diverdown +module DiverDown class DefinitionStore include Enumerable @@ -12,7 +12,7 @@ def initialize # @param id [Integer] # @raise [KeyError] if the id is not found - # @return [Diverdown::Definition] + # @return [DiverDown::Definition] def get(id) index = id - 1 @@ -21,7 +21,7 @@ def get(id) @definitions.fetch(index) end - # @param definitions [Array] + # @param definitions [Array] # @return [Array] ids of the definitions def set(*definitions) definitions.map do @@ -48,12 +48,12 @@ def definition_groups end # @param definition_group [String, nil] - # @return [Array] + # @return [Array] def filter_by_definition_group(definition_group) @definition_group_store.fetch(definition_group, []) end - # @param definition [Diverdown::Definition] + # @param definition [DiverDown::Definition] # @raise [KeyError] if the definition is not found # @return [Integer] def get_id(definition) @@ -80,13 +80,13 @@ def empty? # Clear the store # @return [void] def clear - # Hash{ Integer(unique bit flag) => Diverdown::Definition } + # Hash{ Integer(unique bit flag) => DiverDown::Definition } @definitions = [] @invert_id = {} @definition_group_store = Hash.new { |h, k| h[k] = [] } end - # @yield [Diverdown::Definition] + # @yield [DiverDown::Definition] def each return enum_for(__method__) unless block_given? diff --git a/lib/diver_down/helper.rb b/lib/diver_down/helper.rb index 6e18334..ac4dfda 100644 --- a/lib/diver_down/helper.rb +++ b/lib/diver_down/helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Diverdown +module DiverDown module Helper CLASS_NAME_QUERY = Module.method(:name).unbind.freeze diff --git a/lib/diver_down/indented_string_io.rb b/lib/diver_down/indented_string_io.rb index 5cd9fdb..fa461d6 100644 --- a/lib/diver_down/indented_string_io.rb +++ b/lib/diver_down/indented_string_io.rb @@ -3,7 +3,7 @@ require 'stringio' require 'forwardable' -module Diverdown +module DiverDown class IndentedStringIo extend ::Forwardable diff --git a/lib/diver_down/trace.rb b/lib/diver_down/trace.rb index eebf73c..2b081b4 100644 --- a/lib/diver_down/trace.rb +++ b/lib/diver_down/trace.rb @@ -2,12 +2,12 @@ require 'active_support/inflector' -module Diverdown +module DiverDown module Trace - require 'diverdown/trace/tracer' - require 'diverdown/trace/call_stack' - require 'diverdown/trace/module_set' - require 'diverdown/trace/redefine_ruby_methods' + require 'diver_down/trace/tracer' + require 'diver_down/trace/call_stack' + require 'diver_down/trace/module_set' + require 'diver_down/trace/redefine_ruby_methods' @trace_events = %i[ call c_call return c_return @@ -17,9 +17,9 @@ module Trace # Override Ruby only with the minimal set of methods needed to trace dependencies. # # @return [void] - def self.trace_only_ruby_world!(map = Diverdown::Trace::RedefineRubyMethods::DEFAULT_METHODS) - Diverdown::Trace::Tracer.trace_events = %i[call return] - Diverdown::Trace::RedefineRubyMethods.redefine_c_methods(map) + def self.trace_only_ruby_world!(map = DiverDown::Trace::RedefineRubyMethods::DEFAULT_METHODS) + DiverDown::Trace::Tracer.trace_events = %i[call return] + DiverDown::Trace::RedefineRubyMethods.redefine_c_methods(map) end end end diff --git a/lib/diver_down/trace/call_stack.rb b/lib/diver_down/trace/call_stack.rb index 075e8ee..cc2b0ae 100644 --- a/lib/diver_down/trace/call_stack.rb +++ b/lib/diver_down/trace/call_stack.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Diverdown +module DiverDown module Trace # To handle call stacks obtained by TracePoint more efficiently. # TracePoint also acquires calls that are not trace targets, but for dependency extraction, we want to acquire only a list of targets. diff --git a/lib/diver_down/trace/module_set.rb b/lib/diver_down/trace/module_set.rb index 804f597..df3316c 100644 --- a/lib/diver_down/trace/module_set.rb +++ b/lib/diver_down/trace/module_set.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Diverdown +module DiverDown module Trace # A class to quickly determine if a TracePoint is a module to be traced. class ModuleSet @@ -59,7 +59,7 @@ def superclass_include(mod) def add(mod_or_module_name, value) @set[mod_or_module_name] = value - if Diverdown::Helper.module?(mod_or_module_name) + if DiverDown::Helper.module?(mod_or_module_name) @set[normalize_module_name(mod_or_module_name)] = value else @set[constantize(mod_or_module_name)] = value @@ -69,13 +69,13 @@ def add(mod_or_module_name, value) # @param [String] module_name # @return [Module] def constantize(module_name) - @constantized_cache[module_name] ||= Diverdown::Helper.constantize(module_name) + @constantized_cache[module_name] ||= DiverDown::Helper.constantize(module_name) end # @param [Module] mod # @return [String] def normalize_module_name(mod) - @normalized_module_name_cache[mod] ||= Diverdown::Helper.normalize_module_name(mod) + @normalized_module_name_cache[mod] ||= DiverDown::Helper.normalize_module_name(mod) end end end diff --git a/lib/diver_down/trace/redefine_ruby_methods.rb b/lib/diver_down/trace/redefine_ruby_methods.rb index fc3671c..0e01822 100644 --- a/lib/diver_down/trace/redefine_ruby_methods.rb +++ b/lib/diver_down/trace/redefine_ruby_methods.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Diverdown +module DiverDown module Trace # Tracepoint traces only ruby-lang calls because tracing c-lang calls is very slow. # In this case, methods such as new will not be traceable under normal circumstances, so at a minimum, redefine them in ruby and hack them so that they can be traced. diff --git a/lib/diver_down/trace/tracer.rb b/lib/diver_down/trace/tracer.rb index 2baf04e..062e098 100644 --- a/lib/diver_down/trace/tracer.rb +++ b/lib/diver_down/trace/tracer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Diverdown +module DiverDown module Trace class Tracer StackContext = Data.define(:source, :method_id, :caller_location) @@ -15,20 +15,20 @@ class << self attr_writer :trace_events end - # @param module_set [Diverdown::Trace::ModuleSet, Array] + # @param module_set [DiverDown::Trace::ModuleSet, Array] # @param target_files [Array, nil] if nil, trace all files # @param filter_method_id_path [#call, nil] filter method_id.path - # @param module_set [Diverdown::Trace::ModuleSet, nil] for optimization + # @param module_set [DiverDown::Trace::ModuleSet, nil] for optimization # @param module_finder [#call] find module from source def initialize(module_set: [], target_files: nil, filter_method_id_path: nil, module_finder: nil) if target_files && !target_files.all? { Pathname.new(_1).absolute? } raise ArgumentError, "target_files must be absolute path(#{target_files})" end - @module_set = if module_set.is_a?(Diverdown::Trace::ModuleSet) + @module_set = if module_set.is_a?(DiverDown::Trace::ModuleSet) module_set else - Diverdown::Trace::ModuleSet.new(module_set) + DiverDown::Trace::ModuleSet.new(module_set) end @target_file_set = target_files&.to_set @@ -41,10 +41,10 @@ def initialize(module_set: [], target_files: nil, filter_method_id_path: nil, mo # @param title [String] # @param definition_group [String, nil] # - # @return [Diverdown::Definition] + # @return [DiverDown::Definition] def trace(title:, definition_group: nil, &) - call_stack = Diverdown::Trace::CallStack.new - definition = Diverdown::Definition.new( + call_stack = DiverDown::Trace::CallStack.new + definition = DiverDown::Definition.new( definition_group:, title: ) @@ -53,8 +53,8 @@ def trace(title:, definition_group: nil, &) case tp.event when :call, :c_call # puts "#{tp.method_id} #{tp.path}:#{tp.lineno}" - mod = Diverdown::Helper.resolve_module(tp.self) - source_name = Diverdown::Helper.normalize_module_name(mod) if !mod.nil? && @module_set.include?(mod) + mod = DiverDown::Helper.resolve_module(tp.self) + source_name = DiverDown::Helper.normalize_module_name(mod) if !mod.nil? && @module_set.include?(mod) pushed = false unless source_name.nil? @@ -73,7 +73,7 @@ def trace(title:, definition_group: nil, &) # `dependency.nil?` means source_name equals to called_source.source. # self-references are not tracked because it is not "dependency". if dependency - context = Diverdown::Helper.module?(tp.self) ? 'class' : 'instance' + context = DiverDown::Helper.module?(tp.self) ? 'class' : 'instance' method_id = dependency.find_or_build_method_id(name: tp.method_id, context:) method_id_path = "#{called_stack_context.caller_location.path}:#{called_stack_context.caller_location.lineno}" method_id_path = @filter_method_id_path.call(method_id_path) if @filter_method_id_path diff --git a/lib/diver_down/version.rb b/lib/diver_down/version.rb index bd6f4e6..934a6d5 100644 --- a/lib/diver_down/version.rb +++ b/lib/diver_down/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -module Diverdown +module DiverDown VERSION = '0.1.0' end diff --git a/lib/diver_down/web.rb b/lib/diver_down/web.rb index 66816b5..36e6f9b 100644 --- a/lib/diver_down/web.rb +++ b/lib/diver_down/web.rb @@ -3,24 +3,24 @@ require 'rack' require 'yaml' -module Diverdown +module DiverDown class Web WEB_DIR = File.expand_path('../../web', __dir__) - require 'diverdown/web/action' - require 'diverdown/web/definition_to_dot' - require 'diverdown/web/concurrency_worker' - require 'diverdown/web/definition_enumerator' - require 'diverdown/web/bit_id' + require 'diver_down/web/action' + require 'diver_down/web/definition_to_dot' + require 'diver_down/web/concurrency_worker' + require 'diver_down/web/definition_enumerator' + require 'diver_down/web/bit_id' # For development - autoload :DevServerMiddleware, 'diverdown/web/dev_server_middleware' + autoload :DevServerMiddleware, 'diver_down/web/dev_server_middleware' M = Mutex.new # @param definition_dir [String] - # @param store [Diverdown::DefinitionStore] - def initialize(definition_dir:, store: Diverdown::DefinitionStore.new) + # @param store [DiverDown::DefinitionStore] + def initialize(definition_dir:, store: DiverDown::DefinitionStore.new) @definition_dir = definition_dir @store = store @files_server = Rack::Files.new(File.join(WEB_DIR)) @@ -30,7 +30,7 @@ def initialize(definition_dir:, store: Diverdown::DefinitionStore.new) # @return [Array[Integer, Hash, Array]] def call(env) request = Rack::Request.new(env) - action = Diverdown::Web::Action.new(store: @store, request:) + action = DiverDown::Web::Action.new(store: @store, request:) if @store.empty? M.synchronize do @@ -71,10 +71,10 @@ def load_store # TODO: Loading all yaml is slow. Need to filter to load only wanted yaml. files = Dir[File.join(@definition_dir, '**', '*.msgpack')].sort.first(1000) - concurrency_worker = Diverdown::Web::ConcurrencyWorker.new(concurrency: 30) + concurrency_worker = DiverDown::Web::ConcurrencyWorker.new(concurrency: 30) concurrency_worker.run(files) do |path| - hash = Diverdown::Helper.deep_symbolize_keys(MessagePack.unpack(File.binread(path))) - definition = Diverdown::Definition.from_hash(hash) + hash = DiverDown::Helper.deep_symbolize_keys(MessagePack.unpack(File.binread(path))) + definition = DiverDown::Definition.from_hash(hash) @store.set(definition) end diff --git a/lib/diver_down/web/action.rb b/lib/diver_down/web/action.rb index c3942d3..6077534 100644 --- a/lib/diver_down/web/action.rb +++ b/lib/diver_down/web/action.rb @@ -2,7 +2,7 @@ require 'json' -module Diverdown +module DiverDown class Web class Action Pagination = Data.define( @@ -12,7 +12,7 @@ class Action :per ) - # @param store [Diverdown::Definition::Store] + # @param store [DiverDown::Definition::Store] # @param request [Rack::Request] def initialize(store:, request:) @store = store @@ -47,7 +47,7 @@ def sources # @param title [String] # @param source [String] def definitions(page:, per:, title:, source:) - definition_enumerator = Diverdown::Web::DefinitionEnumerator.new(@store, title:, source:) + definition_enumerator = DiverDown::Web::DefinitionEnumerator.new(@store, title:, source:) definitions, pagination = paginate(definition_enumerator, page, per) json( @@ -66,7 +66,7 @@ def definitions(page:, per:, title:, source:) # # @param bit_id [Integer] def combine_definitions(bit_id) - ids = Diverdown::Web::BitId.bit_id_to_ids(bit_id) + ids = DiverDown::Web::BitId.bit_id_to_ids(bit_id) valid_ids = ids.select do @store.key?(_1) @@ -76,9 +76,9 @@ def combine_definitions(bit_id) if definition json( - bit_id: Diverdown::Web::BitId.ids_to_bit_id(valid_ids).to_s, + bit_id: DiverDown::Web::BitId.ids_to_bit_id(valid_ids).to_s, title: definition.title, - dot: Diverdown::Web::DefinitionToDot.new(definition).to_s, + dot: DiverDown::Web::DefinitionToDot.new(definition).to_s, sources: definition.sources.map { { source_name: _1.source_name } } ) else @@ -92,7 +92,7 @@ def combine_definitions(bit_id) def source(source_name) found_sources = [] related_definitions = [] - reverse_dependencies = Hash.new { |h, dependency_source_name| h[dependency_source_name] = Diverdown::Definition::Dependency.new(source_name: dependency_source_name) } + reverse_dependencies = Hash.new { |h, dependency_source_name| h[dependency_source_name] = DiverDown::Definition::Dependency.new(source_name: dependency_source_name) } @store.each do |id, definition| found_source = nil @@ -125,7 +125,7 @@ def source(source_name) modules = if found_sources.empty? [] else - Diverdown::Definition::Source.combine(*found_sources).modules + DiverDown::Definition::Source.combine(*found_sources).modules end json( @@ -203,7 +203,7 @@ def fetch_definition(ids) def combine_ids_definitions(ids) definitions = ids.map { @store.get(_1) } - Diverdown::Definition.combine(definition_group: nil, title: 'combined', definitions:) + DiverDown::Definition.combine(definition_group: nil, title: 'combined', definitions:) end def json(data) diff --git a/lib/diver_down/web/bit_id.rb b/lib/diver_down/web/bit_id.rb index ec67468..4b7f228 100644 --- a/lib/diver_down/web/bit_id.rb +++ b/lib/diver_down/web/bit_id.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Diverdown +module DiverDown class Web # Use bitflag for a lightweight representation of a list of bound definitions on a URL. # Each definition is related with a unique bitflag, and when merging, the bitflag is calculated with `OR` to represent the merged definitions in a lightweight and fast. diff --git a/lib/diver_down/web/concurrency_worker.rb b/lib/diver_down/web/concurrency_worker.rb index 7d5eb34..1fc59dc 100644 --- a/lib/diver_down/web/concurrency_worker.rb +++ b/lib/diver_down/web/concurrency_worker.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module Diverdown +module DiverDown class Web class ConcurrencyWorker # @param concurrency [Integer] diff --git a/lib/diver_down/web/definition_enumerator.rb b/lib/diver_down/web/definition_enumerator.rb index d42ca30..3c18a8d 100644 --- a/lib/diver_down/web/definition_enumerator.rb +++ b/lib/diver_down/web/definition_enumerator.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -module Diverdown +module DiverDown class Web class DefinitionEnumerator include Enumerable - # @param store [Diverdown::Definition::Store] + # @param store [DiverDown::Definition::Store] # @param query [String] def initialize(store, title: '', source: '') @store = store diff --git a/lib/diver_down/web/definition_to_dot.rb b/lib/diver_down/web/definition_to_dot.rb index 275ff3a..e31413a 100644 --- a/lib/diver_down/web/definition_to_dot.rb +++ b/lib/diver_down/web/definition_to_dot.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -module Diverdown +module DiverDown class Web class DefinitionToDot class SourceDecorator < BasicObject attr_reader :dependencies - # @param source [Diverdown::Definition::Source] + # @param source [DiverDown::Definition::Source] def initialize(source) @source = source @dependencies = source.dependencies.map { DependencyDecorator.new(_1) } @@ -43,7 +43,7 @@ def respond_to_missing?(action, include_private = false) end class DependencyDecorator < BasicObject - # @param dependency [Diverdown::Definition::dependency] + # @param dependency [DiverDown::Definition::dependency] def initialize(dependency) @dependency = dependency end @@ -78,10 +78,10 @@ def respond_to_missing?(action, include_private = false) end end - # @param definition [Diverdown::Definition] + # @param definition [DiverDown::Definition] def initialize(definition) @definition = definition - @io = Diverdown::IndentedStringIo.new + @io = DiverDown::IndentedStringIo.new @indent = 0 end diff --git a/lib/diver_down/web/dev_server_middleware.rb b/lib/diver_down/web/dev_server_middleware.rb index 5703dc3..cd43fd4 100644 --- a/lib/diver_down/web/dev_server_middleware.rb +++ b/lib/diver_down/web/dev_server_middleware.rb @@ -4,7 +4,7 @@ require 'websocket/driver' require 'eventmachine' -module Diverdown +module DiverDown class Web # For vite class DevServerMiddleware diff --git a/package.json b/package.json index ce865e4..dfdd31e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "diverdown", + "name": "diver_down", "version": "0.1.0", "prettier": "prettier-config-smarthr", "engines": { @@ -17,7 +17,7 @@ "private": true, "repository": { "type": "git", - "url": "git://github.com/alpaca-tc/diverdown.git" + "url": "git://github.com/alpaca-tc/diver_down.git" }, "scripts": { "dev": "vite", diff --git a/spec/diver_down/definition/dependency_spec.rb b/spec/diver_down/definition/dependency_spec.rb index c6259fe..48033d0 100644 --- a/spec/diver_down/definition/dependency_spec.rb +++ b/spec/diver_down/definition/dependency_spec.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Definition::Dependency do +RSpec.describe DiverDown::Definition::Dependency do describe 'ClassMethods' do describe '.from_hash' do it 'loads hash' do dependency = described_class.new( source_name: 'a.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'A', context: 'class', paths: ['a.rb'] @@ -24,7 +24,7 @@ dependency_a = described_class.new( source_name: 'b.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'to_s', context: 'class', paths: ['a.rb'] @@ -35,17 +35,17 @@ dependency_b = described_class.new( source_name: 'b.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'to_s', context: 'class', paths: ['b.rb'] ), - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'to_i', context: 'class', paths: ['b.rb'] ), - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'to_i', context: 'instance', paths: ['c.rb'] @@ -56,7 +56,7 @@ dependency_c = described_class.new( source_name: 'c.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'to_z', context: 'class', paths: ['c.rb'] @@ -69,17 +69,17 @@ described_class.new( source_name: 'b.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'to_s', context: 'class', paths: ['a.rb', 'b.rb'] ), - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'to_i', context: 'class', paths: ['b.rb'] ), - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'to_i', context: 'instance', paths: ['c.rb'] @@ -89,7 +89,7 @@ described_class.new( source_name: 'c.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'to_z', context: 'class', paths: ['c.rb'] @@ -113,7 +113,7 @@ described_class.new( source_name: 'a.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'A', context: 'class' ), @@ -125,12 +125,12 @@ describe '#find_or_build_method_id' do it 'returns existing method_id if method_id exists' do - class_method_id = Diverdown::Definition::MethodId.new( + class_method_id = DiverDown::Definition::MethodId.new( name: 'to_s', context: 'class', paths: ['a.rb'] ) - instance_method_id = Diverdown::Definition::MethodId.new( + instance_method_id = DiverDown::Definition::MethodId.new( name: 'to_s', context: 'instance', paths: ['a.rb'] @@ -145,7 +145,7 @@ end it "returns new method_id if method_id doesn't exist" do - method_id = Diverdown::Definition::MethodId.new( + method_id = DiverDown::Definition::MethodId.new( name: 'to_s', context: 'class', paths: ['a.rb'] @@ -156,7 +156,7 @@ ) expect(dependency.find_or_build_method_id(name: 'to_i', context: 'class')).to eq( - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( context: 'class', name: 'to_i' ) @@ -166,12 +166,12 @@ describe '#method_id' do it 'returns existing method_id if method_id exists' do - class_method_id = Diverdown::Definition::MethodId.new( + class_method_id = DiverDown::Definition::MethodId.new( name: 'to_s', context: 'class', paths: ['a.rb'] ) - instance_method_id = Diverdown::Definition::MethodId.new( + instance_method_id = DiverDown::Definition::MethodId.new( name: 'to_s', context: 'instance', paths: ['a.rb'] @@ -193,7 +193,7 @@ dependency = described_class.new( source_name: 'a.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'A', context: 'class', paths: ['a.rb'] diff --git a/spec/diver_down/definition/method_id_spec.rb b/spec/diver_down/definition/method_id_spec.rb index 139c682..146dc0a 100644 --- a/spec/diver_down/definition/method_id_spec.rb +++ b/spec/diver_down/definition/method_id_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Definition::MethodId do +RSpec.describe DiverDown::Definition::MethodId do describe 'InstanceMethods' do describe '#human_method_name' do it 'returns a string' do diff --git a/spec/diver_down/definition/modulee_spec.rb b/spec/diver_down/definition/modulee_spec.rb index 65cef97..019a1b9 100644 --- a/spec/diver_down/definition/modulee_spec.rb +++ b/spec/diver_down/definition/modulee_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Definition::Modulee do +RSpec.describe DiverDown::Definition::Modulee do describe 'InstanceMethods' do describe '#hash' do it 'returns a hash' do @@ -13,13 +13,13 @@ describe '#<=>' do it 'compares with other' do array = [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'a' ), - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'b' ), - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'c' ), ].shuffle @@ -40,7 +40,7 @@ describe '#to_h' do it 'returns a hash' do - modulee = Diverdown::Definition::Modulee.new( + modulee = DiverDown::Definition::Modulee.new( module_name: 'A' ) diff --git a/spec/diver_down/definition/source_spec.rb b/spec/diver_down/definition/source_spec.rb index 510a5c2..a43eeae 100644 --- a/spec/diver_down/definition/source_spec.rb +++ b/spec/diver_down/definition/source_spec.rb @@ -1,28 +1,28 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Definition::Source do +RSpec.describe DiverDown::Definition::Source do describe 'ClassMethods' do describe '.from_hash' do it 'loads hash' do - source = Diverdown::Definition::Source.new( + source = DiverDown::Definition::Source.new( source_name: 'a.rb', dependencies: [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'b.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'A', context: 'class', paths: ['a.rb'] ), ] ), - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'c.rb' ), ], modules: [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'A' ), ] @@ -69,10 +69,10 @@ source_a = described_class.new( source_name: 'a.rb', dependencies: [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'b.rb' ), - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'c.rb' ), ] @@ -81,17 +81,17 @@ source_b = described_class.new( source_name: 'a.rb', dependencies: [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'b.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'to_s', context: 'class', paths: ['a.rb'] ), ] ), - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'd.rb' ), ] @@ -101,20 +101,20 @@ described_class.new( source_name: 'a.rb', dependencies: [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'b.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'to_s', context: 'class', paths: ['a.rb'] ), ] ), - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'c.rb' ), - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'd.rb' ), ] @@ -126,10 +126,10 @@ source_a = described_class.new( source_name: 'a.rb', modules: [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'A' ), - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'B' ), ] @@ -138,10 +138,10 @@ source_b = described_class.new( source_name: 'a.rb', modules: [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'A' ), - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'B' ), ] @@ -150,7 +150,7 @@ source_c = described_class.new( source_name: 'a.rb', modules: [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'C' ), ] @@ -171,7 +171,7 @@ expect(source.dependencies).to eq( [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'b.rb' ), ] @@ -205,10 +205,10 @@ expect(source.modules).to eq( [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'A' ), - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'B' ), ] @@ -241,10 +241,10 @@ source = described_class.new( source_name: 'a.rb', dependencies: [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'b.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'A', context: 'class', paths: ['a.rb'] @@ -253,7 +253,7 @@ ), ], modules: [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'A' ), ] diff --git a/spec/diver_down/definition_spec.rb b/spec/diver_down/definition_spec.rb index ad65337..ab9f9d3 100644 --- a/spec/diver_down/definition_spec.rb +++ b/spec/diver_down/definition_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Definition do +RSpec.describe DiverDown::Definition do describe 'ClassMethods' do describe '.from_hash' do it 'loads hash' do @@ -8,18 +8,18 @@ title: 'title', definition_group: 'x', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb', dependencies: [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'b.rb' ), - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'c.rb' ), ], modules: [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'A' ), ] @@ -36,18 +36,18 @@ definition_1 = described_class.new( title: 'title', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb', dependencies: [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'b.rb' ), - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'c.rb' ), ], modules: [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'A' ), ] @@ -58,18 +58,18 @@ definition_2 = described_class.new( title: 'title', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'd.rb', dependencies: [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'e.rb' ), - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'f.rb' ), ], modules: [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'B' ), ] @@ -126,25 +126,25 @@ title: 'title', definition_group: 'xxx', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb', dependencies: [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'b.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'A', context: 'class', paths: ['a.rb'] ), ] ), - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'c.rb' ), ], modules: [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'A' ), ] @@ -189,25 +189,25 @@ definition = described_class.new( title: 'title', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb', dependencies: [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'b.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'A', context: 'class', paths: ['a.rb'] ), ] ), - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'c.rb' ), ], modules: [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'A' ), ] @@ -222,25 +222,25 @@ definition = described_class.new( title: 'title', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb', dependencies: [ - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'b.rb', method_ids: [ - Diverdown::Definition::MethodId.new( + DiverDown::Definition::MethodId.new( name: 'A', context: 'class', paths: ['a.rb'] ), ] ), - Diverdown::Definition::Dependency.new( + DiverDown::Definition::Dependency.new( source_name: 'c.rb' ), ], modules: [ - Diverdown::Definition::Modulee.new( + DiverDown::Definition::Modulee.new( module_name: 'A' ), ] @@ -249,7 +249,7 @@ ) msgpack = definition.to_msgpack - hash = Diverdown::Helper.deep_symbolize_keys(MessagePack.unpack(msgpack)) + hash = DiverDown::Helper.deep_symbolize_keys(MessagePack.unpack(msgpack)) expect(described_class.from_hash(hash)).to eq(definition) end end diff --git a/spec/diver_down/definition_store_spec.rb b/spec/diver_down/definition_store_spec.rb index dcc0eca..7f77498 100644 --- a/spec/diver_down/definition_store_spec.rb +++ b/spec/diver_down/definition_store_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -RSpec.describe Diverdown::DefinitionStore do +RSpec.describe DiverDown::DefinitionStore do describe 'InstanceMethods' do describe '#get' do it 'raises KeyError if key not found' do store = described_class.new - definition = Diverdown::Definition.new + definition = DiverDown::Definition.new store.set(definition) expect { store.get(0) }.to raise_error(KeyError) @@ -14,7 +14,7 @@ it 'returns definition if key is found' do store = described_class.new - definition = Diverdown::Definition.new + definition = DiverDown::Definition.new ids = store.set(definition) expect(store.get(ids[0])).to eq(definition) end @@ -23,16 +23,16 @@ describe '#set' do it 'set definitions' do store = described_class.new - definition_1 = Diverdown::Definition.new(title: 'a') - definition_2 = Diverdown::Definition.new(title: 'b') - definition_3 = Diverdown::Definition.new(title: 'c') + definition_1 = DiverDown::Definition.new(title: 'a') + definition_2 = DiverDown::Definition.new(title: 'b') + definition_3 = DiverDown::Definition.new(title: 'c') ids = store.set(definition_1, definition_2, definition_3) expect(ids).to eq([1, 2, 3]) end it 'raises exception if definition already set' do store = described_class.new - definition = Diverdown::Definition.new(title: 'a') + definition = DiverDown::Definition.new(title: 'a') store.set(definition) expect { store.set(definition) }.to raise_error(ArgumentError, /Definition already set/) @@ -42,10 +42,10 @@ describe '#definition_groups' do it 'returns definition_groups' do store = described_class.new - definition_1 = Diverdown::Definition.new - definition_2 = Diverdown::Definition.new(definition_group: 'b') - definition_3 = Diverdown::Definition.new(definition_group: 'c', title: '1') - definition_4 = Diverdown::Definition.new(definition_group: 'c', title: '2') + definition_1 = DiverDown::Definition.new + definition_2 = DiverDown::Definition.new(definition_group: 'b') + definition_3 = DiverDown::Definition.new(definition_group: 'c', title: '1') + definition_4 = DiverDown::Definition.new(definition_group: 'c', title: '2') store.set(definition_1, definition_2, definition_3, definition_4) expect(store.definition_groups).to eq(['b', 'c', nil]) @@ -55,10 +55,10 @@ describe '#filter_by_definition_group' do it 'returns definitions' do store = described_class.new - definition_1 = Diverdown::Definition.new - definition_2 = Diverdown::Definition.new(definition_group: 'b') - definition_3 = Diverdown::Definition.new(definition_group: 'c', title: '1') - definition_4 = Diverdown::Definition.new(definition_group: 'c', title: '2') + definition_1 = DiverDown::Definition.new + definition_2 = DiverDown::Definition.new(definition_group: 'b') + definition_3 = DiverDown::Definition.new(definition_group: 'c', title: '1') + definition_4 = DiverDown::Definition.new(definition_group: 'c', title: '2') store.set(definition_1, definition_2, definition_3, definition_4) expect(store.filter_by_definition_group(nil)).to eq([definition_1]) @@ -70,12 +70,12 @@ describe '#get_id' do it 'raises KeyError if key not found' do store = described_class.new - expect { store.get_id(Diverdown::Definition.new) }.to raise_error(KeyError) + expect { store.get_id(DiverDown::Definition.new) }.to raise_error(KeyError) end it 'returns bit_id if definition is found' do store = described_class.new - definition = Diverdown::Definition.new + definition = DiverDown::Definition.new ids = store.set(definition) expect(store.get_id(definition)).to eq(ids[0]) end @@ -89,7 +89,7 @@ it 'returns definition if key is found' do store = described_class.new - definition = Diverdown::Definition.new + definition = DiverDown::Definition.new ids = store.set(definition) expect(store.key?(ids[0])).to be(true) end @@ -98,7 +98,7 @@ describe '#clear' do it 'clears store' do store = described_class.new - definition = Diverdown::Definition.new + definition = DiverDown::Definition.new store.set(definition) expect(store.length).to eq(1) store.clear @@ -111,7 +111,7 @@ store = described_class.new expect(store.empty?).to be(true) - definition = Diverdown::Definition.new + definition = DiverDown::Definition.new store.set(definition) expect(store.empty?).to be(false) end diff --git a/spec/diver_down/helper_spec.rb b/spec/diver_down/helper_spec.rb index ffadd75..21a8397 100644 --- a/spec/diver_down/helper_spec.rb +++ b/spec/diver_down/helper_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Helper do +RSpec.describe DiverDown::Helper do describe 'ClassMethods' do describe '.normalize_module_name' do it 'returns string given module' do diff --git a/spec/diver_down/indented_string_io_spec.rb b/spec/diver_down/indented_string_io_spec.rb index f32d767..0129d3f 100644 --- a/spec/diver_down/indented_string_io_spec.rb +++ b/spec/diver_down/indented_string_io_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Diverdown::IndentedStringIo do +RSpec.describe DiverDown::IndentedStringIo do describe 'InstanceMethods' do describe '#write' do it 'writes string' do diff --git a/spec/diver_down/trace/call_stack_spec.rb b/spec/diver_down/trace/call_stack_spec.rb index afa59f1..3361c66 100644 --- a/spec/diver_down/trace/call_stack_spec.rb +++ b/spec/diver_down/trace/call_stack_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Trace::CallStack do +RSpec.describe DiverDown::Trace::CallStack do describe 'InstanceMethods' do describe '#pop' do it 'raises error if stack is empty' do diff --git a/spec/diver_down/trace/module_set_spec.rb b/spec/diver_down/trace/module_set_spec.rb index 78ea20b..0592d35 100644 --- a/spec/diver_down/trace/module_set_spec.rb +++ b/spec/diver_down/trace/module_set_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Trace::ModuleSet do +RSpec.describe DiverDown::Trace::ModuleSet do describe 'InstanceMethods' do describe '#include?' do it 'checks module or module name' do diff --git a/spec/diver_down/trace/redefine_ruby_methods_spec.rb b/spec/diver_down/trace/redefine_ruby_methods_spec.rb index 9adf63c..8218c8c 100644 --- a/spec/diver_down/trace/redefine_ruby_methods_spec.rb +++ b/spec/diver_down/trace/redefine_ruby_methods_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Trace::RedefineRubyMethods do +RSpec.describe DiverDown::Trace::RedefineRubyMethods do describe 'ClassMethods' do describe '.redefine_c_methods' do it 'redefines c methods to ruby methods' do diff --git a/spec/diver_down/trace/tracer_spec.rb b/spec/diver_down/trace/tracer_spec.rb index a05b77b..f4aa878 100644 --- a/spec/diver_down/trace/tracer_spec.rb +++ b/spec/diver_down/trace/tracer_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Trace::Tracer do +RSpec.describe DiverDown::Trace::Tracer do describe '#initialize' do describe 'with relative path target_files' do it 'raises ArgumentError' do @@ -16,7 +16,7 @@ describe '#trace' do describe 'when tracing script' do # @param path [String] - # @return [Diverdown::Definition] + # @return [DiverDown::Definition] def trace_fixture(path, module_set: [], target_files: nil, filter_method_id_path: nil, module_finder: nil, definition_group: nil) # NOTE: Script need to define .run method script = fixture_path(path) diff --git a/spec/diver_down/web/bit_id_spec.rb b/spec/diver_down/web/bit_id_spec.rb index bd6f6b1..2f7a59c 100644 --- a/spec/diver_down/web/bit_id_spec.rb +++ b/spec/diver_down/web/bit_id_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Web::BitId do +RSpec.describe DiverDown::Web::BitId do describe 'ClassMethods' do describe '.ids_to_bit_id' do it 'returns bit_id' do diff --git a/spec/diver_down/web/definition_enumerator_spec.rb b/spec/diver_down/web/definition_enumerator_spec.rb index 4df4479..e1bf2b5 100644 --- a/spec/diver_down/web/definition_enumerator_spec.rb +++ b/spec/diver_down/web/definition_enumerator_spec.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Web::DefinitionEnumerator do +RSpec.describe DiverDown::Web::DefinitionEnumerator do describe 'InstanceMethods' do describe '#each' do it 'returns definitions sorted by definition_group' do - store = Diverdown::DefinitionStore.new - definition_1 = Diverdown::Definition.new - definition_2 = Diverdown::Definition.new(definition_group: 'b', title: 'definition_2') - definition_3 = Diverdown::Definition.new(definition_group: 'c', title: 'definition_3') - definition_4 = Diverdown::Definition.new(definition_group: 'c', title: 'definition_4') + store = DiverDown::DefinitionStore.new + definition_1 = DiverDown::Definition.new + definition_2 = DiverDown::Definition.new(definition_group: 'b', title: 'definition_2') + definition_3 = DiverDown::Definition.new(definition_group: 'c', title: 'definition_3') + definition_4 = DiverDown::Definition.new(definition_group: 'c', title: 'definition_4') ids = store.set(definition_1, definition_2, definition_3, definition_4) expect(described_class.new(store).each.to_a).to eq( @@ -37,20 +37,20 @@ def assert_query(store, title, expected) end it 'filters by title' do - store = Diverdown::DefinitionStore.new + store = DiverDown::DefinitionStore.new - definition_1 = Diverdown::Definition.new( + definition_1 = DiverDown::Definition.new( title: '01234', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb' ), ] ) - definition_2 = Diverdown::Definition.new( + definition_2 = DiverDown::Definition.new( title: '56789', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'b.rb' ), ] @@ -83,20 +83,20 @@ def assert_query(store, source, expected) end it 'filters by source' do - store = Diverdown::DefinitionStore.new + store = DiverDown::DefinitionStore.new - definition_1 = Diverdown::Definition.new( + definition_1 = DiverDown::Definition.new( title: '01234', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb' ), ] ) - definition_2 = Diverdown::Definition.new( + definition_2 = DiverDown::Definition.new( title: '56789', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'b.rb' ), ] diff --git a/spec/diver_down/web/definition_to_dot_spec.rb b/spec/diver_down/web/definition_to_dot_spec.rb index a0901cd..3ba520d 100644 --- a/spec/diver_down/web/definition_to_dot_spec.rb +++ b/spec/diver_down/web/definition_to_dot_spec.rb @@ -1,22 +1,22 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Web::DefinitionToDot do +RSpec.describe DiverDown::Web::DefinitionToDot do describe 'InstanceMethods' do describe '#to_s' do def build_definition(title: 'title', sources: []) definition_sources = sources.map do |source| dependencies = (source[:dependencies] || []).map do |dependency| - Diverdown::Definition::Dependency.new(**dependency) + DiverDown::Definition::Dependency.new(**dependency) end modules = (source[:modules] || []).map do |mod| - Diverdown::Definition::Modulee.new(**mod) + DiverDown::Definition::Modulee.new(**mod) end - Diverdown::Definition::Source.new(**source, dependencies:, modules:) + DiverDown::Definition::Source.new(**source, dependencies:, modules:) end - Diverdown::Definition.new(title:, sources: definition_sources) + DiverDown::Definition.new(title:, sources: definition_sources) end context 'when definition is blank' do diff --git a/spec/diver_down/web_spec.rb b/spec/diver_down/web_spec.rb index 3fe56a9..67c9c74 100644 --- a/spec/diver_down/web_spec.rb +++ b/spec/diver_down/web_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Diverdown::Web do +RSpec.describe DiverDown::Web do include Rack::Test::Methods def app @@ -12,17 +12,17 @@ def app end let(:store) do - Diverdown::DefinitionStore.new + DiverDown::DefinitionStore.new end describe 'GET /' do around do |example| - index_path = File.join(Diverdown::Web::WEB_DIR, 'index.html') + index_path = File.join(DiverDown::Web::WEB_DIR, 'index.html') file_exist = File.exist?(index_path) unless file_exist # index.html is generated by `pnpn run build` - FileUtils.mkdir_p(Diverdown::Web::WEB_DIR) + FileUtils.mkdir_p(DiverDown::Web::WEB_DIR) FileUtils.touch(index_path) end @@ -54,10 +54,10 @@ def app end it 'returns definition if store has one definition' do - definition = Diverdown::Definition.new( + definition = DiverDown::Definition.new( title: 'title', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb' ), ] @@ -99,18 +99,18 @@ def assert_title(title, expected_ids) end it 'filters definitions by title=value' do - definition_1 = Diverdown::Definition.new( + definition_1 = DiverDown::Definition.new( title: '01234', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb' ), ] ) - definition_2 = Diverdown::Definition.new( + definition_2 = DiverDown::Definition.new( title: '56789', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'b.rb' ), ] @@ -147,18 +147,18 @@ def assert_source(source, expected_ids) end it 'filters definitions by source=value' do - definition_1 = Diverdown::Definition.new( + definition_1 = DiverDown::Definition.new( title: '01234', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb' ), ] ) - definition_2 = Diverdown::Definition.new( + definition_2 = DiverDown::Definition.new( title: '56789', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'b.rb' ), ] @@ -192,10 +192,10 @@ def assert_source(source, expected_ids) end it 'returns definition if store has one definition' do - definition = Diverdown::Definition.new( + definition = DiverDown::Definition.new( title: 'title', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb' ), ] @@ -222,10 +222,10 @@ def assert_source(source, expected_ids) end it 'returns definition if id is found' do - definition = Diverdown::Definition.new( + definition = DiverDown::Definition.new( title: 'title', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb' ), ] @@ -240,18 +240,18 @@ def assert_source(source, expected_ids) end it 'returns combined definition' do - definition_1 = Diverdown::Definition.new( + definition_1 = DiverDown::Definition.new( title: 'title', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb' ), ] ) - definition_2 = Diverdown::Definition.new( + definition_2 = DiverDown::Definition.new( title: 'second title', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'b.rb' ), ] @@ -274,18 +274,18 @@ def assert_source(source, expected_ids) end it 'returns response if source is found' do - definition_1 = Diverdown::Definition.new( + definition_1 = DiverDown::Definition.new( title: 'title', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'a.rb' ), ] ) - definition_2 = Diverdown::Definition.new( + definition_2 = DiverDown::Definition.new( title: 'second title', sources: [ - Diverdown::Definition::Source.new( + DiverDown::Definition::Source.new( source_name: 'b.rb' ), ] diff --git a/spec/diver_down_spec.rb b/spec/diver_down_spec.rb index 4a2104a..4527ae0 100644 --- a/spec/diver_down_spec.rb +++ b/spec/diver_down_spec.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true -RSpec.describe Diverdown do +RSpec.describe DiverDown do end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e3a9ec3..bb508a2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'diverdown' -require 'diverdown-web' -require 'diverdown-trace' +require 'diver_down' +require 'diver_down-web' +require 'diver_down-trace' Dir['./spec/support/**/*.rb'].each { require(_1) }