class Asgit::Url

Attributes

details[R]
service[R]

Public Class Methods

new(details, service) click to toggle source
# File lib/asgit/url.rb, line 6
def initialize details, service
  @details = details
  @service = service
end

Public Instance Methods

branch(name) click to toggle source
# File lib/asgit/url.rb, line 23
def branch name
  File.join( project, service.branch_uri % { branch: name } )
end
commit(sha) click to toggle source
# File lib/asgit/url.rb, line 19
def commit sha
  File.join( project, service.commit_uri % { commit: sha } )
end
compare(ref_a, ref_b) click to toggle source
# 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={}) click to toggle source
# 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={}) click to toggle source
# 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
project() click to toggle source
# File lib/asgit/url.rb, line 11
def project
  service.base_structure % {
    base_url: service.base_url,
    organization: details.organization,
    project: details.project
  }
end

Private Instance Methods

format_lines(input) click to toggle source
# File lib/asgit/url.rb, line 48
def format_lines input
  if input.respond_to?(:begin) && input.respond_to?(:end)
    return "#L#{input.begin}-L#{input.end}"
  else
    return "#L#{input}"
  end
end