Class: Karafka::Cli::Install
- Includes:
- Helpers::Colorize
- Defined in:
- lib/karafka/cli/install.rb
Overview
Install Karafka Cli action
Constant Summary collapse
- INSTALL_DIRS =
Directories created by default
%w[ app/consumers log ].freeze
- INSTALL_FILES_MAP =
Where should we map proper files from templates
{ 'karafka.rb.erb' => Karafka.boot_file, 'application_consumer.rb.erb' => 'app/consumers/application_consumer.rb', 'example_consumer.rb.erb' => 'app/consumers/example_consumer.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 ⇒ Install
constructor
Initializes the install command.
-
#rails? ⇒ Boolean
This allows us to generate customized karafka.rb template with some tweaks specific for Rails.
Methods included from Helpers::Colorize
Methods inherited from Base
aliases, commands, desc, load, name, names, option, parse_options
Constructor Details
#initialize ⇒ Install
Initializes the install command
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/karafka/cli/install.rb', line 28 def initialize super dependencies = Bundler::LockfileParser.new( Bundler.read_file( Bundler.default_lockfile ) ).dependencies @rails = dependencies.key?('railties') || dependencies.key?('rails') 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 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/karafka/cli/install.rb', line 41 def call INSTALL_DIRS.each do |dir| FileUtils.mkdir_p Karafka.root.join(dir) end puts puts 'Installing Karafka framework...' puts 'Ruby on Rails detected...' if rails? puts INSTALL_FILES_MAP.each do |source, target| pathed_target = Karafka.root.join(target) FileUtils.mkdir_p File.dirname(pathed_target) template = File.read(Karafka.core_root.join("templates/#{source}")) render = ERB.new(template, trim_mode: '-').result(binding) File.write(pathed_target, render) puts "#{green('Created')} #{target}" end puts puts("Installation #{green('completed')}. Have fun!") puts end |
#rails? ⇒ Boolean
This allows us to generate customized karafka.rb template with some tweaks specific for Rails
71 72 73 |
# File 'lib/karafka/cli/install.rb', line 71 def rails? @rails end |