Class: GitRemote

Inherits:
Object
  • Object
show all
Defined in:
lib/pimpmychangelog/git_remote.rb

Constant Summary collapse

REPOSITORY_PATTERN =
%r{
  # Define recurring patterns
  (?<part> [\w\d-]+ ){0}

  (?<user>\g<part>)/(?<repo>\g<part>)(.git)?$
}x

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = nil) ⇒ GitRemote

Returns a new instance of GitRemote.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pimpmychangelog/git_remote.rb', line 10

def initialize(url = nil)
  @url = url || fetch_url

  match = @url.match(REPOSITORY_PATTERN)

  @user = match[:user]
  @project = match[:repo]

  unless @user && @project
    raise "Can't extract github user and project from origin remote"
  end
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



23
24
25
# File 'lib/pimpmychangelog/git_remote.rb', line 23

def project
  @project
end

#userObject (readonly)

Returns the value of attribute user.



23
24
25
# File 'lib/pimpmychangelog/git_remote.rb', line 23

def user
  @user
end