Class: Tapioca::Commands::Require
- Inherits:
-
CommandWithoutTracker
- Object
- Command
- CommandWithoutTracker
- Tapioca::Commands::Require
- Defined in:
- lib/tapioca/commands/require.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(requires_path:, sorbet_config_path:) ⇒ Require
constructor
A new instance of Require.
Methods included from Tapioca::CliHelper
#netrc_file, #rbi_formatter, #say_error
Constructor Details
#initialize(requires_path:, sorbet_config_path:) ⇒ Require
Returns a new instance of Require.
13 14 15 16 17 18 |
# File 'lib/tapioca/commands/require.rb', line 13 def initialize(requires_path:, sorbet_config_path:) @requires_path = requires_path @sorbet_config_path = sorbet_config_path super() end |
Instance Method Details
#execute ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tapioca/commands/require.rb', line 21 def execute compiler = Static::RequiresCompiler.new(@sorbet_config_path) name = set_color(@requires_path, :yellow, :bold) say("Compiling #{name}, this may take a few seconds... ") rb_string = compiler.compile if rb_string.empty? say("Nothing to do", :green) return end # Clean all existing requires before regenerating the list so we update # it with the new one found in the client code and remove the old ones. File.delete(@requires_path) if File.exist?(@requires_path) content = +"# typed: true\n" content << "# frozen_string_literal: true\n\n" content << rb_string create_file(@requires_path, content, verbose: false) say("Done", :green) say("All requires from this application have been written to #{name}.", [:green, :bold]) cmd = set_color(default_command(:gem), :yellow, :bold) say("Please review changes and commit them, then run `#{cmd}`.", [:green, :bold]) end |