Class: R10kDiff::PuppetModule

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, ref: nil, git: nil, forge: nil) ⇒ PuppetModule

Returns a new instance of PuppetModule.



26
27
28
29
30
31
# File 'lib/r10kdiff.rb', line 26

def initialize(name, ref:nil, git:nil, forge:nil)
  @name = name
  @ref = ref
  @git = git
  @forge = forge
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



32
33
34
# File 'lib/r10kdiff.rb', line 32

def name
  @name
end

#refObject (readonly)

Returns the value of attribute ref.



32
33
34
# File 'lib/r10kdiff.rb', line 32

def ref
  @ref
end

Instance Method Details

#different?(other_module) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/r10kdiff.rb', line 38

def different?(other_module)
  # Note that forge & git r10k modules have different naming convention so
  # we don't need to compare url (forge is user/modulename and git is just
  # modulename with :git attr as the url of the module
  @ref != other_module.ref
end

#git?Boolean

Returns:

  • (Boolean)


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

def git?
  !!@git
end

#git_httpsObject



69
70
71
72
73
74
75
76
77
# File 'lib/r10kdiff.rb', line 69

def git_https
  if @git.start_with? "https://"
    return @git
  elsif @git.start_with? "git://"
    return @git.gsub(/^git:/, "https:")
  elsif @git.start_with? "git@"
    return @git.gsub(":", "/").gsub(/^git@/, "https://").gsub(/.git$/, "")
  end
end

#pretty_version(include_url) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/r10kdiff.rb', line 59

def pretty_version(include_url)
  basic_string = "#{name} at #{ref}"
  if include_url
    return "#{basic_string} (#{web_url})"
  else
    return basic_string
  end

end

#pretty_version_diff(other_module, include_url) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/r10kdiff.rb', line 45

def pretty_version_diff(other_module, include_url)
  basic_compare = "#{ref} -> #{other_module.ref}"

  # special case for github - generate compate url
  if git? && other_module.git? && include_url
    return "#{name} #{git_https}/compare/#{ref}...#{other_module.ref}"

  elsif include_url
    return "#{name} #{basic_compare} (#{web_url})"
  else
    return "#{name} #{basic_compare}"
  end
end

#web_urlObject



79
80
81
# File 'lib/r10kdiff.rb', line 79

def web_url
  return git? ? git_https : @forge
end