Class: InchCI::ProjectUID

Inherits:
Object
  • Object
show all
Defined in:
lib/inch_ci/project_uid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params_or_uid) ⇒ ProjectUID

Returns a new instance of ProjectUID.


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/inch_ci/project_uid.rb', line 5

def initialize(params_or_uid)
  if params_or_uid.is_a?(Hash)
    @service = params_or_uid[:service]
    @user_name = params_or_uid[:user]
    @repo_name = params_or_uid[:repo]
  else
    service_and_nwo = params_or_uid.split(':')
    @service = service_and_nwo.first
    nwo = service_and_nwo.last.split('/')
    if nwo.size == 2
      @user_name = nwo.first
      @repo_name = nwo.last
    end
  end
end

Instance Attribute Details

#repo_nameObject (readonly)

Returns the value of attribute repo_name


3
4
5
# File 'lib/inch_ci/project_uid.rb', line 3

def repo_name
  @repo_name
end

#serviceObject (readonly)

Returns the value of attribute service


3
4
5
# File 'lib/inch_ci/project_uid.rb', line 3

def service
  @service
end

#user_nameObject (readonly)

Returns the value of attribute user_name


3
4
5
# File 'lib/inch_ci/project_uid.rb', line 3

def user_name
  @user_name
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'lib/inch_ci/project_uid.rb', line 21

def blank?
  service.to_s.empty? || user_name.to_s.empty? || repo_name.to_s.empty?
end

#project_uidObject


25
26
27
28
# File 'lib/inch_ci/project_uid.rb', line 25

def project_uid
  return if blank?
  "#{service}:#{user_name}/#{repo_name}"
end

#repo_urlObject


30
31
32
33
34
35
36
37
# File 'lib/inch_ci/project_uid.rb', line 30

def repo_url
  return if blank?
  if service == 'github'
    "https://github.com/#{user_name}/#{repo_name}.git"
  else
    raise "Unknown service: #{service}"
  end
end