Class: Octopussy::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/octopussy/repo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Repo

Returns a new instance of Repo.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/octopussy/repo.rb', line 5

def initialize(repo)
  if repo.is_a?(String)
    repo = repo.split("/")
    @name = repo.pop
    @username = repo.pop
  elsif repo.is_a?(Repo)
    @username = repo.username
    @name = repo.name
  elsif repo.is_a?(Hash)
    @name = repo[:repo] ||= repo[:name] 
    @username = repo[:username] ||= repo[:user] ||= repo[:owner]
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/octopussy/repo.rb', line 3

def name
  @name
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/octopussy/repo.rb', line 3

def username
  @username
end

Class Method Details

.from_url(url) ⇒ Object



43
44
45
46
47
# File 'lib/octopussy/repo.rb', line 43

def self.from_url(url)
  return if url.nil?
  username, name = url.gsub("http://github.com/", "").split("/")
  Repo.new("#{username}/#{name}")
end

Instance Method Details

#repoObject



35
36
37
# File 'lib/octopussy/repo.rb', line 35

def repo
  @name
end

#slugObject



19
20
21
# File 'lib/octopussy/repo.rb', line 19

def slug
  "#{@username}/#{@name}"
end

#to_sObject



23
24
25
# File 'lib/octopussy/repo.rb', line 23

def to_s
  self.slug
end

#urlObject



27
28
29
# File 'lib/octopussy/repo.rb', line 27

def url
  "http://github.com/#{slug}"
end

#userObject



31
32
33
# File 'lib/octopussy/repo.rb', line 31

def user
  @username
end

#user=(val) ⇒ Object



39
40
41
# File 'lib/octopussy/repo.rb', line 39

def user=(val)
  @username = val
end