Class: Lhj::TodoCheckHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/lhj/helper/todo_check_helper.rb

Class Method Summary collapse

Class Method Details

.check(path, type = 'm,h') ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/lhj/helper/todo_check_helper.rb', line 3

def self.check(path, type = 'm,h')
  all_files = Dir.glob("#{path}/**/*.{#{type}}").reject do |p|
    p =~ /Pods/
  end
  result = []
  all_files.each do |f|
    result << handle_file(f)
  end
  notify(result.flatten) if result.length.positive? && result.flatten.length.positive?
end

.handle_file(file) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lhj/helper/todo_check_helper.rb', line 14

def self.handle_file(file)
  result = []
  File.open(file, 'r') do |f|
    f.readlines.each_with_index do |line, idx|
      next unless line =~ %r{//} && line =~ /todo|TOdo|Todo|TODO/

      result << { file: File.basename(file), idx: idx + 1, todo: line.strip }
    end
  end
  result
end

.notify(result) ⇒ Object



30
31
32
33
34
35
# File 'lib/lhj/helper/todo_check_helper.rb', line 30

def self.notify(result)
  temp = Lhj::ErbTemplateHelper.load('todo_code_notify')
  temp_result = Lhj::ErbTemplateHelper.render(temp, { result: result }, '-')
  puts temp_result
  Lhj::Dingtalk.post_message_robot(robot_url, 'check code', temp_result)
end

.robot_urlObject



26
27
28
# File 'lib/lhj/helper/todo_check_helper.rb', line 26

def self.robot_url
  'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807'
end