Created
August 2, 2012 07:08
-
-
Save jackhong/3234708 to your computer and use it in GitHub Desktop.
Overwrite create
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module OmfRc::ResourceProxy::Garage | |
include OmfRc::ResourceProxyDSL | |
register_proxy :garage | |
def create(type, opts = nil) | |
# I can check the type here | |
if type.to_sym == :engine | |
logger.info "I can do it" | |
else | |
raise "Go away, I can't create #{type}" | |
end | |
# I can define some default properties for children | |
# by initialise property with a mash (only if property hasn't been initialised) | |
opts.property ||= Hashie::Mash.new | |
# I can also access garage's property with "self". | |
opts.property.provider = "Cosworth #{self.uid}" | |
super | |
end | |
hook :before_create do |resource, new_resource_type, new_resource_opts| | |
if new_resource_type.to_sym == :engine | |
logger.info "I can do it" | |
else | |
raise "Go away, I can't create #{new_resource_type}" | |
end | |
new_resource_opts.property ||= Hashie::Mash.new | |
new_resource_opts.property.provider = "Cosworth #{resource.uid}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment