class Supercop::Actions::Loaders::Base

Constants

BUNDLE_REQUIRED

Attributes

config[R]
file[R]
gem_name[R]
injector[R]

Public Class Methods

new(gem_name) click to toggle source
# File lib/supercop/actions/loaders/base.rb, line 9
def initialize(gem_name)
  @gem_name = gem_name
  @config = Supercop.configuration.public_send(gem_name)
  @injector = Supercop::Actions::FileInjector
  @file = Supercop.configuration.path('Gemfile')
end

Public Instance Methods

call() click to toggle source
# File lib/supercop/actions/loaders/base.rb, line 23
def call
  add_gem

  puts "'#{gem_name}' was added as dependency.\n"
  BUNDLE_REQUIRED
end
installed?() click to toggle source
# File lib/supercop/actions/loaders/base.rb, line 16
def installed?
  load_gem
  true
rescue LoadError
  false
end

Private Instance Methods

add_gem() click to toggle source
# File lib/supercop/actions/loaders/base.rb, line 36
def add_gem
  puts "Inserting into #{file} \n"
  puts "gem config #{gem_config}\n"

  injector.new(filename: file, line: gem_config).call
end
gem_config() click to toggle source
# File lib/supercop/actions/loaders/base.rb, line 43
def gem_config
  result = ["gem '#{gem_name}'"]
  result << ", #{config[:version]}" if option?(:version)
  result << ", path: '#{config[:path]}'" if option?(:path)
  result << ", git: '#{config[:git]}'" if option?(:git) && !option?(:path)
  result << "\n"
  result.join(' ')
end
load_gem() click to toggle source
# File lib/supercop/actions/loaders/base.rb, line 32
def load_gem
  require gem_name.to_s
end
option?(option) click to toggle source
# File lib/supercop/actions/loaders/base.rb, line 52
def option?(option)
  config.keys.include?(option)
end