Sha256: dddc3984d63c0b4eb7e22b81484c44c2d0b3a8204fa509606426bdbfa06c6511

Contents?: true

Size: 879 Bytes

Versions: 8

Compression:

Stored size: 879 Bytes

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
        has_exec "line_in_#{filepath}" do
          command "grep -q \'#{line.safe_quote}\' #{filepath} || echo \'#{line.safe_quote}\' >> #{filepath}"
          not_if "grep -q \'#{line.safe_quote}\' #{filepath}"
        end
      end
      
      def print_to_chef
        <<-EOE
# line in file: <%= filepath %>
        EOE
      end
      
    end
    
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
auser-poolparty-1.3.0 lib/poolparty/resources/line.rb
auser-poolparty-1.3.1 lib/poolparty/resources/line.rb
auser-poolparty-1.3.2 lib/poolparty/resources/line.rb
auser-poolparty-1.3.3 lib/poolparty/resources/line.rb
auser-poolparty-1.3.4 lib/poolparty/resources/line.rb
poolparty-1.3.4 lib/poolparty/resources/line.rb
poolparty-1.3.3 lib/poolparty/resources/line.rb
poolparty-1.3.1 lib/poolparty/resources/line.rb