Sha256: 3bd3e48843f7f612e3e67e4c053ef55145a0ce25955b5f8f61d25b53dd587ba9

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

require 'plist'
require 'open-uri'
require 'fileutils'

module BundleMate

  class Bundle
    attr_reader :name
    
    def initialize(bundle_url)
      @url = bundle_url
      @name = File.basename(bundle_url, '.tmbundle')
    end
    
    def installed?
      File.exist?(local_path)
    end
    
    def meta_data(key)
      (@meta_data ||= remote_plist)[key]
    end
    
    def install(revision = 'HEAD')
      system("cd '#{self.class.local_bundle_path}' && svn co -r#{revision} #{remote_url}")
    end
    
    def update
      system("cd '#{local_path}' && svn up")
    end
    
    def uninstall_with_confirmation
      with_confirmation("About to remove #{local_path}.") do
        uninstall
      end
    end
  
    def uninstall
      FileUtils.rm_rf(local_path)
    end
  
    class << self
      attr_accessor :local_bundle_path
      
      def from_macromates(bundle_name)
        new(File.join(BundleMate::MACROMATES_REPOSITORY, bundle_name + '.tmbundle'))
      end
      
      def installed_bundles
        Dir["#{local_bundle_path}/**/*.tmbundle"].map do |bundle_path|
          new(File.basename(bundle_path, '.tmbundle'))
        end
      end
      
      def remote_bundle_list(repository = BundleMate::MACROMATES_REPOSITORY)
        `svn ls #{repository}`.split("\n").map do |bundle|
          bundle_name = bundle.match(/(.*)\.tmbundle\/$/)[1]
        end
      end
    end
    
    private
      def with_confirmation(confirmation_message, &block)
        puts confirmation_message
        print "Proceed? "
        input = $stdin.gets.strip
        yield if input =~ /^(yes|Yes|y|Y)/
      end
    
      def local_path
        File.join(self.class.local_bundle_path, bundle_file_name)
      end
      
      def bundle_file_name
        @name + '.tmbundle'
      end
      
      def remote_plist
        plist_xml = open(File.join(remote_url, 'info.plist')).read
        Plist.parse_xml(plist_xml)
      end
      
      def remote_url
        URI.encode(@url)
      end
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bundlemate-0.1.0 lib/bundle_mate/bundle.rb
bundlemate-0.1.1 lib/bundle_mate/bundle.rb