Class: Fuselage::Reference

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

Instance Attribute Summary collapse

Attributes inherited from Base

#api

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

delete_method, get, #initialize, post

Constructor Details

This class inherits a constructor from Fuselage::Base

Instance Attribute Details

#objectObject

Returns the value of attribute object.



4
5
6
# File 'lib/fuselage/reference.rb', line 4

def object
  @object
end

#refObject

Returns the value of attribute ref.



4
5
6
# File 'lib/fuselage/reference.rb', line 4

def ref
  @ref
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/fuselage/reference.rb', line 4

def url
  @url
end

Class Method Details

.create(repo, ref, sha) ⇒ Object



27
28
29
30
31
32
# File 'lib/fuselage/reference.rb', line 27

def self.create(repo, ref, sha)
  raise AuthenticationRequired unless Api.authenticated
  params = {:ref => ref, :sha => sha}
  user = User.current.
  Reference.new(post("/repos/#{user}/#{repo}/git/refs", params))
end

.delete(repo, ref) ⇒ Object



41
42
43
44
45
# File 'lib/fuselage/reference.rb', line 41

def self.delete(repo, ref)
  raise AuthenticationRequired unless Api.authenticated
  user ||= User.current.
  delete_method("/repos/#{user}/#{repo}/git/refs/#{ref}")
end

.find(repo, ref, user = nil) ⇒ Object

Find a reference

ref must have 'heads/' in front of branch name

examples:
  Reference.find('cockpit', 'heads/master')


12
13
14
15
16
# File 'lib/fuselage/reference.rb', line 12

def self.find(repo, ref, user=nil)
  raise AuthenticationRequired unless Api.authenticated
  user ||= User.current.
  Reference.new(get("/repos/#{user}/#{repo}/git/refs/#{ref}"))
end

.find_all(repo, user = nil) ⇒ Object

Finds all the refs for a given repo.



19
20
21
22
23
24
25
# File 'lib/fuselage/reference.rb', line 19

def self.find_all(repo, user=nil)
  raise AuthenticationRequired unless Api.authenticated
  user ||= User.current.
  refs = []
  get("/repos/#{user}/#{repo}/git/refs").each { |r| refs << Reference.new(r) }
  refs
end

.update(repo, ref, sha, force = true, user = nil) ⇒ Object



34
35
36
37
38
39
# File 'lib/fuselage/reference.rb', line 34

def self.update(repo, ref, sha, force=true, user=nil)
  raise AuthenticationRequired unless Api.authenticated
  params = {:force => force, :sha => sha}
  user ||= User.current.
  Reference.new(post("/repos/#{user}/#{repo}/git/refs/#{ref}", params))
end

Instance Method Details

#shaObject



47
48
49
# File 'lib/fuselage/reference.rb', line 47

def sha
  object['sha'] if object
end

#to_sObject



51
52
53
# File 'lib/fuselage/reference.rb', line 51

def to_s
  ref
end