tla-sbuilder 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +116 -33
  3. data/VERSION +1 -1
  4. data/lib/cli/cli-customer.rb +41 -23
  5. data/lib/cli/cli-example.rb +1 -1
  6. data/lib/cli/cli-pet.rb +33 -30
  7. data/lib/cli/cli-text.rb +57 -17
  8. data/lib/cli/cli.rb +56 -10
  9. data/lib/sbuilder.rb +3 -1
  10. data/lib/sbuilder/constants.rb +5 -2
  11. data/lib/sbuilder/controller.rb +289 -59
  12. data/lib/sbuilder/default-sbuilder.yaml +25 -3
  13. data/lib/sbuilder/domain.rb +1 -1
  14. data/lib/sbuilder/domain_cardinality.rb +1 -1
  15. data/lib/sbuilder/domain_value.rb +1 -1
  16. data/lib/sbuilder/exception.rb +13 -7
  17. data/lib/sbuilder/extension_loader.rb +75 -18
  18. data/lib/sbuilder/facade/api_loader.rb +293 -0
  19. data/lib/sbuilder/factory.rb +66 -3
  20. data/lib/sbuilder/model.rb +59 -3
  21. data/lib/sbuilder/mustache/template.rb +13 -13
  22. data/lib/sbuilder/mustache/template_reader_context.rb +5 -3
  23. data/lib/sbuilder/param_set.rb +2 -1
  24. data/lib/sbuilder/param_set_db.rb +1 -1
  25. data/lib/sbuilder/param_set_def.rb +1 -1
  26. data/lib/sbuilder/param_set_if.rb +1 -1
  27. data/lib/sbuilder/param_set_loader_swagger.rb +122 -121
  28. data/lib/sbuilder/param_set_step.rb +1 -1
  29. data/lib/sbuilder/parameter.rb +1 -1
  30. data/lib/sbuilder/parameter_container.rb +1 -1
  31. data/lib/sbuilder/parameter_dom.rb +1 -1
  32. data/lib/sbuilder/parameter_ref.rb +2 -2
  33. data/lib/sbuilder/resolver_rule.rb +1 -1
  34. data/lib/sbuilder/resolver_rule_match.rb +1 -1
  35. data/lib/sbuilder/resolver_rule_ref.rb +1 -1
  36. data/lib/sbuilder/spec/README +5 -0
  37. data/lib/sbuilder/spec/api_loader_facade.rb +247 -0
  38. data/lib/utils/cache_lines.rb +21 -0
  39. data/lib/utils/netio.rb +5 -13
  40. data/mustache/cfg/macro_run.mustache +1 -0
  41. data/mustache/interface_processes.mustache +9 -2
  42. data/mustache/interface_stubs_dummy.mustache +7 -0
  43. data/mustache/interface_types.mustache +3 -3
  44. data/mustache/invariant_activate.mustache +16 -0
  45. data/mustache/setup/assumptions_activate.mustache +16 -0
  46. data/mustache/{domains_run.mustache → setup/domains_run.mustache} +2 -2
  47. data/mustache/setup/operator_run.mustache +2 -0
  48. data/mustache/setup/steps_run_bind_set.mustache +1 -1
  49. data/mustache/setup/steps_run_parameterBind.mustache +4 -2
  50. data/mustache/tla/macro_run.mustache +8 -0
  51. data/mustache/tla/operator_run.mustache +1 -0
  52. data/mustache/tla/plc_define_run.mustache +2 -4
  53. data/mustache/tla/plc_run_state.mustache +1 -1
  54. data/src-extend/extend/extend_invariant_cfg.mustache +1 -1
  55. data/src/pet/assumption_domains.tla +1 -1
  56. data/src/pet/correctness.cfg +4 -0
  57. data/tla-sbuilder.gemspec +3 -1
  58. metadata +14 -10
  59. data/lib/sbuilder/param_set_loader.rb +0 -77
  60. data/src-extend/extend_app/correctness.cfg +0 -9
@@ -57,7 +57,7 @@ generate:
57
57
 
58
58
  - desc: Interface types
59
59
  template: interface_types.mustache
60
- modelData: interfaces
60
+ modelData: interface_types # = interfaces (not filtered)
61
61
 
62
62
  - desc: Start of plc block
63
63
  template: tla/plc_header.mustache
@@ -240,10 +240,15 @@ generate:
240
240
  # --------------------
241
241
  # extension point: extend_invariant.cfg
242
242
 
243
- - desc: Extension pointo to activate specification invariants
243
+ - desc: Extension point to activate specification invariants - DEPRECATED
244
244
  template: extend/extend_invariant_cfg.mustache
245
245
  modelData: none
246
246
 
247
+ - desc: Activate invariants defined in sbuilder.yaml
248
+ template: invariant_activate.mustache
249
+ modelData: invariants
250
+
251
+
247
252
  - desc: End of module
248
253
  template: cfg/module_footer.mustache
249
254
  modelData: none
@@ -271,9 +276,14 @@ generate:
271
276
  modelData: none
272
277
 
273
278
  - desc: Setup domain values
274
- template: domains_run.mustache
279
+ template: setup/domains_run.mustache
275
280
  modelData: domains
276
281
 
282
+ - desc: Activate assumptions on setup
283
+ template: setup/assumptions_activate.mustache
284
+ modelData: assumptions
285
+
286
+
277
287
  # - desc: interface calls in setup
278
288
  # template: interface_steps.mustache
279
289
  # modelData: interfaces
@@ -301,6 +311,10 @@ generate:
301
311
  template: data-model-dump.mustache
302
312
  modelData: interfaces
303
313
 
314
+ - desc: Model interface_types (=request/reponse for all interfaces)
315
+ template: data-model-dump.mustache
316
+ modelData: interface_types
317
+
304
318
  - desc: Model infrastructureServices
305
319
  template: data-model-dump.mustache
306
320
  modelData: infrastructureServices
@@ -321,6 +335,14 @@ generate:
321
335
  template: data-model-dump.mustache
322
336
  modelData: steps
323
337
 
338
+ - desc: Active invariants
339
+ template: data-model-dump.mustache
340
+ modelData: invariants
341
+
342
+ - desc: Active assumptions
343
+ template: data-model-dump.mustache
344
+ modelData: assumptions
345
+
324
346
  - desc: Model footer
325
347
  template: data-model-footer.mustache
326
348
  modelData: none
@@ -15,7 +15,7 @@ module Sbuilder
15
15
 
16
16
  def initialize( options = {} )
17
17
  @logger = getLogger( PROGNAME, options )
18
- @logger.info( "#{__method__} initialized" )
18
+ @logger.debug( "#{__method__} initialized" )
19
19
  end
20
20
 
21
21
  def to_s
@@ -14,7 +14,7 @@ module Sbuilder
14
14
  def initialize( options = {} )
15
15
  super( options )
16
16
  @logger = getLogger( PROGNAME, options )
17
- @logger.info( "#{__method__} initialized" )
17
+ @logger.debug( "#{__method__} initialized" )
18
18
 
19
19
  # default values one
20
20
  @cardinality = 1
@@ -14,7 +14,7 @@ module Sbuilder
14
14
  def initialize( options = {} )
15
15
  super( options )
16
16
  @logger = getLogger( PROGNAME, options )
17
- @logger.info( "#{__method__} initialized" )
17
+ @logger.debug( "#{__method__} initialized" )
18
18
 
19
19
  # default values one
20
20
  @values = []
@@ -1,26 +1,32 @@
1
1
  module Sbuilder
2
2
 
3
- class TemplateReaderException < Exception
3
+ class SbuilderException < Exception
4
+ end
5
+
6
+ class TemplateReaderException < SbuilderException
4
7
  end
5
8
 
6
9
 
7
- class ResolverException < Exception
10
+ class ResolverException < SbuilderException
8
11
  end
9
12
 
10
- class ExtensionException < Exception
13
+ class ExtensionException < SbuilderException
11
14
  end
12
15
 
13
16
 
14
- class DomainException < Exception
17
+ class DomainException < SbuilderException
15
18
  end
16
19
 
17
- class ControllerException < Exception
20
+ class ControllerException < SbuilderException
18
21
  end
19
22
 
20
- class ModelException < Exception
23
+ class ModelException < SbuilderException
24
+ end
25
+
26
+ class LoaderException < SbuilderException
21
27
  end
22
28
 
23
- class LoaderException < Exception
29
+ class FactoryException < SbuilderException
24
30
  end
25
31
 
26
32
 
@@ -26,7 +26,7 @@ module Sbuilder
26
26
 
27
27
  def initialize( options = {} )
28
28
  @logger = getLogger( PROGNAME, options )
29
- @logger.info( "#{__method__} initialized" )
29
+ @logger.debug( "#{__method__} initialized" )
30
30
  self
31
31
  end
32
32
 
@@ -229,6 +229,9 @@ module Sbuilder
229
229
  # NB: expandedStepExtensionDef = stepExtensionDef['input']
230
230
  mustacheTemplateData = extendStepDefaults( interface, expandedStepExtensionDef, mustacheTemplateData )
231
231
 
232
+ # assign unique number to hash element in 'mustacheTemplateData'
233
+ mustacheTemplateData = extendNumbering( mustacheTemplateData )
234
+
232
235
  # added to stepParameterSet
233
236
  return mustacheTemplateData
234
237
 
@@ -467,6 +470,41 @@ module Sbuilder
467
470
 
468
471
  end
469
472
 
473
+ # ------------------------------------------------------------------
474
+ # number elements
475
+
476
+ # assign '_first' element for hash within 'mustacheTemplateData'
477
+ #
478
+ # @param mustacheTemplateData [Hash]
479
+ # @return [Hash] 'mustacheTemplateData' with record elements numbered
480
+ def extendNumbering( mustacheTemplateData )
481
+
482
+ recurseHash( mustacheTemplateData ) do |h,k,v,i|
483
+ v["_index"] = i
484
+ end
485
+ return mustacheTemplateData
486
+ end
487
+
488
+ # recurse hash, and yield 'hash', 'key', 'value', 'index' for each
489
+ # entry within the hash structure, which is_a?(Hash).
490
+
491
+ def recurseHash( hash, &block )
492
+
493
+ hash && hash.each_with_index do |(k,v),index|
494
+ if v.is_a?( Hash ) then
495
+ yield hash, k, v, index
496
+ recurseHash( v, &block)
497
+ elsif v.is_a?( Array ) then
498
+ v.each_with_index do |array_element,i|
499
+ if array_element.is_a?(Hash)
500
+ yield hash, k, array_element, i
501
+ recurseHash( array_element, &block)
502
+ end
503
+ end
504
+ end
505
+ end
506
+ end
507
+
470
508
  # ------------------------------------------------------------------
471
509
  # recurse 'stepExtensionInputs' configuration and create a hash
472
510
  # structure, which can be passed to mustache template
@@ -589,22 +627,38 @@ module Sbuilder
589
627
  # >> : end array
590
628
  def recurseStepInputs( stepExtensionInputs, keys=[], row=0, &block )
591
629
  stepExtensionInputs.each do |parameterName, parameterDef|
592
- if parameterDef.is_a?( Array ) then
593
- yield "<<", keys + [parameterName], nil, 0
594
- parameterDef.each.with_index do |parameterDefRow,index|
595
- yield "<<", keys + [parameterName], nil, index+1
596
- recurseStepInputs( parameterDefRow, keys + [parameterName], index+1, &block )
597
- yield ">>", keys + [parameterName], nil, index+1
630
+ begin
631
+ if parameterDef.is_a?( Array ) then
632
+ yield "<<", keys + [parameterName], nil, 0
633
+ parameterDef.each.with_index do |parameterDefRow,index|
634
+ yield "<<", keys + [parameterName], nil, index+1
635
+ recurseStepInputs( parameterDefRow, keys + [parameterName], index+1, &block )
636
+ yield ">>", keys + [parameterName], nil, index+1
637
+ end
638
+ yield ">>", keys + [parameterName], nil, 0
639
+
640
+ elsif parameterDef.is_a?( Hash ) then
641
+ yield "[", keys + [parameterName], nil, row
642
+ recurseStepInputs( parameterDef, keys + [parameterName], row, &block )
643
+ yield "]", keys + [parameterName], nil, row
644
+ else
645
+ # do not process "meta fields" e.g '_default'
646
+ yield "=", keys + [parameterName], parameterDef, row
598
647
  end
599
- yield ">>", keys + [parameterName], nil, 0
600
-
601
- elsif parameterDef.is_a?( Hash ) then
602
- yield "[", keys + [parameterName], nil, row
603
- recurseStepInputs( parameterDef, keys + [parameterName], row, &block )
604
- yield "]", keys + [parameterName], nil, row
605
- else
606
- # do not process "meta fields" e.g '_default'
607
- yield "=", keys + [parameterName], parameterDef, row
648
+ rescue SbuilderException => e
649
+ msg = <<-EOS.gsub( /^\s*/, '' )
650
+ Error:
651
+
652
+ #{e.message}
653
+
654
+
655
+ when processing parameter #{parameterName} with definition:
656
+
657
+ #{parameterDef.to_yaml}
658
+
659
+ EOS
660
+ @logger.error( "#{__method__} #{msg}" )
661
+ raise Sbuilder::LoaderException.new, msg, e.backtrace
608
662
  end
609
663
  end
610
664
  end # recurseStepInputs
@@ -695,7 +749,7 @@ module Sbuilder
695
749
  :parameter_name => parameterName,
696
750
  "rows" => false,
697
751
  "columns" => false,
698
- "_comma" => "",
752
+ "_comma" => ",", # assume that comma get removed if -needed
699
753
  }
700
754
  end
701
755
 
@@ -707,7 +761,10 @@ module Sbuilder
707
761
 
708
762
  # la
709
763
  columns['columns'].last["_comma"] = ',' if columns['columns'].length > 0
710
-
764
+
765
+ # no comma here
766
+ column["_comma"] = ''
767
+
711
768
  columns['columns'] << column
712
769
  return column
713
770
  end
@@ -0,0 +1,293 @@
1
+ module Sbuilder
2
+
3
+ # Facade to Sbuilder for api loaders.
4
+ #
5
+ # Class implements following service groups
6
+ #
7
+ # - for controller to configure the facade (this part is not visible for api)
8
+ #
9
+ # - for api loader to read/cache api configuration, to create
10
+ # model objects, and build sbuilder model
11
+ #
12
+
13
+ class ApiLoader
14
+
15
+ extend Forwardable # for easy delegation
16
+
17
+ # facade configuration
18
+
19
+ attr_reader :infrastructureServices # default 'false'
20
+
21
+ # string to prefix to all definitions (default 'nil' ie. no
22
+ # prefix). Allow homonymous API definition names ie. same
23
+ # name in separata definitions.
24
+ attr_reader :namespace
25
+
26
+ attr_reader :cacheFile # controller sets before
27
+ # loader called
28
+
29
+ # facade collaborators
30
+
31
+ attr_reader :factory # to create stuff
32
+ attr_accessor :controller # get sets when load starts
33
+
34
+ def_delegators :controller,
35
+ :modelDefinition, #
36
+ :modelInterface
37
+
38
+
39
+ def_delegators :factory,
40
+ :createParamSet, # @return[Sbuilder::ParamSet]
41
+ :createParameter # @return[Sbuilder::Parameter]
42
+
43
+ # ------------------------------------------------------------------
44
+
45
+
46
+ # progname for logger
47
+ PROGNAME = "ApiLoader"
48
+
49
+ include Sbuilder::Utils::MyLogger # mix logger
50
+
51
+
52
+ # ------------------------------------------------------------------
53
+ # @!group Constructore
54
+
55
+ def initialize( factory, options = {} )
56
+ @logger = getLogger( PROGNAME, options )
57
+ @logger.info( "#{__method__} initialized" )
58
+
59
+ # collaborators init
60
+ setFactory( factory )
61
+ @controller = nil
62
+
63
+ # configuration init
64
+ @infrastructureServices = false
65
+ @namespace = nil
66
+
67
+ @cacheFile = nil
68
+ @options = options
69
+
70
+ end
71
+
72
+ # @!endgroup
73
+
74
+ # ------------------------------------------------------------------
75
+ # @!group Interface used by controller to configure the facade
76
+
77
+ # Allow facade to access controller services
78
+ # @param controller [Sbuilder::Controller] controller sets self
79
+ def setController( controller )
80
+ @controller = controller
81
+ end
82
+
83
+ # Facade delagates the task to create new objects to `factory
84
+ # @param factory [Sbuilder::Factory] to create new obejcts
85
+ def setFactory( factory )
86
+ @factory = factory
87
+ end
88
+
89
+ # Tag all interfaces created using this facadate with property 'infrastructureServices'
90
+ #
91
+ # @param infrastructureServices [Boolean] true/false set on all interfaces
92
+ #
93
+ def configureInfrastructureService( infrastructureServices )
94
+ @infrastructureServices = infrastructureServices
95
+ end
96
+
97
+ # Prefix all definititions with "#{namespace}." string
98
+ #
99
+ # @param namespace [String] string to prefix to all definitions
100
+ #
101
+ def configureNamespace( namespace )
102
+ @namespace = namespace
103
+ end
104
+
105
+ # Cache string read into 'cacheFile'
106
+ #
107
+ # @param cacheFile [String] name of file to cache content in this facade
108
+ #
109
+ def setInterfaceCacheFilePath( cacheFile )
110
+ @cacheFile = cacheFile
111
+ end
112
+
113
+ # @!endgroup
114
+
115
+ # ------------------------------------------------------------------
116
+ # @!group Read and cache api content
117
+
118
+ # Reader service: read String of interface definitions from
119
+ # 'location'. The string is cached in '@cacheFile', which
120
+ # controller has configured.
121
+ #
122
+ # @param location [String] uri/file/block parameter from which to
123
+ # read the string
124
+ #
125
+ # @param blk [yield] yield block to read if no block given use
126
+ # 'Sbuilder::Utils::NetIo.read_lines'. Block should return a
127
+ # string.
128
+ #
129
+ # @return [String] read from 'location' (or from @cacheFile)
130
+ def read_cached( location, &blk )
131
+ # return cached
132
+ line = get_cached
133
+ return line if line
134
+ if block_given?
135
+ line = yield( location )
136
+ else
137
+ line = Sbuilder::Utils::NetIo.read_lines( location )
138
+ end
139
+ cache_line( line )
140
+ return line
141
+ end
142
+
143
+ # Read previously cached content (@see cache_line)
144
+ # @param what [String] sub-content in cache
145
+ # @return [String] cached content (nil if no cached content
146
+ def get_cached( what=nil )
147
+ Sbuilder::Utils::CacheLines.cache_read( get_cachefile(what) ) if doCache?
148
+ end
149
+
150
+ # Service for loader to save 'line' into cache
151
+ # @param line [String] content to store
152
+ # @param what [String] sub-content in cache
153
+ def cache_line( line, what=nil )
154
+ Sbuilder::Utils::CacheLines.cache_write( get_cachefile(what), line ) if doCache? && line
155
+ end
156
+
157
+ # @return [Boolean] true if cache i.e. when cacheFile defined
158
+ def doCache?
159
+ !cacheFile.nil?
160
+ end
161
+
162
+ # @!endgroup
163
+ # ------------------------------------------------------------------
164
+
165
+ # ------------------------------------------------------------------
166
+ # @!group Build model
167
+
168
+ # Add 'newDefinition' to model
169
+ # @param newDefinition [Sbuilder::ParamSetDef] definition to add
170
+ def modelDefinition( newDefinition )
171
+ controller.modelDefinition( newDefinition )
172
+ end
173
+
174
+ # Add 'newInterface' to model
175
+ # @param newInterface [Sbuilder::ParamSet_If] interface to add
176
+ def modelInterface( newInterface )
177
+ controller.modelInterface( newInterface )
178
+ end
179
+
180
+ # @!endgroup
181
+
182
+ # ------------------------------------------------------------------
183
+ # @!group Construct model objects
184
+
185
+ #
186
+ # @param definitionName [String] name of defintition to create
187
+ # @param isArray [Boolean] if array defined
188
+ #
189
+ # @return [Sbuilder::ParamSetDef] New definition object created
190
+ def newDefinition( definitionName, isArray=false )
191
+ paramSet = createParamSet( Sbuilder::Constants::SWAGGER_DEFINITION )
192
+ # optionally prefix within namespace
193
+ definitionName = namespacedReferenceName( definitionName )
194
+ paramSet.setDefinition( definitionName )
195
+ paramSet.setIsArray( isArray )
196
+ return paramSet
197
+ end
198
+
199
+ # Create new interface paramtereter sert (and response parameter set)
200
+ #
201
+ # @param path [String] path of restfull interface operation
202
+ #
203
+ # @param op [String] rest operation (get, put, post,...), defaults
204
+ # to 'response' (ie. definiting return from a operation)
205
+ #
206
+ # @return [Sbuilder::ParamSet_If] New interface param set createds
207
+ # for request. Use #response to access response object.
208
+ def newInterface( path, op )
209
+ interfaceParamSet = newParamset( path, op )
210
+ paramSetResponse = newParamset( path )
211
+ interfaceParamSet.setResponse( paramSetResponse )
212
+ return interfaceParamSet
213
+ end
214
+
215
+ # Cretate new pojo for a simple paramter
216
+ # @param name [String] name of the simple paramter to create
217
+ # @param isArray [Boolean] true if array
218
+ # @return [Sbuilder::Parameter_Dom] new parmater created
219
+ def newParameter( name, isArray=false )
220
+ swagger_parameter = createParameter( Sbuilder::Constants::PARAMETER )
221
+ swagger_parameter.setName( name )
222
+ # default for parameter 'not array' - set exlicitely array
223
+ swagger_parameter.setIsArray( isArray )
224
+ return swagger_parameter
225
+ end
226
+
227
+ # Create new pojo for a reference to a definition
228
+ #
229
+ # @param name [String] name of the simple paramter to create
230
+ # @param referenceName [String] definition name referenced
231
+ # @param isArray [Boolean] true if array
232
+ # @return [Sbuilder::Parameter_Ref] new parmater created
233
+
234
+ def newParameterReference( name, referenceName, isArray )
235
+ swagger_parameter = createParameter( Sbuilder::Constants::PARAMETER_REF )
236
+ swagger_parameter.setName( name )
237
+ # namespace.name
238
+ referenceName = namespacedReferenceName( referenceName )
239
+ swagger_parameter.setReference( referenceName )
240
+ swagger_parameter.setIsArray( isArray )
241
+ return swagger_parameter
242
+ end
243
+
244
+ # @!endgroup
245
+ # ------------------------------------------------------------------
246
+
247
+ # ------------------------------------------------------------------
248
+ # @!group misc
249
+
250
+ # @return [String] semver number
251
+ def version
252
+ "1.0.2"
253
+ end
254
+
255
+ # @param logname [String] progname to set on logger
256
+ # @return [Logger] new logger object
257
+ def createLogger( logname )
258
+ getLogger( logname, @options )
259
+ end
260
+
261
+ # @!endgroup
262
+
263
+ # ------------------------------------------------------------------
264
+ # Private
265
+
266
+ private
267
+
268
+ # @return [Sbuilder::ParamSet_If] New interface param set created
269
+ def newParamset( path, op ='response' )
270
+ interfaceParamSet = createParamSet( Sbuilder::Constants::INTERFACE_OPERATION )
271
+ interfaceParamSet.setIdentity( path, op )
272
+ interfaceParamSet.setInfrastructureService( infrastructureServices )
273
+ return interfaceParamSet
274
+ end
275
+
276
+ # @return [String] path to cachefile
277
+ def get_cachefile( what )
278
+ "#{cacheFile}#{ what ? '.' + what : '' }"
279
+ end
280
+
281
+ # @return [String] 'definitionName' optionallayy prefixed with namespace
282
+ def namespacedReferenceName( definitionName )
283
+ if namespace
284
+ definitionName = "#{namespace}.#{definitionName}"
285
+ end
286
+ return definitionName
287
+ end
288
+
289
+
290
+ end # class ApiLoader
291
+
292
+
293
+ end # module