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
25
# 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

#out_dirObject (readonly)

Returns the value of attribute out_dir.



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

def out_dir
  @out_dir
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)


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

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

#github?Boolean

Returns:

  • (Boolean)


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

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

#originObject



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

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)


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

def private?
  @private
end

#public?Boolean

Returns:

  • (Boolean)


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

def public?
  !@private
end

#urlObject



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

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