lib/poolparty/modules/resourcing_dsl.rb in auser-poolparty-1.0.0 vs lib/poolparty/modules/resourcing_dsl.rb in auser-poolparty-1.1.1

- old
+ new

@@ -1,69 +1,74 @@ module PoolParty module ResourcingDsl # Overrides for syntax # Allows us to send require to require a resource - def require(str="") - str ? options.merge!(:require => str) : options[:require] - end def requires(str=nil) - # str ? options.append!(:require => str) : options[:require] - str ? options.append!(:require => send_if_method(str)) : options[:require] - end + str ? dsl_options.merge!(:require => send_if_method(str)) : dsl_options[:require] + end + def on_change(str=nil) + str ? dsl_options.merge!(:notify => send_if_method(str)) : dsl_options[:notify] + end def ensures(str="running") - # if %w(absent running).map {|a| self.send a.to_sym}.include?(str) - str == "absent" ? is_absent : is_present - # else - # options.append!(:ensure => str) - # end - # str + str == :absent ? is_absent : is_present end + def present + "present" + end + def absent + "absent" + end # Allows us to send an ensure to ensure the presence of a resource def is_present(*args) - options.merge!(:ensure => present) + dsl_options.merge!(:ensures => present) + present end # Ensures that what we are sending is absent def is_absent(*args) - options.merge!(:ensure => absent) + dsl_options.merge!(:ensures => absent) + absent end # Alias for unless def ifnot(str="") - options.merge!(:unless => str) + dsl_options.merge!(:unless => str) end - def present - "present" - end - def absent - "absent" - end def cancel(*args) - options[:cancelled] = args.empty? ? true : args[0] + dsl_options[:cancelled] = args.empty? ? true : args[0] end def cancelled? - options[:cancelled] || false + dsl_options[:cancelled] || false end def printed(*args) - options[:printed] = true + dsl_options[:printed] = true end def printed? - options[:printed] || false + dsl_options[:printed] || false end - # Give us a template to work with on the resource - # Make sure this template is moved to the tmp directory as well - # - # TODO: Change this method to store the template files for later - # copying to prevent unnecessary copying and tons of directories - # everywhere - def template(file, opts={}) - raise TemplateNotFound.new("no template given") unless file - raise TemplateNotFound.new("template cannot be found #{file}") unless ::File.file?(file) - - unless opts[:just_copy] - options.merge!({:content => "template(\"#{::File.basename(file)}\")"}) - options.delete(:source) if options.has_key?(:source) - copy_template_to_storage_directory(file) + + #TODO: Diet + def render_template + # @templates. + end + + def get_client_or_gem_template(file) + if ::File.file?(file) && ::File.readable?(file) + file + elsif client_templates_directory_exists? && client_template_exists?(file) + vputs "using custom template #{::File.join(Dir.pwd, "templates/#{file}")}" + ::File.join(Dir.pwd, "templates/#{file}") else - copy_file_to_storage_directory(file) + vputs "using standard template: #{::File.join(::File.dirname(__FILE__), "..", "templates/#{file}")}" + ::File.join(::File.dirname(__FILE__), "..", "templates/#{file}") end + end + + def client_templates_directory_exists? + ::File.directory?("#{Dir.pwd}/templates") + end + + def client_template_exists?(filename) + return true if ::File.file?(filename) && ::File.readable?(filename) + file = ::File.join("#{Dir.pwd}/templates", filename) + ::File.file?(file) && ::File.readable?(file) end end end \ No newline at end of file