Sha256: 35db6032b9179e26ba47637583d96713236dd8da909e1d91603aefb6f5f924b8

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 KB

Contents

module PoolParty    
  module Resources
    
    def execute_if(attr_s="$hostname", str="", parent=self, &block)
      parent = parent.is_a?(PoolParty::Cloud::Cloud) ? parent : parent.parent
      opts = {:attribute => attr_s, :equal => str}
      options = parent.respond_to?(:options) ? parent.options.merge!(opts) : opts
      @c = PoolParty::Resources::Conditional.new(options, parent, &block)
      parent.instance_eval {add_resource(:conditional, options, parent, &block) }
      @c
    end
    
    class Conditional < Resource
      
      def initialize(opts={}, parent=self, &block)
        name "#{opts[:attribute]} == #{opts[:equal]}"
        attribute opts[:attribute]
        equal opts[:equal]
        super
      end
      
      # This way, we only get other resources, and not the conditional
      # itself as a resource
      def virtual_resource?
        true
      end
      
      def to_string(prev="")
        returning Array.new do |output|
          output << "# #{name.sanitize}"
          output << "case #{attribute} {"
          output << "#{equal} : { #{resources_string_from_resources(resources)} }"
          output << "default : {}"
          output << "}"
        end.join("\n")
      end
      
    end
    
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
auser-poolparty-0.2.3 lib/poolparty/pool/resources/conditional.rb
auser-poolparty-0.2.4 lib/poolparty/pool/resources/conditional.rb
auser-poolparty-0.2.5 lib/poolparty/pool/resources/conditional.rb
auser-poolparty-0.2.6 lib/poolparty/pool/resources/conditional.rb
auser-poolparty-0.2.8 lib/poolparty/pool/resources/conditional.rb
auser-poolparty-0.2.9 lib/poolparty/pool/resources/conditional.rb
poolparty-0.2.6 lib/poolparty/pool/resources/conditional.rb