Sha256: 697cce0215345d853a9725dd5636a7355fd7fbb6b2d8b304f22dd77c3e9c1b63

Contents?: true

Size: 1.15 KB

Versions: 28

Compression:

Stored size: 1.15 KB

Contents

=begin rdoc
  Gives access to conditional statements
  
  == Usage
    has_case "os" do
      when_is :ubuntu, "git-core"
      else_is "git"
    end
  
  translates to:
  
    case "os"
    when :ubuntu
      "git-core"
    else
      "git"
    end
=end
module PoolParty
  module Resources
    
    class Conditional < Resource
      
      default_options(
        :name => nil
      )
      
      def self.has_method_name
        "case"
      end
      
      # When is
      def when_is(val, output)
        conditions << [val, output]
      end
      
      def else_is(output)
        conditions.push([:else, output])
      end
      
      def conditions
        @conditions ||= []
      end
      
      def print_to_chef
        arr = []
        arr << "case #{print_variable(name)}"
        conditions.each do |cond|
          if cond[0] == :else
            arr << "else"
            arr << "  #{print_variable(cond[1])}"
            break
          else
            arr << "when #{print_variable(cond[0])}"
            arr << "  #{print_variable(cond[1])}"
          end
        end
        arr << "end"
        arr.join("\n")
      end
      
    end
    
  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
auser-poolparty-1.3.0 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.1 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.10 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.11 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.12 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.13 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.14 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.15 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.16 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.17 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.2 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.3 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.4 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.5 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.6 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.7 lib/poolparty/resources/conditional.rb
auser-poolparty-1.3.8 lib/poolparty/resources/conditional.rb
fairchild-poolparty-1.3.17 lib/poolparty/resources/conditional.rb
fairchild-poolparty-1.3.5 lib/poolparty/resources/conditional.rb
poolparty-1.3.15 lib/poolparty/resources/conditional.rb