Class: Avm::Ruby::Rubocop

Inherits:
Object
  • 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
15
16
17
18
19
20
21
22
# File 'lib/avm/ruby/rubocop/_configured.rb', line 12

def configured_rubocop_command_by_command
  rubocop_command = configuration.if_present { |v| v.read_entry('ruby.rubocop.command') }
  return nil unless rubocop_command.present?

  args = if rubocop_command.is_a?(::Enumerable)
           rubocop_command.map(&:to_s)
         else
           ::Shellwords.split(rubocop_command)
         end
  cmd(args).chdir(::File.dirname(configuration.storage_path))
end

#configured_rubocop_command_by_gemfileObject



24
25
26
27
28
29
30
31
32
# File 'lib/avm/ruby/rubocop/_configured.rb', line 24

def configured_rubocop_command_by_gemfile
  gemfile_path = configuration.if_present { |v| v.read_entry('ruby.rubocop.gemfile') }
  return nil unless gemfile_path.present?

  gemfile_path = ::Pathname.new(gemfile_path).expand_path(configuration.storage_path.parent)
  raise "Gemfile path \"#{gemfile_path}\" does not exist" unless gemfile_path.exist?

  rubocop_command_by_gemfile_path(gemfile_path.parent)
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')
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 unless mygem.present?

  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