class Karafka::Cli::Install
Constants
- INSTALL_DIRS
Directories created by default
- INSTALL_FILES_MAP
Where should we map proper files from templates
Public Class Methods
new(*args)
click to toggle source
@param args [Array] all the things that Thor CLI accepts
Calls superclass method
Karafka::Cli::Base::new
# File lib/karafka/cli/install.rb, line 31 def initialize(*args) super dependencies = Bundler::LockfileParser.new( Bundler.read_file( Bundler.default_lockfile ) ).dependencies @rails = dependencies.key?('railties') || dependencies.key?('rails') end
Public Instance Methods
call()
click to toggle source
Install
all required things for Karafka
application in current directory
# File lib/karafka/cli/install.rb, line 42 def call INSTALL_DIRS.each do |dir| FileUtils.mkdir_p Karafka.root.join(dir) end INSTALL_FILES_MAP.each do |source, target| target = Karafka.root.join(target) template = File.read(Karafka.core_root.join("templates/#{source}")) # @todo Replace with the keyword argument version once we don't have to support # Ruby < 2.6 render = ::ERB.new(template, nil, '-').result(binding) File.open(target, 'w') { |file| file.write(render) } end end
rails?()
click to toggle source
@return [Boolean] true if we have Rails loaded This allows us to generate customized karafka.rb template with some tweaks specific for Rails
# File lib/karafka/cli/install.rb, line 62 def rails? @rails end