Class: Tapioca::Generator
- Inherits:
-
Thor::Shell::Color
- Object
- Thor::Shell::Color
- Tapioca::Generator
- Extended by:
- T::Sig
- Defined in:
- lib/tapioca/generator.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #build_gem_rbis(gem_names) ⇒ Object
- #build_todos ⇒ Object
-
#initialize(config) ⇒ Generator
constructor
A new instance of Generator.
- #sync_rbis_with_gemfile ⇒ Object
Constructor Details
#initialize(config) ⇒ Generator
Returns a new instance of Generator.
19 20 21 22 23 24 25 26 27 |
# File 'lib/tapioca/generator.rb', line 19 def initialize(config) @config = config @bundle = T.let(nil, T.nilable(Gemfile)) @loader = T.let(nil, T.nilable(Loader)) @compiler = T.let(nil, T.nilable(Compilers::SymbolTableCompiler)) @existing_rbis = T.let(nil, T.nilable(T::Hash[String, String])) @expected_rbis = T.let(nil, T.nilable(T::Hash[String, String])) super() end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/tapioca/generator.rb', line 12 def config @config end |
Instance Method Details
#build_gem_rbis(gem_names) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tapioca/generator.rb', line 30 def build_gem_rbis(gem_names) require_gem_file gems_to_generate(gem_names) .reject { |gem| config.exclude.include?(gem.name) } .each do |gem| say("Processing '#{gem.name}' gem:", :green) indent do compile_rbi(gem) puts end end say("All operations performed in working directory.", [:green, :bold]) say("Please review changes and commit them.", [:green, :bold]) end |
#build_todos ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tapioca/generator.rb', line 48 def build_todos todos_path = config.todos_path compiler = Compilers::TodosCompiler.new name = set_color(todos_path, :yellow, :bold) say("Compiling #{name}, this may take a few seconds... ") # Clean all existing unresolved constants before regenerating the list # so Sorbet won't grab them as already resolved. File.delete(todos_path) if File.exist?(todos_path) rbi_string = compiler.compile if rbi_string.empty? say("Nothing to do", :green) return end content = String.new content << rbi_header(config.generate_command, "false") content << rbi_string content << "\n" outdir = File.dirname(todos_path) FileUtils.mkdir_p(outdir) File.write(todos_path, content) say("Done", :green) say("All unresolved constants have been written to #{name}.", [:green, :bold]) say("Please review changes and commit them.", [:green, :bold]) end |
#sync_rbis_with_gemfile ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/tapioca/generator.rb', line 80 def sync_rbis_with_gemfile anything_done = [ perform_removals, perform_additions, ].any? if anything_done say("All operations performed in working directory.", [:green, :bold]) say("Please review changes and commit them.", [:green, :bold]) else say("No operations performed, all RBIs are up-to-date.", [:green, :bold]) end puts end |