Class: Karafka::Cli::Install
Overview
Install Karafka Cli action
Constant Summary collapse
- INSTALL_DIRS =
Directories created by default
%w[ app/consumers app/responders app/workers config lib log tmp/pids ].freeze
- INSTALL_FILES_MAP =
Where should we map proper files from templates
{ 'karafka.rb.erb' => Karafka.boot_file.basename, 'application_consumer.rb.erb' => 'app/consumers/application_consumer.rb', 'application_responder.rb.erb' => 'app/responders/application_responder.rb' }.freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#call ⇒ Object
Install all required things for Karafka application in current directory.
-
#initialize(*args) ⇒ Install
constructor
A new instance of Install.
-
#rails? ⇒ Boolean
This allows us to generate customized karafka.rb template with some tweaks specific for Rails.
Methods inherited from Base
Constructor Details
#initialize(*args) ⇒ Install
Returns a new instance of Install.
31 32 33 34 35 36 37 38 |
# File 'lib/karafka/cli/install.rb', line 31 def initialize(*args) super @rails = Bundler::LockfileParser.new( Bundler.read_file( Bundler.default_lockfile ) ).dependencies.key?('railties') end |
Instance Method Details
#call ⇒ Object
Install all required things for Karafka application in current directory
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/karafka/cli/install.rb', line 41 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? ⇒ Boolean
This allows us to generate customized karafka.rb template with some tweaks specific for Rails
61 62 63 |
# File 'lib/karafka/cli/install.rb', line 61 def rails? @rails end |