Class: Twirp::ClientsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/twirp_rails/generators/twirp/clients/clients_generator.rb

Instance Method Summary collapse

Instance Method Details

#check_requirementsObject



7
8
9
10
11
# File 'lib/twirp_rails/generators/twirp/clients/clients_generator.rb', line 7

def check_requirements
  protoc.check_requirements do |msg|
    abort msg
  end
end

#generate_twirp_filesObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/twirp_rails/generators/twirp/clients/clients_generator.rb', line 26

def generate_twirp_files
  in_root do
    FileUtils.mkdir_p dst_path

    protos_mask = File.join src_path, '**/*.proto'
    proto_files = Dir.glob protos_mask

    proto_files.each do |file|
      cmd = protoc.cmd(file, false)

      `#{cmd}`

      abort "protoc failure: #{cmd}" unless $?.success?
    end
  end
end

#rm_old_twirp_filesObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/twirp_rails/generators/twirp/clients/clients_generator.rb', line 13

def rm_old_twirp_files
  return unless cfg.purge_old_twirp_code

  in_root do
    removed_files = protoc.rm_old_twirp_files

    if removed_files
      msg = "#{removed_files.size} twirp and pb files purged from #{dst_path}"
      say_status :protoc, msg, :green
    end
  end
end