Sha256: 706943fabd7771cd9273d4c756f6f9379c27c45c9ac13139e41dedc1505902a6

Contents?: true

Size: 928 Bytes

Versions: 4

Compression:

Stored size: 928 Bytes

Contents

module Gitrb

  # Reference to GitObject to support lazy-loading of git-objects
  class Reference
    undef_method :id, :type rescue nil

    def initialize(properties = {})
      @properties = properties
      @object = nil
    end

    def method_missing(name, *args, &block)
      if @object
        if @object.respond_to? name
          instance_eval %{def self.#{name}(*args, &block); @object.send("#{name}", *args, &block); end}
        end
        @object.send(name, *args, &block)
      elsif name == :type && (mode = @properties['mode'] || @properties[:mode])
        (mode & 040000 == 040000) ? :tree : :blob
      elsif @properties.include?(name)
        @properties[name]
      elsif @properties.include?(name.to_s)
        @properties[name.to_s]
      else
        @object = repository.get(id)
        method_missing(name, *args, &block)
      end
    end

    def resolved?
      @object != nil
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gitrb-0.2.8 lib/gitrb/reference.rb
gitrb-0.2.7 lib/gitrb/reference.rb
gitrb-0.2.6 lib/gitrb/reference.rb
gitrb-0.2.5 lib/gitrb/reference.rb