Module: Rubocop::Custom

Defined in:
lib/rubocop/custom/inject.rb

Class Method Summary collapse

Class Method Details

.cwd_is_root?(cwd) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/rubocop/custom/inject.rb', line 27

def self.cwd_is_root?(cwd)
  %w(Gemfile app).collect do |match|
    File.exist?(File.join(cwd, match))
  end.all?
end

.inject!Object



3
4
5
6
7
8
9
10
11
# File 'lib/rubocop/custom/inject.rb', line 3

def self.inject!
  root = Rubocop::Custom.project_root
  return if root.nil?
  ['spec/cops', 'cops', 'app/cops'].each do |subpath|
    Dir.glob(File.join(root, subpath, '*.rb')).each do |file|
      require file
    end
  end
end

.project_rootObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rubocop/custom/inject.rb', line 13

def self.project_root
  cwd = Dir.pwd
  depth = 10
  while depth > 0
    if Rubocop::Custom.cwd_is_root?(cwd)
      return cwd
    else
      depth -= 1
      cwd = File.expand_path('..', cwd)
    end
  end
  nil
end