Class: Gitrb::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/gitrb/reference.rb

Overview

Reference to GitObject to support lazy-loading of git-objects

Instance Method Summary collapse

Constructor Details

#initialize(properties = {}) ⇒ Reference

Returns a new instance of Reference.



7
8
9
10
# File 'lib/gitrb/reference.rb', line 7

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitrb/reference.rb', line 12

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

Instance Method Details

#resolved?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/gitrb/reference.rb', line 30

def resolved?
  @object != nil
end