Sha256: 6141dea8e8899c7dcd0ed30a0236f0c06446be8c689cbf24ee6f2e1375501c99

Contents?: true

Size: 1.99 KB

Versions: 8

Compression:

Stored size: 1.99 KB

Contents

module Gem
  (class << self; self; end).class_eval do
    def default_attributes
      %w(name version date files executables)
    end
    
    def set_root(root)
      @root = File.expand_path(root)
      @name = File.basename(@root)
      @conf ||= YAML.load File.read("#{@root}/gem.yml")
      @attributes ||= (default_attributes + @conf.keys.map(&:to_s)).uniq
    end
    
    # attr_reader :root, :conf, :attributes, 
    attr_reader :name

    def attribute(name)
      if @conf.key?(name) && !%w(dependencies).include?(name)
        @conf[name]
      else
        self.send(name)
      end
    end

    #
    # create a new Gem::Specification object for this gem.
    def spec(root)
      self.set_root root
    
      Gem::Specification.new do |s|
        @attributes.each do |attr|
          v = attribute(attr)
          next if v.nil?
          
          log attr, v
          
          s.send attr + "=", v
        end
        
        %w(pre_uninstall post_install).each do |hook|
          next unless File.exists?("#{root}/hooks/#{hook}.rb")
          log hook, "yes"
          Gem.send(hook) {
            load "hooks/#{hook}.rb"
          }
        end
      end
    end
    
    def log(attr, v)
      v = case attr
      when "files" then "#{v.length} files"
      else              v.inspect
      end
      
      STDERR.puts "#{"%20s" % attr}:\t#{v}"
    end
    
    def dependencies
      return nil unless @conf["dependencies"]

      @conf["dependencies"].map do |d|
        Gem::Dependency.new d, ">= 0"
      end
    end
    
    def head(file)
      File.open(file) do |f|
        f.readline
      end
    end
    
    def executables
      r = Dir.glob("#{@root}/bin/**/*").map do |file|
        next unless head(file) =~ /^#!/
        file[@root.length + 5 .. -1]
      end.compact
      
      return nil if r.empty?
      r
    end

    #
    # get files from git
    def files
      r = `git ls-files`.split("\n")
    end

    #
    # return the date
    def date
      Date.today.to_s
    end
  end
end

Version data entries

8 entries across 8 versions & 6 rubygems

Version Path
vex-0.6.2 vex/gem.rb
rack-mason-0.1.2 vex/gem.rb
cached-0.2 vex/gem.rb
dlog-0.2.3 vex/gem.rb
etest-0.6.0 vex/gem.rb
dispaaro-couch-0.1 vex/gem.rb
dlog-0.2.1 vex/gem.rb
dlog-0.2 vex/gem.rb