Class: Sbuilder::ApiLoaderFacade
- Inherits:
-
Object
- Object
- Sbuilder::ApiLoaderFacade
- Extended by:
- Forwardable
- Includes:
- Utils::MyLogger
- Defined in:
- lib/sbuilder/facade/api_loader_facade.rb
Overview
Facade to Sbuilder for api loaders.
Class implements following service groups
-
for controller to configure the facade (this part is not visible for api)
-
for api loader to read/cache api configuration, to create model objects, and build sbuilder model
Constant Summary collapse
- PROGNAME =
progname for logger
nil
Constants included from Utils::MyLogger
Instance Attribute Summary collapse
-
#cacheFile ⇒ Object
readonly
Returns the value of attribute cacheFile.
-
#controller ⇒ Object
get sets when load starts.
-
#factory ⇒ Object
readonly
facade collaborators.
- #infrastructureServices ⇒ Object readonly
- #interfaceServices ⇒ Object readonly
-
#namespace ⇒ Object
readonly
string to prefix to all definitions (default ‘nil’ ie. no prefix).
Construtor collapse
-
#initialize(factory, options = {}) ⇒ ApiLoaderFacade
constructor
——————————————————————.
Prepare Facade collapse
-
#configureInfrastructureService(infrastructureServices) ⇒ Object
Tag all interfaces loaded using this facede with property ‘infrastructureServices’.
-
#configureInterfaceService(interfaceServices) ⇒ Object
Tag all interfaces loaded using this facadate with property ‘interfaceService’.
-
#configureNamespace(namespace) ⇒ Object
Prefix all definititions with “##namespace.” string.
-
#setController(controller) ⇒ Object
Allow facade to access controller services.
-
#setFactory(factory) ⇒ Object
Facade delagates the task to create new objects to ‘factory.
-
#setInterfaceCacheFilePath(cacheFile) ⇒ Object
Cache string read into ‘cacheFile’.
Cache API Metadata collapse
-
#cache_line(line, what = nil) ⇒ Object
Service for loader to save ‘line’ into cache.
-
#doCache? ⇒ Boolean
True if cache i.e.
-
#get_cached(what = nil) ⇒ String
Read previously cached content (@see cache_line).
-
#getCacheDir ⇒ String
Return cache directory location from opitions.
-
#read_cached(location, &blk) ⇒ String
Reader service: read String of interface definitions from ‘location’.
Add to Sbuilder collapse
-
#modelDefinition(newDefinition) ⇒ Object
Add ‘newDefinition’ to model.
-
#modelInterface(newInterface) ⇒ Object
Add ‘newInterface’ to model.
Construct Model Objects collapse
-
#addParameter(paramSet, parameter, domain_name = nil) ⇒ Object
Add
paramtertoparameterSet. -
#addResponseParameter(paramSet, parameter, domain_name = nil) ⇒ Object
Add
paramtertoparameterSetresponse. -
#configParameterDomain(parameter, domain_name) ⇒ Object
Set
domain_nametoparameter. -
#newDefinition(definitionName, isArray = false) ⇒ Sbuilder::ParamSetDef
New definition object created.
-
#newFunctionDefinition(definitionName, isArray = false) ⇒ Sbuilder::ParamSetDefFunc
Create a function definition (parameter set).
-
#newInterface(path, op, optionReturn = nil, optionInterface = nil) ⇒ Sbuilder::ParamSet_If
Create new interface paramtereter set (and a response parameter set).
-
#newParameter(name, isArray = false) ⇒ Sbuilder::Parameter_Dom
Cretate new pojo for a simple paramter.
-
#newParameterReference(name, referenceName, isArray) ⇒ Sbuilder::Parameter_Ref
Create new pojo for a reference to a definition.
-
#setSourceLink(paramSet, sourceModule, sourceLine, sourceColumn = 0) ⇒ Object
Implementation delegates ‘setSourceLink’ to ‘paramSet’.
domain collapse
-
#defineDomain(domainName, domainValues = nil) ⇒ Object
Add
domainNameto sbuilder.
Access framework context collapse
-
#baseMetatypes ⇒ Hash
Return array of base metatypes in sbuilder context.
Miscellaneous Operations collapse
-
#createLogger(logname) ⇒ Logger
New logger object.
-
#version ⇒ Object
# @return [String] semver number.
Methods included from Utils::MyLogger
Constructor Details
#initialize(factory, options = {}) ⇒ ApiLoaderFacade
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 57 def initialize( factory, = {} ) @logger = getLogger( PROGNAME, ) @logger.info( "#{__method__} initialized" ) # collaborators init setFactory( factory ) @controller = nil # configuration init configureInfrastructureService( false ) configureInterfaceService( true ) @namespace = nil @cacheFile = nil @options = end |
Instance Attribute Details
#cacheFile ⇒ Object (readonly)
Returns the value of attribute cacheFile.
30 31 32 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 30 def cacheFile @cacheFile end |
#controller ⇒ Object
get sets when load starts
36 37 38 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 36 def controller @controller end |
#factory ⇒ Object (readonly)
facade collaborators
35 36 37 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 35 def factory @factory end |
#infrastructureServices ⇒ Object (readonly)
19 20 21 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 19 def infrastructureServices @infrastructureServices end |
#interfaceServices ⇒ Object (readonly)
22 23 24 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 22 def interfaceServices @interfaceServices end |
#namespace ⇒ Object (readonly)
string to prefix to all definitions (default ‘nil’ ie. no prefix). Allow homonymous API definition names ie. same name in separata definitions.
28 29 30 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 28 def namespace @namespace end |
Instance Method Details
#addParameter(paramSet, parameter, domain_name = nil) ⇒ Object
Add paramter to parameterSet
302 303 304 305 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 302 def addParameter( paramSet, parameter, domain_name=nil ) paramSet.addParameter( parameter ) configParameterDomain( parameter, domain_name ) if domain_name end |
#addResponseParameter(paramSet, parameter, domain_name = nil) ⇒ Object
Add paramter to parameterSet response
316 317 318 319 320 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 316 def addResponseParameter( paramSet, parameter, domain_name=nil ) responseParamSet = paramSet.response responseParamSet.addParameter( parameter ) configParameterDomain( parameter, domain_name ) if domain_name end |
#baseMetatypes ⇒ Hash
Return array of base metatypes in sbuilder context
393 394 395 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 393 def baseMetatypes controller.baseMetatypes end |
#cache_line(line, what = nil) ⇒ Object
Service for loader to save ‘line’ into cache
167 168 169 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 167 def cache_line( line, what=nil ) Sbuilder::Utils::FileIo.cache_write( get_cachefile(what), line ) if doCache? && line end |
#configParameterDomain(parameter, domain_name) ⇒ Object
Set domain_name to parameter
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 328 def configParameterDomain( parameter, domain_name ) if !parameter.is_a?(Parameter_Dom) then msg = <<-EOS Only domain parameters can assgined domain In this case domain '#{domain_name}' was assigned to #{parameter.class} EOS @logger.error "#{__method__}, msg" raise PluginException, msg end # call static busines rule to set 'domain' on 'parameter' in model context ResolverRuleMatch.setDomain( parameter, domain_name, controller.model ) end |
#configureInfrastructureService(infrastructureServices) ⇒ Object
Tag all interfaces loaded using this facede with property ‘infrastructureServices’. See attriute #infrastructureServices
99 100 101 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 99 def configureInfrastructureService( infrastructureServices ) @infrastructureServices = infrastructureServices end |
#configureInterfaceService(interfaceServices) ⇒ Object
Tag all interfaces loaded using this facadate with property ‘interfaceService’. See attribute #interfaceServices
106 107 108 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 106 def configureInterfaceService( interfaceServices ) @interfaceServices = interfaceServices end |
#configureNamespace(namespace) ⇒ Object
Prefix all definititions with “##namespace.” string
115 116 117 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 115 def configureNamespace( namespace ) @namespace = namespace end |
#createLogger(logname) ⇒ Logger
Returns new logger object.
413 414 415 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 413 def createLogger( logname ) getLogger( logname, @options ) end |
#defineDomain(domainName, domainValues = nil) ⇒ Object
Add domainName to sbuilder. Pass domainValues to controller using setApplicationDomainValues api if defined.
375 376 377 378 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 375 def defineDomain( domainName, domainValues = nil ) controller.domainEncountered( domainName ) controller.setApplicationDomainValues( domainName, domainValues ) if domainValues && domainValues.is_a?( Array ) && domainValues.any? end |
#doCache? ⇒ Boolean
Returns true if cache i.e. when cacheFile defined.
172 173 174 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 172 def doCache? !cacheFile.nil? end |
#get_cached(what = nil) ⇒ String
Read previously cached content (@see cache_line)
160 161 162 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 160 def get_cached( what=nil ) Sbuilder::Utils::FileIo.cache_read( get_cachefile(what) ) if doCache? end |
#getCacheDir ⇒ String
Return cache directory location from opitions
179 180 181 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 179 def getCacheDir controller.getCacheDir end |
#modelDefinition(newDefinition) ⇒ Object
Add ‘newDefinition’ to model
191 192 193 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 191 def modelDefinition( newDefinition ) controller.modelDefinition( newDefinition ) end |
#modelInterface(newInterface) ⇒ Object
Add ‘newInterface’ to model
197 198 199 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 197 def modelInterface( newInterface ) controller.modelInterface( newInterface ) end |
#newDefinition(definitionName, isArray = false) ⇒ Sbuilder::ParamSetDef
Returns New definition object created.
211 212 213 214 215 216 217 218 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 211 def newDefinition( definitionName, isArray=false ) paramSet = createParamSet( Sbuilder::Constants::DEFINITION ) # optionally prefix within namespace definitionName = namespacedReferenceName( definitionName ) paramSet.setDefinition( definitionName ) paramSet.setIsArray( isArray ) return paramSet end |
#newFunctionDefinition(definitionName, isArray = false) ⇒ Sbuilder::ParamSetDefFunc
Create a function definition (parameter set)
227 228 229 230 231 232 233 234 235 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 227 def newFunctionDefinition( definitionName, isArray=false ) paramSet = createParamSet( Sbuilder::Constants::DEFINITION_FUNCTION ) # optionally prefix within namespace definitionName = namespacedReferenceName( definitionName ) paramSet.setDefinition( definitionName ) paramSet.setIsArray( isArray ) return paramSet end |
#newInterface(path, op, optionReturn = nil, optionInterface = nil) ⇒ Sbuilder::ParamSet_If
Create new interface paramtereter set (and a response parameter set)
response, nil uses facade #infrastructureServices
process for the service, nil uses facade default #interfaceServices
to ‘response’ (ie. definiting return from a operation)
for request. Use #response to access response object.
254 255 256 257 258 259 260 261 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 254 def newInterface( path, op, optionReturn=nil, optionInterface=nil ) @logger.info "#{__method__}: path=#{path}, op=#{op}, optionReturn=#{optionReturn}, optionInterface=#{optionInterface}" interfaceParamSet = newParamset( path, op, optionReturn, optionInterface ) paramSetResponse = newParamset( path ) interfaceParamSet.setResponse( paramSetResponse ) return interfaceParamSet end |
#newParameter(name, isArray = false) ⇒ Sbuilder::Parameter_Dom
Cretate new pojo for a simple paramter
285 286 287 288 289 290 291 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 285 def newParameter( name, isArray=false ) swagger_parameter = createParameter( Sbuilder::Constants::PARAMETER ) swagger_parameter.setName( name ) # default for parameter 'not array' - set exlicitely array swagger_parameter.setIsArray( isArray ) return swagger_parameter end |
#newParameterReference(name, referenceName, isArray) ⇒ Sbuilder::Parameter_Ref
Create new pojo for a reference to a definition
352 353 354 355 356 357 358 359 360 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 352 def newParameterReference( name, referenceName, isArray ) refParameter = createParameter( Sbuilder::Constants::PARAMETER_REF ) refParameter.setName( name ) # namespace.name referenceName = namespacedReferenceName( referenceName ) refParameter.setReference( referenceName ) refParameter.setIsArray( isArray ) return refParameter end |
#read_cached(location, &blk) ⇒ String
Reader service: read String of interface definitions from ‘location’. The string is cached in ‘@cacheFile’, which controller has configured.
read the string
‘Sbuilder::Utils::NetIo.read_lines’. Block should return a string.
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 144 def read_cached( location, &blk ) # return cached line = get_cached return line if line if block_given? line = yield( location ) else line = Sbuilder::Utils::NetIo.read_lines( location ) end cache_line( line ) return line end |
#setController(controller) ⇒ Object
Allow facade to access controller services
83 84 85 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 83 def setController( controller ) @controller = controller end |
#setFactory(factory) ⇒ Object
Facade delagates the task to create new objects to ‘factory
89 90 91 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 89 def setFactory( factory ) @factory = factory end |
#setInterfaceCacheFilePath(cacheFile) ⇒ Object
Cache string read into ‘cacheFile’
123 124 125 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 123 def setInterfaceCacheFilePath( cacheFile ) @cacheFile = cacheFile end |
#setSourceLink(paramSet, sourceModule, sourceLine, sourceColumn = 0) ⇒ Object
Implementation delegates ‘setSourceLink’ to ‘paramSet’
parameter set
275 276 277 278 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 275 def setSourceLink(paramSet, sourceModule, sourceLine, sourceColumn=0) @logger.info "#{__method__}: paramSet=#{paramSet}, sourceModule=#{sourceModule}, sourceLine=#{sourceLine}" paramSet.setSourceLink(sourceModule, sourceLine, sourceColumn) end |