Class: Nugem::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/nugem/repository.rb

Defined Under Namespace

Classes: Host

Constant Summary collapse

HOSTS =
[
  Host.new(domain: 'github.com',    camel_case: 'GitHub',    id: :github),
  Host.new(domain: 'bitbucket.org', camel_case: 'BitBucket', id: :bitbucket),
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Repository

Returns a new instance of Repository.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/nugem/repository.rb', line 12

def initialize(options)
  @host = HOSTS.find { |host| host.id == options[:host] }
  @private = options[:private]
  @name = options[:name]
  @user = options[:user]
  @global_config = Rugged::Config.global
  abort 'Git global config not found' if @global_config.nil?

  @user_name  = @global_config['user.name']
  @user_email = @global_config['user.email']
  @gem_server_url = options[:gem_server_url]
  @private = options[:private]
end

Instance Attribute Details

#gem_server_urlObject (readonly)

Returns the value of attribute gem_server_url.



4
5
6
# File 'lib/nugem/repository.rb', line 4

def gem_server_url
  @gem_server_url
end

#global_configObject (readonly)

Returns the value of attribute global_config.



4
5
6
# File 'lib/nugem/repository.rb', line 4

def global_config
  @global_config
end

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/nugem/repository.rb', line 4

def host
  @host
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/nugem/repository.rb', line 4

def name
  @name
end

#privateObject (readonly)

Returns the value of attribute private.



4
5
6
# File 'lib/nugem/repository.rb', line 4

def private
  @private
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'lib/nugem/repository.rb', line 4

def user
  @user
end

#user_emailObject (readonly)

Returns the value of attribute user_email.



4
5
6
# File 'lib/nugem/repository.rb', line 4

def user_email
  @user_email
end

#user_nameObject (readonly)

Returns the value of attribute user_name.



4
5
6
# File 'lib/nugem/repository.rb', line 4

def user_name
  @user_name
end

Instance Method Details

#bitbucket?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/nugem/repository.rb', line 26

def bitbucket?
  @host.id == :bitbucket
end

#github?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/nugem/repository.rb', line 30

def github?
  @host.id == :github
end

#originObject



34
35
36
# File 'lib/nugem/repository.rb', line 34

def origin
  "git@#{@host.domain}:#{@user}/#{@name}.git"
end

#private?Boolean

TODO: Currently all private repositories are on BitBucket and all public repos are on GitHub TODO: Drop BitBucket? TODO: Support private repos on GitHub

Returns:

  • (Boolean)


41
42
43
# File 'lib/nugem/repository.rb', line 41

def private?
  @private
end

#public?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/nugem/repository.rb', line 45

def public?
  !@private
end

#urlObject



49
50
51
# File 'lib/nugem/repository.rb', line 49

def url
  "https://#{@host.domain}/#{@user}/#{@name}"
end