Class: Avm::Ruby::Rubocop

Inherits:
Object show all
Defined in:
lib/avm/ruby/rubocop.rb,
lib/avm/ruby/rubocop/_envvar.rb,
lib/avm/ruby/rubocop/_gemfile.rb,
lib/avm/ruby/rubocop/_configured.rb

Constant Summary collapse

RUBOCOP_COMMAND_ENVVAR_NAME =
'RUBOCOP_COMMAND'

Instance Method Summary collapse

Instance Method Details

#configured_rubocop_command_by_commandObject



12
13
14
# File 'lib/avm/ruby/rubocop/_configured.rb', line 12

def configured_rubocop_command_by_command
  configuration.if_present(&:rubocop_command)
end

#configured_rubocop_command_by_gemfileObject



16
17
18
19
20
# File 'lib/avm/ruby/rubocop/_configured.rb', line 16

def configured_rubocop_command_by_gemfile
  configuration.if_present(&:rubocop_gemfile).if_present do |v|
    rubocop_command_by_gemfile_path(v.parent)
  end
end

#configured_rubocop_command_uncachedObject



8
9
10
# File 'lib/avm/ruby/rubocop/_configured.rb', line 8

def configured_rubocop_command_uncached
  configured_rubocop_command_by_command || configured_rubocop_command_by_gemfile
end

#env_rubocop_commandObject



11
12
13
# File 'lib/avm/ruby/rubocop/_envvar.rb', line 11

def env_rubocop_command
  ENV[RUBOCOP_COMMAND_ENVVAR_NAME].present? ? cmd(ENV[RUBOCOP_COMMAND_ENVVAR_NAME]) : nil
end

#gemfile_rubocop_commandObject



10
11
12
13
14
# File 'lib/avm/ruby/rubocop/_gemfile.rb', line 10

def gemfile_rubocop_command
  return nil unless rubocop_gemfile?

  rubocop_command_by_gemfile_path(mygem.root)
end

#rubocop_command_by_gemfile_path(path) ⇒ Object



16
17
18
# File 'lib/avm/ruby/rubocop/_gemfile.rb', line 16

def rubocop_command_by_gemfile_path(path)
  ::EacRubyGemsUtils::Gem.new(path).bundle('exec', 'rubocop').chdir_root
end

#rubocop_gemfile?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/avm/ruby/rubocop/_gemfile.rb', line 20

def rubocop_gemfile?
  return false if mygem.blank?

  mygem.bundle('install').execute!
  mygem.gemfile_lock_gem_version('rubocop').present?
end

#runObject



17
18
19
20
# File 'lib/avm/ruby/rubocop.rb', line 17

def run
  start_banner
  run_rubocop
end