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 created using this facadate with property ‘infrastructureServices’.
-
#configureInterfaceService(interfaceServices) ⇒ Object
Tag all interfaces created 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) ⇒ 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.
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
273 274 275 276 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 273 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
287 288 289 290 291 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 287 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
364 365 366 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 364 def baseMetatypes controller.baseMetatypes end |
#cache_line(line, what = nil) ⇒ Object
Service for loader to save ‘line’ into cache
165 166 167 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 165 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
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 299 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 created using this facadate with property ‘infrastructureServices’
98 99 100 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 98 def configureInfrastructureService( infrastructureServices ) @infrastructureServices = infrastructureServices end |
#configureInterfaceService(interfaceServices) ⇒ Object
Tag all interfaces created using this facadate with property ‘interfaceService’
104 105 106 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 104 def configureInterfaceService( interfaceServices ) @interfaceServices = interfaceServices end |
#configureNamespace(namespace) ⇒ Object
Prefix all definititions with “##namespace.” string
113 114 115 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 113 def configureNamespace( namespace ) @namespace = namespace end |
#createLogger(logname) ⇒ Logger
Returns new logger object.
384 385 386 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 384 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.
346 347 348 349 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 346 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.
170 171 172 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 170 def doCache? !cacheFile.nil? end |
#get_cached(what = nil) ⇒ String
Read previously cached content (@see cache_line)
158 159 160 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 158 def get_cached( what=nil ) Sbuilder::Utils::FileIo.cache_read( get_cachefile(what) ) if doCache? end |
#getCacheDir ⇒ String
Return cache directory location from opitions
177 178 179 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 177 def getCacheDir controller.getCacheDir end |
#modelDefinition(newDefinition) ⇒ Object
Add ‘newDefinition’ to model
189 190 191 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 189 def modelDefinition( newDefinition ) controller.modelDefinition( newDefinition ) end |
#modelInterface(newInterface) ⇒ Object
Add ‘newInterface’ to model
195 196 197 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 195 def modelInterface( newInterface ) controller.modelInterface( newInterface ) end |
#newDefinition(definitionName, isArray = false) ⇒ Sbuilder::ParamSetDef
Returns New definition object created.
209 210 211 212 213 214 215 216 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 209 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)
225 226 227 228 229 230 231 232 233 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 225 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) ⇒ Sbuilder::ParamSet_If
Create new interface paramtereter set (and a response parameter set)
to ‘response’ (ie. definiting return from a operation)
for request. Use #response to access response object.
245 246 247 248 249 250 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 245 def newInterface( path, op ) interfaceParamSet = newParamset( path, op ) paramSetResponse = newParamset( path ) interfaceParamSet.setResponse( paramSetResponse ) return interfaceParamSet end |
#newParameter(name, isArray = false) ⇒ Sbuilder::Parameter_Dom
Cretate new pojo for a simple paramter
256 257 258 259 260 261 262 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 256 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
323 324 325 326 327 328 329 330 331 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 323 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.
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 142 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’
121 122 123 |
# File 'lib/sbuilder/facade/api_loader_facade.rb', line 121 def setInterfaceCacheFilePath( cacheFile ) @cacheFile = cacheFile end |