Class: OmfRc::ResourceFactory
- Inherits:
-
Object
- Object
- OmfRc::ResourceFactory
- Includes:
- ResourceProxyDSL
- Defined in:
- omf_rc/lib/omf_rc/resource_factory.rb
Overview
Factory class for managing available proxies and creating new resource proxy instances
Constant Summary
- @@proxy_list =
List of registered resource proxies
Hashie::Mash.new
Constants included from ResourceProxyDSL
OmfRc::ResourceProxyDSL::DEFAULT_PROP_ACCESS, OmfRc::ResourceProxyDSL::PROXY_DIR, OmfRc::ResourceProxyDSL::UTIL_DIR
Class Method Summary (collapse)
-
+ (Object) create(type, opts = {}, creation_opts = {}, &creation_callback)
(also: new)
Factory method to initiate new resource proxy.
-
+ (Object) load_additional_resource_proxies(folder)
Require files from a folder contains resource proxy definition files.
-
+ (Object) load_default_resource_proxies
Require files from default resource proxy library folder.
-
+ (Object) proxy_list
Return the proxy list.
-
+ (Object) register_proxy(proxy_opts)
Add a proxy to the list.
Methods included from ResourceProxyDSL
#call_hook, #hook_defined?, included
Class Method Details
+ (Object) create(type, opts = {}, creation_opts = {}, &creation_callback) Also known as: new
Factory method to initiate new resource proxy
25 26 27 28 29 30 31 32 33 34 |
# File 'omf_rc/lib/omf_rc/resource_factory.rb', line 25 def create(type, opts = {}, creation_opts = {}, &creation_callback) unless @@proxy_list.include?(type) raise ArgumentError, "Resource type not found: #{type.to_s}" unless @@proxy_list.include?(type) end # Create a new instance of abstract resource and return it debug "Create resource type: #{type} opts: #{opts} copts: #{creation_opts}" OmfRc::ResourceProxy::AbstractResource.new(type, opts, creation_opts) do |res| creation_callback.call(res) if creation_callback end end |
+ (Object) load_additional_resource_proxies(folder)
Require files from a folder contains resource proxy definition files
62 63 64 65 66 |
# File 'omf_rc/lib/omf_rc/resource_factory.rb', line 62 def load_additional_resource_proxies(folder) Dir["#{folder}/*.rb"].each do |file| require "#{folder}/#{File.basename(file).gsub(/\.rb/, '')}" end end |
+ (Object) load_default_resource_proxies
Require files from default resource proxy library folder
53 54 55 56 57 |
# File 'omf_rc/lib/omf_rc/resource_factory.rb', line 53 def load_default_resource_proxies Dir["#{File.dirname(__FILE__)}/resource_proxy/*.rb"].each do |file| require "omf_rc/resource_proxy/#{File.basename(file).gsub(/\.rb/, '')}" end end |
+ (Object) proxy_list
Return the proxy list
39 40 41 |
# File 'omf_rc/lib/omf_rc/resource_factory.rb', line 39 def proxy_list @@proxy_list end |
+ (Object) register_proxy(proxy_opts)
Add a proxy to the list
44 45 46 47 48 49 50 |
# File 'omf_rc/lib/omf_rc/resource_factory.rb', line 44 def register_proxy(proxy_opts) if @@proxy_list.has_key? proxy_opts[:name] raise StandardError, "Resource has been registered already" else @@proxy_list.update(proxy_opts) end end |