forked from SketchUp/rubocop-sketchup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension_project.rb
65 lines (52 loc) · 1.64 KB
/
extension_project.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true
require 'pathname'
module RuboCop
module SketchUp
module ExtensionProject
include SketchUp::Config
# @return [Pathname]
def config_path
path = config.instance_variable_get(:@loaded_path)
if path
Pathname.new(path).expand_path.dirname
else
Pathname.new(Dir.pwd).expand_path
end
end
# @return [Pathname]
def relative_source_path
Pathname.new(extension_source_path_config)
end
# @return [Pathname]
def source_path
config_path.join(relative_source_path)
end
# @param [RuboCop::ProcessedSource] processed_source
def path_relative_to_source(processed_source)
source_filename = processed_source.buffer.name
rel_path = config.path_relative_to_config(source_filename)
path = Pathname.new(rel_path).expand_path
path.relative_path_from(source_path)
end
# @param [RuboCop::ProcessedSource] processed_source
def root_file?(processed_source)
filename = path_relative_to_source(processed_source)
filename.extname.casecmp('.rb').zero? &&
filename.parent.to_s == '.'
end
def extension_root_files
Dir.glob("#{source_path}/*.rb").map { |path| Pathname.new(path) }
end
def extension_root_file
unless extension_root_files.size == 1
num_files = extension_root_files.size
raise "More than one root extension file (#{num_files})"
end
extension_root_files.first
end
def extension_directory
extension_root_file.dirname
end
end
end
end