2015-08-28 18:49:21 +00:00
|
|
|
# encoding: utf-8
|
2015-10-06 16:55:44 +00:00
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
2015-08-28 18:49:21 +00:00
|
|
|
|
|
|
|
module Vulcano
|
|
|
|
module Plugins
|
|
|
|
class Resource
|
2015-09-05 14:07:54 +00:00
|
|
|
def self.name(name)
|
2015-08-28 18:49:21 +00:00
|
|
|
Vulcano::Plugins::Resource.__register(name, self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.__register(name, obj)
|
2015-09-09 07:42:46 +00:00
|
|
|
# rubocop:disable Lint/NestedMethodDefinition
|
2015-08-28 18:49:21 +00:00
|
|
|
cl = Class.new(obj) do
|
2015-08-30 02:33:15 +00:00
|
|
|
# add some common methods
|
2015-08-28 18:49:21 +00:00
|
|
|
include Vulcano::Plugins::ResourceCommon
|
2015-10-07 21:59:26 +00:00
|
|
|
def initialize(backend, name, *args)
|
2015-08-30 02:33:15 +00:00
|
|
|
# attach the backend to this instance
|
2015-09-06 18:35:41 +00:00
|
|
|
@__backend_runner__ = backend
|
2015-10-07 21:59:26 +00:00
|
|
|
@__resource_name__ = name
|
2015-08-30 02:33:15 +00:00
|
|
|
# call the resource initializer
|
2015-08-28 18:49:21 +00:00
|
|
|
super(*args)
|
|
|
|
end
|
2015-09-06 18:35:41 +00:00
|
|
|
|
|
|
|
def vulcano
|
|
|
|
@__backend_runner__
|
|
|
|
end
|
2015-08-28 18:49:21 +00:00
|
|
|
end
|
2015-09-09 07:42:46 +00:00
|
|
|
# rubocop:enable Lint/NestedMethodDefinition
|
2015-08-30 02:33:15 +00:00
|
|
|
|
|
|
|
# add the resource to the registry by name
|
2015-08-28 18:49:21 +00:00
|
|
|
Vulcano::Resource.registry[name] = cl
|
|
|
|
end
|
2015-10-07 21:59:26 +00:00
|
|
|
|
|
|
|
# Define methods which are available to all resources
|
|
|
|
# and may be overwritten.
|
|
|
|
|
|
|
|
# Print the name of the resource
|
|
|
|
def to_s
|
|
|
|
@__resource_name__
|
|
|
|
end
|
2015-08-28 18:49:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module ResourceCommon
|
|
|
|
def resource_skipped
|
|
|
|
@resource_skipped
|
|
|
|
end
|
|
|
|
|
2015-09-05 14:07:54 +00:00
|
|
|
def skip_resource(message)
|
2015-08-28 18:49:21 +00:00
|
|
|
@resource_skipped = message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|