Class: Regrit::Ref

Inherits:
Object
  • Object
show all
Defined in:
lib/regrit/ref.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, ref) ⇒ Ref

Returns a new instance of Ref.

Raises:



3
4
5
6
7
8
# File 'lib/regrit/ref.rb', line 3

def initialize(repo, ref)
  @repo = repo
  @commit, @full_name = ref.split(/\t/)
  @type, @name = @full_name.scan(%r#refs/([^/]+)/(.+)#).first || [nil, @full_name]
  raise InvalidRefsFormat.new(ref) if @name.nil?
end

Instance Attribute Details

#commitObject (readonly)

Returns the value of attribute commit.



10
11
12
# File 'lib/regrit/ref.rb', line 10

def commit
  @commit
end

#full_nameObject (readonly)

Returns the value of attribute full_name.



10
11
12
# File 'lib/regrit/ref.rb', line 10

def full_name
  @full_name
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/regrit/ref.rb', line 10

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/regrit/ref.rb', line 10

def type
  @type
end

Instance Method Details

#abbrev_commitObject



20
21
22
# File 'lib/regrit/ref.rb', line 20

def abbrev_commit
  commit[0...7]
end

#branch?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/regrit/ref.rb', line 16

def branch?
  type == 'heads'
end

#match?(named) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/regrit/ref.rb', line 24

def match?(named)
  name == named || full_name == named || [type,name].compact.join('/') == named
end

#tag?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/regrit/ref.rb', line 12

def tag?
  type == 'tags'
end