Class: WsdlMapper::SvcGeneration::SvcGenerator

Inherits:
Generation::Base show all
Includes:
Generation
Defined in:
lib/wsdl_mapper/svc_generation/svc_generator.rb

Direct Known Subclasses

DocumentedSvcGenerator

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Generation::Base

#append_file_for, #file, #file_for, #generate_name, #get_module_names, #type_file_for

Constructor Details

- (SvcGenerator) initialize(context, formatter_factory: DefaultFormatter, service_namer: WsdlMapper::Naming::DefaultServiceNamer.new, namer: WsdlMapper::Naming::DefaultNamer.new, service_generator_factory: ServiceGenerator, port_generator_factory: PortGenerator, proxy_generator_factory: ProxyGenerator, operation_generator_factory: OperationGenerator, operation_s8r_generator_factory: OperationS8rGenerator, operation_d10r_generator_factory: OperationD10rGenerator, schema_generator: nil)

Returns a new instance of SvcGenerator



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 29

def initialize(context,
  formatter_factory: DefaultFormatter,
  service_namer: WsdlMapper::Naming::DefaultServiceNamer.new,
  namer: WsdlMapper::Naming::DefaultNamer.new,
  service_generator_factory: ServiceGenerator,
  port_generator_factory: PortGenerator,
  proxy_generator_factory: ProxyGenerator,
  operation_generator_factory: OperationGenerator,
  operation_s8r_generator_factory: OperationS8rGenerator,
  operation_d10r_generator_factory: OperationD10rGenerator,
  schema_generator: nil)

  super(context)

  @formatter_factory = formatter_factory
  @service_namer = service_namer
  @namer = namer
  @service_generator = service_generator_factory.new(self)
  @port_generator = port_generator_factory.new(self)
  @proxy_generator = proxy_generator_factory.new(self)
  @operation_generator = operation_generator_factory.new(self)
  @operation_s8r_generator = operation_s8r_generator_factory.new(self)
  @operation_d10r_generator = operation_d10r_generator_factory.new(self)
  @schema_generator = schema_generator || WsdlMapper::DomGeneration::SchemaGenerator.new(context,
    ctr_generator_factory: WsdlMapper::DomGeneration::DefaultCtrGenerator,
    namer: namer
  )
end

Instance Attribute Details

- (Object) context (readonly)

Returns the value of attribute context



27
28
29
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 27

def context
  @context
end

- (Object) namer (readonly)

Returns the value of attribute namer



27
28
29
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 27

def namer
  @namer
end

- (Object) operation_d10r_generator (readonly)

Returns the value of attribute operation_d10r_generator



27
28
29
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 27

def operation_d10r_generator
  @operation_d10r_generator
end

- (Object) operation_generator (readonly)

Returns the value of attribute operation_generator



27
28
29
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 27

def operation_generator
  @operation_generator
end

- (Object) operation_s8r_generator (readonly)

Returns the value of attribute operation_s8r_generator



27
28
29
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 27

def operation_s8r_generator
  @operation_s8r_generator
end

- (Object) port_generator (readonly)

Returns the value of attribute port_generator



27
28
29
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 27

def port_generator
  @port_generator
end

- (Object) proxy_generator (readonly)

Returns the value of attribute proxy_generator



27
28
29
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 27

def proxy_generator
  @proxy_generator
end

- (Object) schema_generator (readonly)

Returns the value of attribute schema_generator



27
28
29
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 27

def schema_generator
  @schema_generator
end

- (Object) service_generator (readonly)

Returns the value of attribute service_generator



27
28
29
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 27

def service_generator
  @service_generator
end

- (Object) service_namer (readonly)

Returns the value of attribute service_namer



27
28
29
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 27

def service_namer
  @service_namer
end

Instance Method Details

- (Object) api_base



123
124
125
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 123

def api_base
  @api_base ||= runtime_base 'Api', 'api'
end

- (Object) body_base



147
148
149
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 147

def body_base
  @body_base ||= runtime_base 'Body', 'body'
end

- (Object) generate(desc)



58
59
60
61
62
63
64
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 58

def generate(desc)
  result = Result.new description: desc

  generate_api desc, result

  result
end

- (Object) generate_api(desc, result)



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 70

def generate_api(desc, result)
  name = @service_namer.get_api_name
  modules = get_module_names name
  services = desc.each_service.map do |service|
    TypeToGenerate.new service, @service_namer.get_service_name(service), @service_namer.get_property_name(service)
  end

  services.each do |service|
    @service_generator.generate_service service, result
  end

  type_file_for name, result do |f|
    f.requires api_base.require_path
    f.requires *services.map { |s| s.name.require_path }

    f.in_modules modules do
      generate_api_class f, name, services
    end
  end
end

- (Object) generate_api_class(f, name, services)



91
92
93
94
95
96
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 91

def generate_api_class(f, name, services)
  f.in_sub_class name.class_name, api_base.name do
    generate_api_service_accessors f, services
    generate_api_ctr f, services
  end
end

- (Object) generate_api_ctr(f, services)



102
103
104
105
106
107
108
109
110
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 102

def generate_api_ctr(f, services)
  f.in_def :initialize, 'backend' do
    f.call :super, 'backend'
    services.each do |s|
      f.assignment s.property_name.var_name, "#{s.name.name}.new(self)"
      f.statement "@_services << #{s.property_name.var_name}"
    end
  end
end

- (Object) generate_api_service_accessors(f, services)



98
99
100
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 98

def generate_api_service_accessors(f, services)
  f.attr_readers *services.map { |s| s.property_name.attr_name }
end

- (Object) get_formatter(io)



66
67
68
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 66

def get_formatter(io)
  @formatter_factory.new io
end

- (Object) get_ruby_type_name(type)



167
168
169
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 167

def get_ruby_type_name(type)
  @schema_generator.get_ruby_type_name type
end

- (Object) get_type_name(type)



163
164
165
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 163

def get_type_name(type)
  @schema_generator.get_type_name type
end

- (Object) header_base



143
144
145
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 143

def header_base
  @header_base ||= runtime_base 'Header', 'header'
end

- (Object) in_classes(f, *names, &block)



112
113
114
115
116
117
118
119
120
121
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 112

def in_classes(f, *names, &block)
  next_block = if names.length > 1
    proc do
      in_classes f, *names.drop(1), &block
    end
  else
    block
  end
  f.in_class names.first, &next_block
end

- (Object) operation_base



139
140
141
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 139

def operation_base
  @operation_base ||= runtime_base 'Operation', 'operation'
end

- (Object) port_base



131
132
133
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 131

def port_base
  @port_base ||= runtime_base 'Port', 'port'
end

- (Object) proxy_base



135
136
137
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 135

def proxy_base
  @proxy_base ||= runtime_base 'Proxy', 'proxy'
end

- (Object) runtime_base(name, file_name)



151
152
153
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 151

def runtime_base(name, file_name)
  WsdlMapper::Naming::TypeName.new name, runtime_modules, "#{file_name}.rb", runtime_path
end

- (Object) runtime_modules



155
156
157
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 155

def runtime_modules
  @runtime_modules ||= %w[WsdlMapper Runtime]
end

- (Object) runtime_path



159
160
161
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 159

def runtime_path
  @runtime_path ||= %w[wsdl_mapper runtime]
end

- (Object) service_base



127
128
129
# File 'lib/wsdl_mapper/svc_generation/svc_generator.rb', line 127

def service_base
  @service_base ||= runtime_base 'Service', 'service'
end