lib/miam/dsl/context.rb in miam-0.2.2.beta vs lib/miam/dsl/context.rb in miam-0.2.2.beta2

- old
+ new

@@ -1,6 +1,8 @@ class Miam::DSL::Context + include Miam::TemplateHelper + def self.eval(dsl, path, options = {}) self.new(path, options) { eval(dsl, binding, path) } end @@ -9,13 +11,24 @@ def initialize(path, options = {}, &block) @path = path @options = options @result = {:users => {}, :groups => {}, :roles => {}, :instance_profiles => {}} + + @context = Hashie::Mash.new( + :path => path, + :options => options, + :templates => {} + ) + instance_eval(&block) end + def template(name, &block) + @context.templates[name.to_s] = block + end + private def require(file) iamfile = (file =~ %r|\A/|) ? file : File.expand_path(File.join(File.dirname(@path), file)) @@ -33,32 +46,32 @@ if @result[:users][name] raise "User `#{name}` is already defined" end - attrs = Miam::DSL::Context::User.new(name, &block).result + attrs = Miam::DSL::Context::User.new(@context, name, &block).result @result[:users][name] = user_options.merge(attrs) end def group(name, group_options = {}, &block) name = name.to_s if @result[:groups][name] raise "Group `#{name}` is already defined" end - attrs = Miam::DSL::Context::Group.new(name, &block).result + attrs = Miam::DSL::Context::Group.new(@context, name, &block).result @result[:groups][name] = group_options.merge(attrs) end def role(name, role_options = {}, &block) name = name.to_s if @result[:roles][name] raise "Role `#{name}` is already defined" end - attrs = Miam::DSL::Context::Role.new(name, &block).result + attrs = Miam::DSL::Context::Role.new(@context, name, &block).result @result[:roles][name] = role_options.merge(attrs) end def instance_profile(name, instance_profile_options = {}, &block) name = name.to_s