Class: Necropsy::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/necropsy/project.rb

Constant Summary collapse

EXCLUDED_DIRECTORIES =
%w[
  .bundle
  .git
  .serena
  coverage
  doc
  node_modules
  pkg
  tmp
  vendor
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, config:) ⇒ Project

Returns a new instance of Project.



21
22
23
24
# File 'lib/necropsy/project.rb', line 21

def initialize(root:, config:)
  @root = File.expand_path(root)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



19
20
21
# File 'lib/necropsy/project.rb', line 19

def config
  @config
end

#rootObject (readonly)

Returns the value of attribute root.



19
20
21
# File 'lib/necropsy/project.rb', line 19

def root
  @root
end

Instance Method Details

#changed_files(diff_base) ⇒ Object



52
53
54
# File 'lib/necropsy/project.rb', line 52

def changed_files(diff_base)
  Guardrail::Diff.changed_files(root: root, diff_base: diff_base)
end

#relative_path(file) ⇒ Object



48
49
50
# File 'lib/necropsy/project.rb', line 48

def relative_path(file)
  Pathname.new(File.expand_path(file)).relative_path_from(Pathname.new(root)).to_s
end

#ruby_filesObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/necropsy/project.rb', line 32

def ruby_files
  @ruby_files ||= begin
    globbed = Dir.glob(File.join(root, '**', '*.rb'))
    special = %w[Rakefile].map { |name| File.join(root, name) }.select { |file| File.file?(file) }
    rake = Dir.glob(File.join(root, '**', '*.rake'))
    executables = Dir.glob(File.join(root, '{bin,exe}', '*')).select { |file| File.file?(file) }
    gemspecs = Dir.glob(File.join(root, '*.gemspec'))
    (globbed + special + rake + executables + gemspecs).uniq.select { |file| analyzable_file?(file) }.sort
  end
end

#scan_resultObject



26
27
28
29
30
# File 'lib/necropsy/project.rb', line 26

def scan_result
  @scan_result ||= Cache::ScanCache.new(project: self).fetch(ruby_files) do
    AstScanner.new(project: self, files: ruby_files).scan
  end
end

#test_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/necropsy/project.rb', line 43

def test_file?(file)
  relative = relative_path(file)
  relative.start_with?('spec/', 'test/')
end