Class: Alain::Driver

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/alain/driver.rb

Constant Summary collapse

TMPL_DIR =
Pathname(__dir__) / 'templates'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

grpc_method, namespace, snake_case

Constructor Details

#initialize(proto_file) ⇒ Driver

Returns a new instance of Driver.



12
13
14
15
16
17
# File 'lib/alain/driver.rb', line 12

def initialize(proto_file)
  @proto = Proto.parse(proto_file)
  @cargo = Cargo.new
  @package = @proto.package # required by namespace()
  @svc_code = SvcCode.new proto.service_name(:snake)
end

Instance Attribute Details

#cargoObject (readonly)

Returns the value of attribute cargo.



9
10
11
# File 'lib/alain/driver.rb', line 9

def cargo
  @cargo
end

#protoObject (readonly)

Returns the value of attribute proto.



9
10
11
# File 'lib/alain/driver.rb', line 9

def proto
  @proto
end

Instance Method Details

#generate(update_server = false, server_conf = false) ⇒ Object



19
20
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
# File 'lib/alain/driver.rb', line 19

def generate(update_server = false, server_conf = false)
  @server_conf = server_conf
  if @svc_code.exist?
    STDERR.puts 'Already exists service definition. Only update methods...'
    update_svc
  else
    update_server = true
    STDERR.puts 'No service definition yet...'
    STDERR.puts 'Generate service definition'
    parse_svc
  end
  if update_server
    STDERR.puts 'Overwrite main.rs'
    parse_erb 'main.rs'
    STDERR.puts 'Overwrite lib.rs'
    parse_erb 'lib.rs'
    STDERR.puts 'Generate build.rs'
    parse_erb 'build.rs', '', '.'
    STDERR.puts 'Generate tests/common/mod.rs'
    FileUtils.mkdir_p 'tests/common/'
    parse_erb 'mod.rs', '', 'tests/common'
    STDERR.puts 'Generate tests/integration_test.rs'
    parse_erb 'integration_test.rs', '', 'tests'
    STDERR.puts 'Update Cargo.toml'
    cargo.add_dependencies(server_conf: @server_conf)
  end
  STDERR.puts 'Done'
end