Module: RuboCop::SketchUp::ExtensionProject

Constant Summary

Constants included from Config

Config::DEFAULT_CONFIGURATION

Instance Method Summary collapse

Instance Method Details

#config_pathPathname

Returns:

  • (Pathname)


12
13
14
15
16
17
18
19
# File 'lib/rubocop/sketchup/extension_project.rb', line 12

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

#extension_directoryObject



59
60
61
# File 'lib/rubocop/sketchup/extension_project.rb', line 59

def extension_directory
  extension_root_file.dirname
end

#extension_root_fileObject



50
51
52
53
54
55
56
57
# File 'lib/rubocop/sketchup/extension_project.rb', line 50

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

#extension_root_filesObject



46
47
48
# File 'lib/rubocop/sketchup/extension_project.rb', line 46

def extension_root_files
  Dir.glob("#{source_path}/*.rb").map { |path| Pathname.new(path) }
end

#path_relative_to_source(processed_source) ⇒ Object

Parameters:

  • processed_source (RuboCop::ProcessedSource)


32
33
34
35
36
37
# File 'lib/rubocop/sketchup/extension_project.rb', line 32

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

#relative_source_pathPathname

Returns:

  • (Pathname)


22
23
24
# File 'lib/rubocop/sketchup/extension_project.rb', line 22

def relative_source_path
  Pathname.new(extension_source_path_config)
end

#root_file?(processed_source) ⇒ Boolean

Parameters:

  • processed_source (RuboCop::ProcessedSource)

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/rubocop/sketchup/extension_project.rb', line 40

def root_file?(processed_source)
  filename = path_relative_to_source(processed_source)
  filename.extname.casecmp('.rb').zero? &&
    filename.parent.to_s == '.'
end

#source_pathPathname

Returns:

  • (Pathname)


27
28
29
# File 'lib/rubocop/sketchup/extension_project.rb', line 27

def source_path
  config_path.join(relative_source_path)
end