Sha256: a331400b327c386be0075be83fae7aaf6f888a1aae63297fc0cbde4c7793b197

Contents?: true

Size: 1.52 KB

Versions: 18

Compression:

Stored size: 1.52 KB

Contents

=begin rdoc


== Line in File

Ensures that the line given is in the file

== Usage

  has_line_in_file('line', '/full/file/path.ext')

== Examples

  has_line_in_file("ENABLED=1", "/etc/default/haproxy")
=end
module PoolParty
  module Resources
    
    class Line < Resource
      
      default_options(
        :file => nil,
        :line => ""
      )
      
      def self.has_method_name
        "line_in_file"
      end
      
      def filepath
        file || name
      end
      
      def after_loaded
        opts = if exists?
          {:command => "grep -q \'#{line.safe_quote}\' #{filepath} || echo \'#{line.safe_quote}\' >> #{filepath}",
          :not_if => "grep -q \'#{line.safe_quote}\' #{filepath}"}
        else
          {:command => "cat #{filepath} | grep -v \'#{line.safe_quote}\' > tempfile && mv tempfile #{filepath}",
          :only_if => "grep -q \'#{line.safe_quote}\' #{filepath}"}
        end
        
        opts.merge!(:name => exists? ? "line in #{filepath}" : "no line in #{filepath}")
        
        e = has_exec opts
        
        # Not incredibly pretty. 
        # {:file => [["pool_name", :reload]]}
        # TODO: Find an alternative
        e.meta_notifies = meta_notifies if meta_notifies
        e.meta_subscribes = meta_subscribes if meta_subscribes
        
        # TODO: Figure out better solution
        deps = @dependencies
        e.instance_eval do
          @dependencies = deps
        end
      end
      
      def print_to_chef
        :no_print
      end
      
    end
    
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
auser-poolparty-1.3.10 lib/poolparty/resources/line.rb
auser-poolparty-1.3.11 lib/poolparty/resources/line.rb
auser-poolparty-1.3.12 lib/poolparty/resources/line.rb
auser-poolparty-1.3.13 lib/poolparty/resources/line.rb
auser-poolparty-1.3.14 lib/poolparty/resources/line.rb
auser-poolparty-1.3.15 lib/poolparty/resources/line.rb
auser-poolparty-1.3.16 lib/poolparty/resources/line.rb
auser-poolparty-1.3.17 lib/poolparty/resources/line.rb
auser-poolparty-1.3.6 lib/poolparty/resources/line.rb
auser-poolparty-1.3.7 lib/poolparty/resources/line.rb
auser-poolparty-1.3.8 lib/poolparty/resources/line.rb
fairchild-poolparty-1.3.17 lib/poolparty/resources/line.rb
poolparty-1.3.15 lib/poolparty/resources/line.rb
poolparty-1.3.14 lib/poolparty/resources/line.rb
poolparty-1.3.13 lib/poolparty/resources/line.rb
poolparty-1.3.8 lib/poolparty/resources/line.rb
poolparty-1.3.7 lib/poolparty/resources/line.rb
poolparty-1.3.6 lib/poolparty/resources/line.rb