bonobot 0.0.6 → 0.0.7

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: c6014e196b254d2d08a4b6054cd1aba997d2fb9158ebe26cfbb897b1c29ef81c
4
- data.tar.gz: 829215850c62ecb9409838362a463f6518120bc9f3209ea6ab059967c5c9b0b6
3
+ metadata.gz: 043e3c7bff916ce8127eb9e341d98f1749cd309fb76c0cabd279c3e0dc05c720
4
+ data.tar.gz: cc48089c16b0a0a6848b003206746b00afa45976c155845084c209d11ba03e6e
5
5
  SHA512:
6
- metadata.gz: 451b94f8a0cffe4d1f05c7913055fa8446caaf3865d504dfd83f749e5e20413ea959db56e6ae4d1d9a066bc684cae5496bf7ca1d4e40ea4bd0f55db98226781b
7
- data.tar.gz: 8401521e0421b536e30ef41683463d31544f1a9534461f90c7dc7a25b280a88053d0dddad1b4a09639dddeba2d9567aff9323a8d01035bee9c7650b043c56d66
6
+ metadata.gz: ceaaab01aa8335bcf7b74cdea321e3f13c50b2cd1f69ac8fedebce56aa136b4da4957ac2a17da2d9def1f0c2227902d0fc39a9cad6a9ebfb3bc4d99a1e58e58d
7
+ data.tar.gz: 81e78cd4498b5eb12bbcdaeea95149adf7f4e5b0d95c3ec2ab518595b992f3c311100a3db4612ca555796263ab2833b1a8c0af28e3c5aa7254cfb190a00c9b68
data/README.md CHANGED
@@ -5,30 +5,39 @@
5
5
  BonoBot is a Ruby gem that helps with Rails monkey patching.
6
6
 
7
7
  ## Usage
8
-
8
+ ### Status
9
+ #### Generate all status:
9
10
  ```bash
10
11
  bundle exec rake bonobot: status
11
12
  ```
13
+ #### Generate a specific status:
14
+ ```bash
15
+ bundle exec rake bonobot:status:out_of_date
16
+ bundle exec rake bonobot:status:up_to_date
17
+ bundle exec rake bonobot:update_out_of_date
18
+ ```
12
19
 
13
- ## Installation
20
+ ### Add missing
21
+ ```bash
22
+ bundle exec rake bonobot:add_missing
23
+ ```
14
24
 
25
+ ### Update out of date
26
+ ```bash
27
+ bundle exec rake bonobot:update_out_of_date
28
+ ```
29
+
30
+ ## Installation
15
31
  Add this line to your application's Gemfile:
16
32
 
17
33
  ```ruby
18
34
  gem 'bonobot'
19
35
  ```
20
36
 
21
- And then execute:
22
-
23
- ```bash
24
- bundle exec rake bonobot:status
25
- ```
26
-
27
37
  Or install it yourself as:
28
38
 
29
39
  ```bash
30
40
  gem install bonobot
31
- bundle exec rake bonobot:status
32
41
  ```
33
42
 
34
43
  ## Contributing
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bonobot
4
+ class Annotator
5
+ def self.add_annotation(path, fingerprint)
6
+ new(path, fingerprint).add_annotation
7
+ end
8
+
9
+ def self.update_annotation(path, fingerprint)
10
+ new(path, fingerprint).update_annotation
11
+ end
12
+
13
+ def initialize(path, fingerprint)
14
+ @path = path
15
+ @fingerprint = fingerprint
16
+ end
17
+
18
+ def add_annotation
19
+ f = File.read(@path).split("\n")
20
+
21
+ if f.first == "# frozen_string_literal: true"
22
+ f.insert(1, "\n#{annotation}")
23
+ else
24
+ f.insert(0, "\n#{annotation}")
25
+ end
26
+
27
+ File.write(@path, "#{f.join("\n")}\n")
28
+ end
29
+
30
+ def update_annotation
31
+ f = File.read(@path).split("\n")
32
+
33
+ f.each_with_index do |line, index|
34
+ f[index] = annotation if match_line(line)
35
+ end
36
+
37
+ File.write(@path, "#{f.join("\n")}\n")
38
+ end
39
+
40
+ def annotation
41
+ if @path.to_s.end_with?(".erb")
42
+ "<%# bonobot_fingerprint: #{@fingerprint} %>"
43
+ else
44
+ "# bonobot_fingerprint: #{@fingerprint}"
45
+ end
46
+ end
47
+
48
+ def match_line(line)
49
+ line.include?("# bonobot_fingerprint") || line.include?("<%# bonobot_fingerprint")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bonobot/overloads_registry"
4
+ require "bonobot/annotator"
5
+
6
+ module Bonobot
7
+ class FilesOp
8
+ def self.missing
9
+ OverloadsRegistry.find_by(status: :missing)
10
+ end
11
+
12
+ def self.out_of_date
13
+ OverloadsRegistry.find_by(status: :out_of_date)
14
+ end
15
+
16
+ def self.add_missing
17
+ missing.each do |overload|
18
+ Annotator.annotate(root.join(overload.path), overload.engine_file.fingerprint)
19
+ end
20
+ end
21
+
22
+ def self.update_out_of_date
23
+ out_of_date.each do |overload|
24
+ Annotator.update_annotation(root.join(overload.path), overload.engine_file.fingerprint)
25
+ end
26
+ end
27
+
28
+ def self.root
29
+ ::Rails.root
30
+ end
31
+ end
32
+ end
@@ -6,7 +6,7 @@ module Bonobot
6
6
  class Status
7
7
  STATUS = { up_to_date: "🥳", out_of_date: "😱", missing: "🤬" }.freeze
8
8
 
9
- def self.generate
9
+ def self.generate(status = nil)
10
10
  puts "-----"
11
11
  puts "🙈 🙉 🙊 Bonobot 🙈 🙉 🙊"
12
12
  puts "-----"
@@ -15,8 +15,12 @@ module Bonobot
15
15
  puts File.expand_path("status.json")
16
16
  puts "-----"
17
17
 
18
- STATUS.each do |status, emoji|
19
- generate_status(status, emoji)
18
+ if status
19
+ generate_status(status.to_sym, STATUS[status.to_sym])
20
+ else
21
+ STATUS.each do |status_type, emoji|
22
+ generate_status(status_type, emoji)
23
+ end
20
24
  end
21
25
 
22
26
  puts "-----"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bonobot
4
- VERSION = "0.0.6"
4
+ VERSION = "0.0.7"
5
5
  end
data/lib/bonobot.rb CHANGED
@@ -10,4 +10,6 @@ module Bonobot
10
10
  autoload :EngineFile, "bonobot/engine_file"
11
11
  autoload :OverloadsRegistry, "bonobot/overloads_registry"
12
12
  autoload :Overload, "bonobot/overload"
13
+ autoload :FilesOp, "bonobot/files_op"
14
+ autoload :Annotator, "bonobot/annotator"
13
15
  end
@@ -6,4 +6,38 @@ namespace :bonobot do
6
6
  status = Bonobot::Status.generate
7
7
  exit 1 unless status
8
8
  end
9
+
10
+ namespace :status do
11
+ desc "Generate status for out of date"
12
+ task out_of_date: :environment do
13
+ Bonobot::Status.generate(:out_of_date)
14
+ end
15
+
16
+ task outdated: :out_of_date
17
+
18
+ desc "Generate status for missing"
19
+ task missing: :environment do
20
+ Bonobot::Status.generate(:missing)
21
+ end
22
+
23
+ desc "Generate status for up to date"
24
+ task up_to_date: :environment do
25
+ Bonobot::Status.generate(:up_to_date)
26
+ end
27
+
28
+ task uptodate: :up_to_date
29
+ end
30
+
31
+ desc "Add missing fingerprint to local files"
32
+ task add_missing: :environment do
33
+ Bonobot::FilesOp.add_missing
34
+ end
35
+
36
+ desc "Update out of date fingerprint to local files"
37
+ task update_out_of_date: :environment do
38
+ Bonobot::FilesOp.update_out_of_date
39
+ end
40
+
41
+ task update_outdated: :update_out_of_date
42
+ task update: :update_out_of_date
9
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bonobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - armandfardeau
@@ -161,8 +161,10 @@ files:
161
161
  - README.md
162
162
  - Rakefile
163
163
  - lib/bonobot.rb
164
+ - lib/bonobot/annotator.rb
164
165
  - lib/bonobot/engine_file.rb
165
166
  - lib/bonobot/engines_files_registry.rb
167
+ - lib/bonobot/files_op.rb
166
168
  - lib/bonobot/local_file.rb
167
169
  - lib/bonobot/local_files_registry.rb
168
170
  - lib/bonobot/overload.rb