bonobot 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60d190ca5c05e4d29f7622276e6f387e53b06b87de3bfed7ed31446ac28b2fd9
4
- data.tar.gz: 8a900dfeb52e73e177d02363e98ce429e0012a94f0d184048208968d9841dbbe
3
+ metadata.gz: 06ccb8b5b500887ae4d039b56d507d9c4c3b949ebf82c0b9213f154689832354
4
+ data.tar.gz: 725a0102e557cde864e780396d2ac713ac6446059ab049a9c8acd555c9ea4e00
5
5
  SHA512:
6
- metadata.gz: 5c72443158105126ae949850fcb70a588517837344c1b6cc4da90400da3e227dc44acb2bed7caf614fb64b9455739091882ae07177783b2a41aea6afbd5a9bd8
7
- data.tar.gz: 31a93680b3b218ebda245eeeb1b97717bdc92e95727042523f85ae599b559635305bc030f996525bc70c76341e12304c2fd3b1a8ff42a4eee74a331c5d1a0540
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 |t|
24
- t.libs << "test"
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
@@ -9,30 +9,30 @@ module Bonobot
9
9
  puts "🙈 🙉 🙊 Bonobot 🙈 🙉 🙊"
10
10
  puts "-----"
11
11
  puts "🛠 Generating status"
12
- File.write("status.json", JSON.pretty_generate({ rails_files: rails_files, engines_files: engines_files, overloads: overloads }))
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: #{present(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: #{present(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: #{present(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
- out_of_date.empty? && missing.empty?
35
+ Overloads.status(:out_of_date).empty? && Overloads.status(:missing).empty?
36
36
  end
37
37
 
38
38
  def self.present(entry)
@@ -42,88 +42,5 @@ module Bonobot
42
42
 
43
43
  "\n#{entries}"
44
44
  end
45
-
46
- def self.out_of_date
47
- overloads.fetch(:out_of_date, [])
48
- end
49
-
50
- def self.up_to_date
51
- overloads.fetch(:up_to_date, [])
52
- end
53
-
54
- def self.missing
55
- overloads.fetch(:missing, [])
56
- end
57
-
58
- def self.overloads
59
- @overloads ||= rails_files.each_with_object({}) do |(path, fingerprint), hash|
60
- engines_files.keys.each do |engine_name|
61
- next unless path.include? engine_name
62
-
63
- source_path = engines_files[engine_name].fetch(path, nil)
64
- next unless source_path
65
-
66
- result = [engine_name, source_path.merge(short_path: path)]
67
-
68
- key = status_key(source_path[:fingerprint], fingerprint)
69
- if hash[key].nil?
70
- hash[key] = [result]
71
- else
72
- hash[key] << result
73
- end
74
- end
75
- end
76
- end
77
-
78
- def self.rails_files
79
- @rails_files ||= Dir.glob(Rails.root.join("app", "**", "*.{erb,rb}")).map { |path| path.sub("#{Rails.root}/", "") }.each_with_object({}) do |path, hash|
80
- hash[path] = read_annotation(path)
81
- end
82
- end
83
-
84
- def self.engines_files
85
- @engine_files ||= ::Rails::Engine.subclasses.each_with_object({}) do |klass, hash|
86
- paths = Dir.glob("#{klass.instance.root}/app/**/*.{erb,rb}")
87
- next if paths.empty?
88
-
89
- hash[engine_to_gem(klass)] = engine_paths(paths)
90
- end
91
- end
92
-
93
- def self.engine_to_gem(engine_class)
94
- if engine_class.respond_to?(:railtie_namespace) && engine_class.railtie_namespace
95
- engine_class.railtie_namespace.to_s.split("::").map(&:underscore).join("/")
96
- else
97
- engine_class.engine_name.sub("_engine", "")
98
- end
99
- end
100
-
101
- def self.engine_paths(paths)
102
- paths.each_with_object({}) do |path, hash|
103
- _name, *short_path = path.sub("#{gems_dir}/gems/", "").split("/")
104
- hash[short_path.join("/")] = { path: path, fingerprint: fingerprint(path) }
105
- end
106
- end
107
-
108
- def self.fingerprint(path)
109
- Digest::MD5.hexdigest(File.read(path))
110
- end
111
-
112
- def self.gems_dir
113
- @gems_dir ||= Bundler.rubygems.gem_dir
114
- end
115
-
116
- def self.read_annotation(path)
117
- File.readlines(path).map do |line|
118
- line.sub(/# bonobot_fingerprint:/, "").sub("<%", "").sub("%>", "").strip if line.match?(/# bonobot_fingerprint:/) || line.match?(/<%# bonobot_fingerprint:/)
119
- end.compact.first
120
- end
121
-
122
- def self.status_key(source_fingerprint, target_fingerprint)
123
- return :up_to_date if source_fingerprint == target_fingerprint
124
- return :missing if target_fingerprint.nil?
125
-
126
- :out_of_date
127
- end
128
45
  end
129
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bonobot
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
data/lib/bonobot.rb CHANGED
@@ -3,4 +3,8 @@
3
3
  require "bonobot/railtie"
4
4
 
5
5
  module Bonobot
6
+ autoload :Status, "bonobot/status"
7
+ autoload :LocalFiles, "bonobot/local_files"
8
+ autoload :EnginesFiles, "bonobot/engines_files"
9
+ autoload :Overloads, "bonobot/overloads"
6
10
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bonobot/status"
4
-
5
3
  namespace :bonobot do
6
4
  desc "Generate status"
7
5
  task status: :environment do
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
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-05 00:00:00.000000000 Z
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