diff --git a/lib/sprinkle/installers/npm.rb b/lib/sprinkle/installers/npm.rb index 102bf58..674f8d0 100644 --- a/lib/sprinkle/installers/npm.rb +++ b/lib/sprinkle/installers/npm.rb @@ -16,8 +16,8 @@ class Npm < Installer attr_accessor :package_name api do - def npm(package, &block) - install Npm.new(self, package, &block) + def npm(package, options={}, &block) + install Npm.new(self, package, options, &block) end end @@ -27,15 +27,15 @@ def has_npm(package) end end - def initialize(parent, package_name, &block) #:nodoc: - super parent, &block + def initialize(parent, package_name, options={}, &block) #:nodoc: + super parent, options, &block @package_name = package_name end protected def install_commands #:nodoc: - "npm install --global #{@package_name}" + "#{sudo_cmd}npm install --global #{@package_name}" end end diff --git a/lib/sprinkle/installers/replace_text.rb b/lib/sprinkle/installers/replace_text.rb index 92f4217..78ac9f6 100644 --- a/lib/sprinkle/installers/replace_text.rb +++ b/lib/sprinkle/installers/replace_text.rb @@ -2,18 +2,20 @@ module Sprinkle module Installers # = Replace text installer # - # This installer replaces a text with another one in a file. - # + # This installer replaces a text matching the regex with another one in a file. + # # == Example Usage # # Change ssh port in /etc/ssh/sshd_config # # package :magic_beans do - # replace_text 'Port 22', 'Port 2500', '/etc/ssh/sshd_config' + # replace_text 'Port [0-9]+', 'Port 2500', '/etc/ssh/sshd_config' # end # + # Because we use sed under the hood, the regex is extended regex. + # # If you user has access to 'sudo' and theres a file that requires - # privileges, you can pass :sudo => true + # privileges, you can pass :sudo => true # # package :magic_beans do # replace_text 'Port 22', 'Port 2500', '/etc/ssh/sshd_config', :sudo => true @@ -25,7 +27,7 @@ module Installers # class ReplaceText < Installer attr_accessor :regex, :text, :path #:nodoc: - + api do def replace_text(regex, text, path, options={}, &block) install ReplaceText.new(self, regex, text, path, options, &block) @@ -38,19 +40,19 @@ def initialize(parent, regex, text, path, options={}, &block) #:nodoc: @text = text @path = path end - + def announce log "--> Replace '#{@regex}' with '#{@text}' in file #{@path}" end protected - + def escape_sed_arg(s) escape_shell_arg(s).gsub("/", "\\\\/").gsub('&', '\\\&') end - + def install_commands #:nodoc: - "#{sudo_cmd}sed -i 's/#{escape_sed_arg(@regex)}/#{escape_sed_arg(@text)}/g' #{@path}" + "#{sudo_cmd}sed -r -i 's/#{escape_sed_arg(@regex)}/#{escape_sed_arg(@text)}/g' #{@path}" end end