lib/sprinkle/installers/source.rb in lachlan-sprinkle-0.0.14 vs lib/sprinkle/installers/source.rb in lachlan-sprinkle-0.0.15

- old
+ new

@@ -44,20 +44,30 @@ # Third, specifying some hooks: # # package :magic_beans do # source 'http://magicbeansland.com/latest-1.1.1.tar.gz' do # prefix '/usr/local' - # + # # pre :prepare { 'echo "Here we go folks."' } # post :extract { 'echo "I believe..."' } # pre :build { 'echo "Cross your fingers!"' } # end # end # + # Fourth, specifying a custom archive name because the downloaded file name + # differs from the source URL: + # + # package :gitosis do + # source 'http://github.com/crafterm/sprinkle/tarball/master' do + # custom_archive 'crafterm-sprinkle-518e33c835986c03ec7ae8ea88c657443b006f28.tar.gz' + # end + # end + # # As you can see, setting options is as simple as creating a # block and calling the option as a method with the value as # its parameter. + class Source < Installer attr_accessor :source #:nodoc: def initialize(parent, source, options = {}, &block) #:nodoc: @source = source @@ -141,11 +151,11 @@ def create_options(key, prefix) #:nodoc: @options[key].inject(' ') { |m, option| m << "#{prefix}-#{option} "; m } end def extract_command #:nodoc: - case @source + case archive_name when /(tar.gz)|(tgz)$/ 'tar xzf' when /(tar.bz2)|(tb2)$/ 'tar xjf' when /tar$/ @@ -156,24 +166,24 @@ raise "Unknown source archive format: #{archive_name}" end end def archive_name #:nodoc: - name = @source.split('/').last + name = @options[:custom_archive] || @source.split('/').last raise "Unable to determine archive name for source: #{source}, please update code knowledge" unless name name end def build_dir #:nodoc: "#{@options[:builds]}/#{options[:custom_dir] || base_dir}" end def base_dir #:nodoc: - if @source.split('/').last =~ /(.*)\.(tar\.gz|tgz|tar\.bz2|tb2)/ + if archive_name.split('/').last =~ /(.*)\.(tar\.gz|tgz|tar\.bz2|tar|tb2)/ return $1 end raise "Unknown base path for source archive: #{@source}, please update code knowledge" end - + end end end