improvement: add default print method to resources

This commit is contained in:
Dominik Richter 2015-10-07 23:59:26 +02:00
parent f2f320f898
commit 4176d1b227
4 changed files with 13 additions and 4 deletions

View file

@ -56,7 +56,7 @@ module Vulcano
end
Vulcano::Resource.registry.each do |id, r|
define_method id.to_sym do |*args|
r.new(self, *args)
r.new(self, id.to_s, *args)
end
end
end

View file

@ -14,9 +14,10 @@ module Vulcano
cl = Class.new(obj) do
# add some common methods
include Vulcano::Plugins::ResourceCommon
def initialize(backend, *args)
def initialize(backend, name, *args)
# attach the backend to this instance
@__backend_runner__ = backend
@__resource_name__ = name
# call the resource initializer
super(*args)
end
@ -30,6 +31,14 @@ module Vulcano
# add the resource to the registry by name
Vulcano::Resource.registry[name] = cl
end
# Define methods which are available to all resources
# and may be overwritten.
# Print the name of the resource
def to_s
@__resource_name__
end
end
module ResourceCommon

View file

@ -63,7 +63,7 @@ module Vulcano
Module.new do
Vulcano::Resource.registry.each do |id, r|
define_method id.to_sym do |*args|
r.new(backend, *args)
r.new(backend, id.to_s, *args)
end
end
end

View file

@ -151,7 +151,7 @@ class MockLoader
def load_resource(resource, *args)
# initialize resource with backend and parameters
@resource_class = Vulcano::Resource.registry[resource]
@resource = @resource_class.new(backend, *args)
@resource = @resource_class.new(backend, resource, *args)
end
end