bonobot 0.0.3 → 0.0.5
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/Rakefile +3 -4
- data/lib/bonobot/engines_files.rb +35 -0
- data/lib/bonobot/local_files.rb +15 -0
- data/lib/bonobot/overloads.rb +34 -0
- data/lib/bonobot/status.rb +18 -95
- data/lib/bonobot/version.rb +1 -1
- data/lib/bonobot.rb +4 -0
- data/lib/tasks/bonobot_tasks.rake +0 -2
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06ccb8b5b500887ae4d039b56d507d9c4c3b949ebf82c0b9213f154689832354
|
4
|
+
data.tar.gz: 725a0102e557cde864e780396d2ac713ac6446059ab049a9c8acd555c9ea4e00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 108229c0e785c832dbc0cc727348b6586ca860d110bf06e8f300b3658b9774c1edc15de024e63f0877328846c682484697998db3633422ea8e95d9ee9f2f480d
|
7
|
+
data.tar.gz: 749c8b17db41e4c317dbaf5adca0ea13d770f09345e8fc787c7121c34d50c76a6f2eb357c42d4483189170e30e92f8a1d686651cf4b73151f82dffd569b0f54e
|
data/Rakefile
CHANGED
@@ -7,6 +7,7 @@ rescue LoadError
|
|
7
7
|
end
|
8
8
|
|
9
9
|
require "rdoc/task"
|
10
|
+
require "rspec/core/rake_task"
|
10
11
|
|
11
12
|
RDoc::Task.new(:rdoc) do |rdoc|
|
12
13
|
rdoc.rdoc_dir = "rdoc"
|
@@ -20,10 +21,8 @@ require "bundler/gem_tasks"
|
|
20
21
|
|
21
22
|
require "rake/testtask"
|
22
23
|
|
23
|
-
Rake::TestTask.new(:test) do |
|
24
|
-
|
25
|
-
t.pattern = "test/**/*_test.rb"
|
26
|
-
t.verbose = false
|
24
|
+
Rake::TestTask.new(:test) do |_t|
|
25
|
+
RSpec::Core::RakeTask.new(:spec)
|
27
26
|
end
|
28
27
|
|
29
28
|
task default: :test
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EnginesFiles
|
4
|
+
def self.files
|
5
|
+
@files ||= ::Rails::Engine.subclasses.each_with_object({}) do |klass, hash|
|
6
|
+
paths = Dir.glob("#{klass.instance.root}/app/**/*.{erb,rb}")
|
7
|
+
next if paths.empty?
|
8
|
+
|
9
|
+
hash[engine_to_name(klass)] = engine_paths(paths)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.engine_to_name(engine_class)
|
14
|
+
if engine_class.respond_to?(:railtie_namespace) && engine_class.railtie_namespace
|
15
|
+
engine_class.railtie_namespace.to_s.split("::").map(&:underscore).join("/")
|
16
|
+
else
|
17
|
+
engine_class.engine_name.sub("_engine", "")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.engine_paths(paths)
|
22
|
+
paths.each_with_object({}) do |path, hash|
|
23
|
+
_name, *short_path = path.sub(gems_dir, "").split("/")
|
24
|
+
hash[short_path.join("/")] = { path: path, fingerprint: fingerprint(path) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.gems_dir
|
29
|
+
@gems_dir ||= "#{Bundler.rubygems.gem_dir}/gems/"
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.fingerprint(path)
|
33
|
+
Digest::MD5.hexdigest(File.read(path))
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LocalFiles
|
4
|
+
def self.files
|
5
|
+
@files ||= Dir.glob(::Rails.root.join("app", "**", "*.{erb,rb}")).map { |path| path.sub("#{::Rails.root}/", "") }.each_with_object({}) do |path, hash|
|
6
|
+
hash[path] = read_annotation(path)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.read_annotation(path)
|
11
|
+
File.readlines(path).map do |line|
|
12
|
+
line.sub(/# bonobot_fingerprint:/, "").sub("<%", "").sub("%>", "").strip if line.match?(/# bonobot_fingerprint:/) || line.match?(/<%# bonobot_fingerprint:/)
|
13
|
+
end.compact.first.presence
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Overloads
|
4
|
+
def self.files
|
5
|
+
@files ||= LocalFiles.files.each_with_object({}) do |(path, fingerprint), hash|
|
6
|
+
EnginesFiles.files.keys.each do |engine_name|
|
7
|
+
next unless path.include? engine_name
|
8
|
+
|
9
|
+
source_path = EnginesFiles.files[engine_name].fetch(path, nil)
|
10
|
+
next unless source_path
|
11
|
+
|
12
|
+
result = [engine_name, source_path.merge(short_path: path)]
|
13
|
+
|
14
|
+
key = status_key(source_path[:fingerprint], fingerprint)
|
15
|
+
if hash[key].nil?
|
16
|
+
hash[key] = [result]
|
17
|
+
else
|
18
|
+
hash[key] << result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.status_key(source_fingerprint, target_fingerprint)
|
25
|
+
return :up_to_date if source_fingerprint == target_fingerprint
|
26
|
+
return :missing if target_fingerprint.nil?
|
27
|
+
|
28
|
+
:out_of_date
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.status(status)
|
32
|
+
files.fetch(status, [])
|
33
|
+
end
|
34
|
+
end
|
data/lib/bonobot/status.rb
CHANGED
@@ -5,119 +5,42 @@ require "json"
|
|
5
5
|
module Bonobot
|
6
6
|
class Status
|
7
7
|
def self.generate
|
8
|
-
puts "
|
8
|
+
puts "-----"
|
9
9
|
puts "🙈 🙉 🙊 Bonobot 🙈 🙉 🙊"
|
10
10
|
puts "-----"
|
11
|
-
puts "🛠 Generating status
|
12
|
-
File.write("status.json", JSON.pretty_generate({ rails_files:
|
11
|
+
puts "🛠 Generating status"
|
12
|
+
File.write("status.json", JSON.pretty_generate({ rails_files: LocalFiles.files, engines_files: EnginesFiles.files, overloads: Overloads.files }))
|
13
13
|
puts File.expand_path("status.json")
|
14
14
|
puts "-----"
|
15
15
|
|
16
|
-
unless up_to_date.empty?
|
17
|
-
puts "🥳 Up to date fingerprint count: #{up_to_date.count}"
|
18
|
-
puts "-> Up to date fingerprint: #{up_to_date}"
|
16
|
+
unless Overloads.status(:up_to_date).empty?
|
17
|
+
puts "🥳 Up to date fingerprint count: #{Overloads.status(:up_to_date).count}"
|
18
|
+
puts "-> Up to date fingerprint: #{present(Overloads.status(:up_to_date))}"
|
19
19
|
puts ""
|
20
20
|
end
|
21
21
|
|
22
|
-
unless out_of_date.empty?
|
23
|
-
puts "😱 Out of date fingerprint count: #{out_of_date.count}"
|
24
|
-
puts "-> Out of date fingerprint: #{out_of_date}"
|
22
|
+
unless Overloads.status(:out_of_date).empty?
|
23
|
+
puts "😱 Out of date fingerprint count: #{Overloads.status(:out_of_date).count}"
|
24
|
+
puts "-> Out of date fingerprint: #{present(Overloads.status(:out_of_date))}"
|
25
25
|
puts ""
|
26
26
|
end
|
27
27
|
|
28
|
-
unless missing.empty?
|
29
|
-
puts "🤬 Files missing fingerprint count: #{missing.count}"
|
30
|
-
puts "-> Missing fingerprint: #{missing}"
|
28
|
+
unless Overloads.status(:missing).empty?
|
29
|
+
puts "🤬 Files missing fingerprint count: #{Overloads.status(:missing).count}"
|
30
|
+
puts "-> Missing fingerprint: #{present(Overloads.status(:missing))}"
|
31
31
|
puts ""
|
32
32
|
end
|
33
33
|
|
34
34
|
puts "-----"
|
35
|
-
|
36
|
-
|
37
|
-
out_of_date.empty? && missing.empty?
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.out_of_date
|
41
|
-
overloads.fetch(:out_of_date, [])
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.up_to_date
|
45
|
-
overloads.fetch(:up_to_date, [])
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.missing
|
49
|
-
overloads.fetch(:missing, [])
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.overloads
|
53
|
-
@overloads ||= rails_files.each_with_object({}) do |(path, fingerprint), hash|
|
54
|
-
engines_files.keys.each do |engine_name|
|
55
|
-
next unless path.include? engine_name
|
56
|
-
|
57
|
-
source_path = engines_files[engine_name].fetch(path, nil)
|
58
|
-
next unless source_path
|
59
|
-
|
60
|
-
result = [engine_name, source_path]
|
61
|
-
|
62
|
-
key = status_key(source_path[:fingerprint], fingerprint)
|
63
|
-
if hash[key].nil?
|
64
|
-
hash[key] = [result]
|
65
|
-
else
|
66
|
-
hash[key] << result
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.rails_files
|
73
|
-
@rails_files ||= Dir.glob(Rails.root.join("app", "**", "*.{erb,rb}")).map { |path| path.sub("#{Rails.root}/", "") }.each_with_object({}) do |path, hash|
|
74
|
-
hash[path] = read_annotation(path)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.engines_files
|
79
|
-
@engine_files ||= ::Rails::Engine.subclasses.each_with_object({}) do |klass, hash|
|
80
|
-
paths = Dir.glob("#{klass.instance.root}/app/**/*.{erb,rb}")
|
81
|
-
next if paths.empty?
|
82
|
-
|
83
|
-
hash[engine_to_gem(klass)] = engine_paths(paths)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.engine_to_gem(engine_class)
|
88
|
-
if engine_class.respond_to?(:railtie_namespace) && engine_class.railtie_namespace
|
89
|
-
engine_class.railtie_namespace.to_s.split("::").map(&:underscore).join("/")
|
90
|
-
else
|
91
|
-
engine_class.engine_name.sub("_engine", "")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def self.engine_paths(paths)
|
96
|
-
paths.each_with_object({}) do |path, hash|
|
97
|
-
_name, *short_path = path.sub("#{gems_dir}/gems/", "").split("/")
|
98
|
-
hash[short_path.join("/")] = { path: path, fingerprint: fingerprint(path) }
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def self.fingerprint(path)
|
103
|
-
Digest::MD5.hexdigest(File.read(path))
|
104
|
-
end
|
105
|
-
|
106
|
-
def self.gems_dir
|
107
|
-
@gems_dir ||= Bundler.rubygems.gem_dir
|
108
|
-
end
|
109
|
-
|
110
|
-
def self.read_annotation(path)
|
111
|
-
File.readlines(path).map do |line|
|
112
|
-
line.sub(/# bonobot_fingerprint:/, "").sub("<%", "").sub("%>", "").strip if line.match?(/# bonobot_fingerprint:/) || line.match?(/<%# bonobot_fingerprint:/)
|
113
|
-
end.compact.first
|
35
|
+
Overloads.status(:out_of_date).empty? && Overloads.status(:missing).empty?
|
114
36
|
end
|
115
37
|
|
116
|
-
def self.
|
117
|
-
|
118
|
-
|
38
|
+
def self.present(entry)
|
39
|
+
entries = entry.map do |(engine_name, source_path)|
|
40
|
+
" - #{engine_name}: #{source_path[:short_path]} (#{source_path[:fingerprint]})"
|
41
|
+
end.join("\n")
|
119
42
|
|
120
|
-
|
43
|
+
"\n#{entries}"
|
121
44
|
end
|
122
45
|
end
|
123
46
|
end
|
data/lib/bonobot/version.rb
CHANGED
data/lib/bonobot.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bonobot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- armandfardeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '11.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rubocop
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: 2.11.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: Description of Bonobot.
|
84
112
|
email:
|
85
113
|
- fardeauarmand@gmail.com
|
@@ -91,6 +119,9 @@ files:
|
|
91
119
|
- README.md
|
92
120
|
- Rakefile
|
93
121
|
- lib/bonobot.rb
|
122
|
+
- lib/bonobot/engines_files.rb
|
123
|
+
- lib/bonobot/local_files.rb
|
124
|
+
- lib/bonobot/overloads.rb
|
94
125
|
- lib/bonobot/railtie.rb
|
95
126
|
- lib/bonobot/status.rb
|
96
127
|
- lib/bonobot/version.rb
|