Class: Asgit::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/asgit/url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(details, service) ⇒ Url

Returns a new instance of Url.



6
7
8
9
# File 'lib/asgit/url.rb', line 6

def initialize details, service
  @details = details
  @service = service
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



4
5
6
# File 'lib/asgit/url.rb', line 4

def details
  @details
end

#serviceObject (readonly)

Returns the value of attribute service.



4
5
6
# File 'lib/asgit/url.rb', line 4

def service
  @service
end

Instance Method Details

#branch(name) ⇒ Object



23
24
25
# File 'lib/asgit/url.rb', line 23

def branch name
  File.join( project, service.branch_uri % { branch: name } )
end

#commit(sha) ⇒ Object



19
20
21
# File 'lib/asgit/url.rb', line 19

def commit sha
  File.join( project, service.commit_uri % { commit: sha } )
end

#compare(ref_a, ref_b) ⇒ Object



42
43
44
# File 'lib/asgit/url.rb', line 42

def compare ref_a, ref_b
  File.join( project, service.compare_uri % { ref_a: ref_a, ref_b: ref_b })
end

#file(file_path, options = {}) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/asgit/url.rb', line 27

def file file_path, options={}
  file_path = file_path.gsub( /^\//, '' )
  branch    = options.fetch(:branch) { details.default_branch }
  line      = options.has_key?(:line) ? format_lines(options[:line]) : ''

  File.join( project, service.file_uri % { file_path: file_path, branch: branch, line: line } )
end

#file_at_commit(file_path, commit, options = {}) ⇒ Object



35
36
37
38
39
40
# File 'lib/asgit/url.rb', line 35

def file_at_commit file_path, commit, options={}
  file_path = file_path.gsub( /^\//, '' )
  line      = options.has_key?(:line) ? format_lines(options[:line]) : ''

  File.join( project, service.file_at_commit_uri % { file_path: file_path, commit: commit, line: line } )
end

#projectObject



11
12
13
14
15
16
17
# File 'lib/asgit/url.rb', line 11

def project
  service.base_structure % {
    base_url: service.base_url,
    organization: details.organization,
    project: details.project
  }
end