Sha256: 83f8267fdf02547d8f369e3de3dba41c7a389c3c3270d2fc7c451d50f62a9f7f

Contents?: true

Size: 1.36 KB

Versions: 9

Compression:

Stored size: 1.36 KB

Contents

module Sprinkle
  module Installers
    # Beware, strange "installer" coming your way.
    #
    # = Text configuration installer
    #
    # This installer pushes simple configuration into a file.
    # 
    # == Example Usage
    #
    # Installing magic_beans into apache2.conf
    #
    #   package :magic_beans do
    #     push_text 'magic_beans', '/etc/apache2/apache2.conf'
    #   end
    #
    # If you user has access to 'sudo' and theres a file that requires
    # priveledges, you can pass :sudo => true 
    #
    #   package :magic_beans do
    #     push_text 'magic_beans', '/etc/apache2/apache2.conf', :sudo => true
    #   end
    #
    # A special verify step exists for this very installer
    # its known as file_contains, it will test that a file indeed
    # contains a substring that you send it.
    #
    class PushText < Installer
      attr_accessor :text, :path #:nodoc:

      def initialize(parent, text, path, options={}, &block) #:nodoc:
        super parent, options, &block
        @text = text
        @path = path
      end

      protected

        def install_commands #:nodoc:
          "#{"#{'sudo ' if option?(:sudo)}grep \"^#{@text.gsub("'", "'\\\\''").gsub("\n", '\n')}$\" #{@path} ||" if option?(:idempotent) }/bin/echo -e '#{@text.gsub("'", "'\\\\''").gsub("\n", '\n')}' |#{'sudo ' if option?(:sudo)}tee -a #{@path}"
        end

    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
sprinkle-0.4.2 lib/sprinkle/installers/push_text.rb
sprinkle-0.4.1 lib/sprinkle/installers/push_text.rb
sprinkle-0.4.0 lib/sprinkle/installers/push_text.rb
sprinkle-0.3.6 lib/sprinkle/installers/push_text.rb
sprinkle-0.3.5 lib/sprinkle/installers/push_text.rb
dhill-sprinkle-0.3.3.1 lib/sprinkle/installers/push_text.rb
sprinkle-0.3.4 lib/sprinkle/installers/push_text.rb
sprinkle-0.3.3 lib/sprinkle/installers/push_text.rb
sprinkle-0.3.2 lib/sprinkle/installers/push_text.rb