Class: Gitrb::Reference

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

Instance Method Summary collapse

Constructor Details

#initialize(properties = {}) ⇒ Reference

Returns a new instance of Reference.



5
6
7
8
# File 'lib/gitrb/reference.rb', line 5

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



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

def method_missing(name, *args, &block)
  if @object
    unless name == :to_ary || name == :to_str
      # Ruby 1.9 uses the presence of the to_ary and to_str methods to determine if an object is coercable.
      # If we create these methods, Ruby will incorrectly think that the object can be converted to an array.
      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]
  elsif object
    method_missing(name, *args, &block)
  else
    super
  end
end

Instance Method Details

#objectObject



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

def object
  @object ||= repository.get(id)
end

#resolved?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/gitrb/reference.rb', line 35

def resolved?
  @object != nil
end