calcifer 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +9 -1
- data/calcifer.gemspec +4 -0
- data/lib/calcifer/builders/root_file_builder.rb +18 -0
- data/lib/calcifer/finders/file_related_finder.rb +23 -0
- data/lib/calcifer/finders/{modules_finder.rb → module_name_finder.rb} +10 -16
- data/lib/calcifer/finders/spec_files_related_finder.rb +6 -12
- data/lib/calcifer/graph/root_file.rb +31 -0
- data/lib/calcifer/version.rb +1 -1
- data/lib/calcifer.rb +13 -7
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a959bb4f96beb91315e7571c4e0b6c6d40e6c9225f545d063b9fc2f3ed926d9a
|
4
|
+
data.tar.gz: 54a53e3d1dcb91bcbd20aac7ffe794d4b22867508a76d66e3066afb16b057321
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b522e099b19572387281ae0d987adcd796e98e3cc47e88115e2a06437a6a1d6bdf9dddd8462a81876f241c1b2a762d656138c35c31b564eff1bbfef40fe6639c
|
7
|
+
data.tar.gz: f98d7b8431f5ef378950ddddff0323abb846d7951b7ac68f875516e5e1307d7a3eeeadcf8f00eae9ac4b4d70aa7b28694496d67d8ea055f4214feaad31644e61
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
calcifer (0.
|
4
|
+
calcifer (0.2.1)
|
5
|
+
rgl
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
9
10
|
diff-lcs (1.5.0)
|
11
|
+
generator (0.0.1)
|
12
|
+
lazy_priority_queue (0.1.1)
|
10
13
|
rake (10.5.0)
|
14
|
+
rgl (0.5.7)
|
15
|
+
lazy_priority_queue (~> 0.1.0)
|
16
|
+
stream (~> 0.5.3)
|
11
17
|
rspec (3.10.0)
|
12
18
|
rspec-core (~> 3.10.0)
|
13
19
|
rspec-expectations (~> 3.10.0)
|
@@ -21,6 +27,8 @@ GEM
|
|
21
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
28
|
rspec-support (~> 3.10.0)
|
23
29
|
rspec-support (3.10.3)
|
30
|
+
stream (0.5.3)
|
31
|
+
generator
|
24
32
|
|
25
33
|
PLATFORMS
|
26
34
|
ruby
|
data/calcifer.gemspec
CHANGED
@@ -14,6 +14,8 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "https://github.com/GustavoDuarteM/calcifer"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
+
spec.required_ruby_version = '>= 2.6.4'
|
18
|
+
|
17
19
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
20
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
21
|
if spec.respond_to?(:metadata)
|
@@ -37,6 +39,8 @@ Gem::Specification.new do |spec|
|
|
37
39
|
spec.executables = ['calcifer']
|
38
40
|
spec.require_paths = ["lib"]
|
39
41
|
|
42
|
+
spec.add_dependency 'rgl'
|
43
|
+
|
40
44
|
spec.add_development_dependency "bundler", "~> 1.17"
|
41
45
|
spec.add_development_dependency "rake", "~> 10.0"
|
42
46
|
spec.add_development_dependency "rspec", "~> 3.0"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Calcifer
|
4
|
+
module Buiders
|
5
|
+
class RootFileBuilder
|
6
|
+
def initialize(file)
|
7
|
+
@file = file
|
8
|
+
end
|
9
|
+
|
10
|
+
def build
|
11
|
+
return unless @file
|
12
|
+
|
13
|
+
module_name = Calcifer::Finders::ModuleNameFinder.new(@file).execute
|
14
|
+
Calcifer::Graph::RootFile.new(module_name, @file) if module_name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Calcifer
|
4
|
+
module Finders
|
5
|
+
class FileRelatedFinder
|
6
|
+
attr_reader :related_spec_files
|
7
|
+
|
8
|
+
def initialize(module_name)
|
9
|
+
@module_name = module_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute
|
13
|
+
related_files_path.split
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def related_files_path
|
19
|
+
`grep -Rlw '#{@module_names}' ./app`
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -2,30 +2,23 @@
|
|
2
2
|
|
3
3
|
module Calcifer
|
4
4
|
module Finders
|
5
|
-
class
|
5
|
+
class ModuleNameFinder
|
6
6
|
MODULE_REGEX = /^(module)\s\w+/.freeze
|
7
7
|
CLASS_REGEX = /^(class)\s\w+/.freeze
|
8
|
+
ONE_LINE_CLASS_REGEX = /^(class)\s\w+\s<\s\w+;\s(end)/.freeze
|
8
9
|
attr_reader :modules
|
9
10
|
|
10
|
-
def initialize(
|
11
|
-
@
|
12
|
-
@modules = []
|
11
|
+
def initialize(file)
|
12
|
+
@file = file
|
13
13
|
end
|
14
14
|
|
15
15
|
def execute
|
16
|
-
|
17
|
-
module_name = build_module_name(file)
|
18
|
-
@modules << module_name if module_name.length.positive?
|
19
|
-
end
|
20
|
-
@modules
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
16
|
+
return unless @file
|
24
17
|
|
25
|
-
def build_module_name(file)
|
26
|
-
# TODO add clause to one line defnition as "class Error < StandardError; end"
|
27
18
|
module_name = ''
|
28
|
-
file.readlines.each do |line|
|
19
|
+
@file.readlines.each do |line|
|
20
|
+
next if line.strip.match(ONE_LINE_CLASS_REGEX)&.length&.positive?
|
21
|
+
|
29
22
|
if line.strip.match(MODULE_REGEX)&.length&.positive?
|
30
23
|
module_name += "#{line.gsub('module', '').strip}::"
|
31
24
|
elsif line.strip.match(CLASS_REGEX)&.length&.positive?
|
@@ -33,7 +26,8 @@ module Calcifer
|
|
33
26
|
break
|
34
27
|
end
|
35
28
|
end
|
36
|
-
|
29
|
+
|
30
|
+
module_name.length.positive? ? module_name : nil
|
37
31
|
end
|
38
32
|
end
|
39
33
|
end
|
@@ -5,25 +5,19 @@ module Calcifer
|
|
5
5
|
class SpecFilesRelatedFinder
|
6
6
|
attr_reader :related_spec_files
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(related_files_path)
|
9
|
+
@related_files_path = related_files_path
|
10
10
|
end
|
11
11
|
|
12
12
|
def execute
|
13
13
|
@related_spec_files = specs_to_related_files.join(' ').strip
|
14
14
|
end
|
15
15
|
|
16
|
-
private
|
17
|
-
|
18
|
-
def related_files_path
|
19
|
-
module_names = @modules.join('\\|')
|
20
|
-
`grep -Rlw '#{module_names}' ./app`
|
21
|
-
end
|
22
|
-
|
23
16
|
def specs_to_related_files
|
24
|
-
related_files_path.
|
25
|
-
file_path.gsub('./app', './spec').gsub('.rb', '_spec.rb')
|
26
|
-
|
17
|
+
@related_files_path.map(&lambda { |file_path|
|
18
|
+
spec_file_path = file_path.gsub('./app', './spec').gsub('.rb', '_spec.rb')
|
19
|
+
File.file?(spec_file_path) ? spec_file_path : nil
|
20
|
+
}).compact
|
27
21
|
end
|
28
22
|
end
|
29
23
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Calcifer
|
4
|
+
module Graph
|
5
|
+
class RootFile
|
6
|
+
attr :graph_root, :module_name, :file_path
|
7
|
+
|
8
|
+
def initialize(module_name, file)
|
9
|
+
@module_name = module_name
|
10
|
+
@file = file
|
11
|
+
@file_path = file.path
|
12
|
+
build_graph_root
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_related_file_path(file_path)
|
16
|
+
@graph_root.add_edge(@file.path, file_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def related_files_paths
|
20
|
+
@graph_root.vertices - [@file.path]
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def build_graph_root
|
26
|
+
@graph_root = RGL::DirectedAdjacencyGraph.new
|
27
|
+
@graph_root.add_vertex(@file.path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/calcifer/version.rb
CHANGED
data/lib/calcifer.rb
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require '
|
5
|
-
require 'calcifer/finders/files_diff_finder'
|
6
|
-
require 'calcifer/finders/spec_files_related_finder'
|
3
|
+
Dir["#{File.dirname(__FILE__)}/calcifer/**/*.rb"].sort.each { |file| require file }
|
4
|
+
require 'rgl/adjacency'
|
7
5
|
|
8
6
|
module Calcifer
|
9
7
|
class Error < StandardError; end
|
10
8
|
|
11
9
|
def self.execute
|
12
10
|
file_list = Calcifer::Finders::FilesDiffFinder.new.execute
|
13
|
-
|
14
|
-
spec_files_path_list = Calcifer::Finders::SpecFilesRelatedFinder.new(module_list).execute
|
11
|
+
graph_list_file = file_list.map(&->(file) { Calcifer::Buiders::RootFileBuilder.new(file).build }).compact
|
15
12
|
|
16
|
-
|
13
|
+
graph_list_file.each do |graph|
|
14
|
+
related_files = Calcifer::Finders::FileRelatedFinder.new(graph.module_name).execute
|
15
|
+
graph_vertices = related_files.map { |related_file| [graph.file_path, related_file] }
|
16
|
+
graph.graph_root.add_edges(*graph_vertices)
|
17
|
+
end
|
18
|
+
|
19
|
+
spec_files_path = graph_list_file.map(&:related_files_paths).flatten
|
20
|
+
spec_files_path_list = Calcifer::Finders::SpecFilesRelatedFinder.new(spec_files_path).execute
|
21
|
+
|
22
|
+
printf `echo #{spec_files_path_list}`
|
17
23
|
end
|
18
24
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calcifer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo Duarte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rgl
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,9 +88,12 @@ files:
|
|
74
88
|
- bin/setup
|
75
89
|
- calcifer.gemspec
|
76
90
|
- lib/calcifer.rb
|
91
|
+
- lib/calcifer/builders/root_file_builder.rb
|
92
|
+
- lib/calcifer/finders/file_related_finder.rb
|
77
93
|
- lib/calcifer/finders/files_diff_finder.rb
|
78
|
-
- lib/calcifer/finders/
|
94
|
+
- lib/calcifer/finders/module_name_finder.rb
|
79
95
|
- lib/calcifer/finders/spec_files_related_finder.rb
|
96
|
+
- lib/calcifer/graph/root_file.rb
|
80
97
|
- lib/calcifer/version.rb
|
81
98
|
homepage: https://github.com/GustavoDuarteM/calcifer
|
82
99
|
licenses:
|
@@ -92,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
109
|
requirements:
|
93
110
|
- - ">="
|
94
111
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
112
|
+
version: 2.6.4
|
96
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
114
|
requirements:
|
98
115
|
- - ">="
|