move to a simpler plugin structure

This has been inspired in its calling structure by the wonderful work done in Vagrant. Kudos to all contributors!

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-08-28 10:10:03 -07:00
parent 9e7ea1ef5d
commit 3bf8037638
4 changed files with 39 additions and 28 deletions

View file

@ -4,9 +4,10 @@
require 'utils/simpleconfig'
module SshConf
class SshConf < Vulcano.resource(1)
name 'ssh_config'
def create( conf_path = nil, type = nil )
def initialize( conf_path = nil, type = nil )
@conf_path = conf_path || '/etc/ssh/ssh_conf'
@conf_dir = File.expand_path(File.dirname @conf_path)
@conf = nil
@ -56,12 +57,10 @@ module SshConf
end
module SshdConf
include SshConf
def create(path = nil)
class SshdConf < SshConf
name 'sshd_config'
def initialize(path = nil)
super(path || '/etc/ssh/sshd_config')
end
end
Vulcano.add_resource('ssh_config', SshConf)
Vulcano.add_resource('sshd_config', SshdConf)

View file

@ -12,6 +12,17 @@ module Vulcano
__CTX = self
backend = Vulcano::Backend::Mock::Runner.new
resource_classes = {}
Vulcano::Resource.registry.each do |name, cl|
resource_classes[name] = Class.new(cl) do
include Vulcano::ResourceCommon
def initialize(backend, *args)
@vulcano = backend
super(*args)
end
end
end
# This is the heart of the profile context
# An instantiated object which has all resources registered to it
# and exposes them to the a test file.
@ -19,24 +30,20 @@ module Vulcano
include Serverspec::Helper::Type
extend Serverspec::Helper::Type
include Vulcano::DSL
define_method :__register_rule do |*args|
__CTX.register_rule(*args)
end
define_method :__unregister_rule do |*args|
__CTX.unregister_rule(*args)
end
Vulcano::Resources.modules.each do |id, r|
resource_classes.each do |id,r|
define_method id.to_sym do |*args|
res = Class.new(Vulcano::Resource) do
include r
def initialize(backend, *args)
@vulcano = backend
create(*args)
end
end
res.new(backend, *args)
r.new(backend, *args)
end
end
def to_s
'Profile Context Run'
end

View file

@ -4,6 +4,16 @@
module Vulcano
class Resource
def self.registry
@registry ||= {}
end
def self.name( name )
Vulcano::Resource.registry[name] = self
end
end
module ResourceCommon
def resource_skipped
@resource_skipped
@ -14,4 +24,8 @@ module Vulcano
end
end
end
def self.resource(version)
Vulcano::Resource
end
end

View file

@ -1,15 +1,6 @@
# encoding: utf-8
require 'utils/modulator'
module Vulcano
class Resources
extend Modulator
end
def self.add_resource(*args)
Vulcano::Resources.add_module(*args)
end
end
require 'vulcano/resource'
# require 'resources/apache_conf'
# require 'resources/audit_policy'