Class: OmfRc::ResourceFactory
- Inherits:
-
Object
- Object
- OmfRc::ResourceFactory
- Includes:
- ResourceProxyDSL
- Defined in:
- lib/omf_rc/resource_factory.rb
Overview
Factory class for managing available proxies and creating new resource proxy instances
Constant Summary collapse
- @@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
-
.create(type, opts = {}, creation_opts = {}, &creation_callback) ⇒ Object
(also: new)
Factory method to initiate new resource proxy.
-
.load_additional_resource_proxies(folder) ⇒ Object
Require files from a folder contains resource proxy definition files.
-
.load_default_resource_proxies ⇒ Object
Require files from default resource proxy library folder.
-
.proxy_list ⇒ Object
Return the proxy list.
-
.register_proxy(proxy_opts) ⇒ Object
Add a proxy to the list.
Methods included from ResourceProxyDSL
#call_hook, #hook_defined?, included
Class Method Details
.create(type, opts = {}, creation_opts = {}, &creation_callback) ⇒ Object Also known as: new
Factory method to initiate new resource proxy
25 26 27 28 29 30 31 32 33 34 |
# File '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 |
.load_additional_resource_proxies(folder) ⇒ Object
Require files from a folder contains resource proxy definition files
62 63 64 65 66 |
# File '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 |
.load_default_resource_proxies ⇒ Object
Require files from default resource proxy library folder
53 54 55 56 57 |
# File '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 |
.proxy_list ⇒ Object
Return the proxy list
39 40 41 |
# File 'lib/omf_rc/resource_factory.rb', line 39 def proxy_list @@proxy_list end |
.register_proxy(proxy_opts) ⇒ Object
Add a proxy to the list
44 45 46 47 48 49 50 |
# File '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 |