class MediTAF::Services::ResourcesMgr
Attributes
Public Class Methods
@note loads euresource adapter by default, otherwise attempts to load a specific adapter. adapters are
specified in *MediTAF_configuration.services.adapter* value. the location of the adapter defaults to services/clients within MediTAF, otherwise it can be specified in *MediTAF_configuration.services.adapter_home* value. when MediTAF attempts to load the adapter and no location has been specified, MediTAF assumes that the adapter has been load into the environment.
@note the adapter must be in namespace MediTAF::Services::Clients @raise [ResourceAdapterMethodMissing] when adapter does not respond to configure @raise [ResourceAdapterLoadError] when adapter could not be loaded
# File lib/MediTAF/services/resources_mgr.rb, line 28 def initialize @resources = {} @adapters = {} raise ServiceConfigurationMissing, "services not found in configuration" unless MediTAF::Utils::Configuration['services'] adapter_home = MediTAF::Utils::Configuration['services']['adapter_home'] adapter_home ||= "#{MediTAF.root}/lib/MediTAF/services/clients" adapters = MediTAF::Utils::Configuration['services']['adapters'] if adapters adapters.split(/ *, */).each do |adapter| begin require "#{adapter_home}/#{adapter}_adapter" if File.exist? "#{adapter_home}/#{adapter}_adapter.rb" @adapters[adapter.to_sym] = "MediTAF::Services::Clients::#{adapter.camelize}Adapter".constantize.new @adapters[adapter.to_sym].configure rescue NoMethodError => e raise ResourceAdapterMethodMissing, %Q|"#{adapter.camelize}Adapter" is missing required configure method| rescue NameError => e raise ResourceAdapterLoadError, %Q|Couldn't load resource adapter "#{adapter.camelize}Adapter". Inner Exception: #{e.to_s}| end end end end
Public Instance Methods
checks if a resource is consumable @note not implemented @param resource [Symbol] the resource to check
# File lib/MediTAF/services/resources_mgr.rb, line 74 def connected?(resource) raise "not implemented" end
@param adapter [Symbol] the adapter to get the stage from @return [Symbol] gets the default stage set for the adapter
# File lib/MediTAF/services/resources_mgr.rb, line 86 def default_stage(adapter=:euresource) @adapters[adapter].default_stage if @adapters.has_key? adapter end
removes all or one resource from the resources hash @param resource [Symbol] the resource to remove
# File lib/MediTAF/services/resources_mgr.rb, line 56 def delete(resource=nil) if resource @resources.delete(resource) if @resources.include?(resource) else @resources.clear end end
checks if a resource has been deployed @note not implemented @param resource [Symbol] the resource to check
# File lib/MediTAF/services/resources_mgr.rb, line 67 def deployed?(resource) raise "not implemented" end
@param resource [Symbol] resource as a method name @param args [Object] args are passed to underlying adapter @return [Object] the specific resource adapter object @raise [ResourceAdapterMethodMissing] when adapter does not respond to load
# File lib/MediTAF/services/resources_mgr.rb, line 94 def method_missing(resource, *args, &block) opts = args[0] || {} unless @resources.include?(resource) unless @adapters.has_key? opts[:adapter] raise ResourceAdapterMissing, %Q/'#{opts[:adapter]}' adapter not found/ end adapter = @adapters[ opts[:adapter] ] opts.delete(:adapter) @resources[resource] = ( opts.nil? || opts.empty?) ? adapter.load(resource) : adapter.load(opts) end @resources[resource] rescue NoMethodError => e raise ResourceAdapterMethodMissing, "required load method missing" end