Class: TerraspaceBundler::Mod

Inherits:
Object
  • Object
show all
Extended by:
Props::Extension
Includes:
Concerns::LocalConcern, Concerns::StackConcern
Defined in:
lib/terraspace_bundler/mod/props.rb,
lib/terraspace_bundler/mod.rb,
lib/terraspace_bundler/mod/fetcher.rb,
lib/terraspace_bundler/mod/registry.rb

Overview

Delegates to:

1. Local
2. Git

Defined Under Namespace

Modules: Concerns, Http Classes: Fetcher, Props, Registry

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Props::Extension

prop

Methods included from Concerns::LocalConcern

#local?

Methods included from Concerns::StackConcern

#all_stacks, #all_stacks?, #array_stacks, #normalize_stacks, #stacks

Constructor Details

#initialize(props = {}) ⇒ Mod

Returns a new instance of Mod.



10
11
12
13
14
# File 'lib/terraspace_bundler/mod.rb', line 10

def initialize(props={})
  @props = props.symbolize_keys
  # These props are used for version comparing by VersionComparer
  @version, @ref, @tag, @branch = @props[:version], @props[:ref], @props[:tag], @props[:branch]
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



9
10
11
# File 'lib/terraspace_bundler/mod.rb', line 9

def branch
  @branch
end

#propsObject (readonly)

Returns the value of attribute props.



9
10
11
# File 'lib/terraspace_bundler/mod.rb', line 9

def props
  @props
end

#refObject (readonly)

Returns the value of attribute ref.



9
10
11
# File 'lib/terraspace_bundler/mod.rb', line 9

def ref
  @ref
end

#tagObject (readonly)

Returns the value of attribute tag.



9
10
11
# File 'lib/terraspace_bundler/mod.rb', line 9

def tag
  @tag
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/terraspace_bundler/mod.rb', line 9

def version
  @version
end

Instance Method Details

#checkout_versionObject

support variety of options, prefer version



17
18
19
# File 'lib/terraspace_bundler/mod.rb', line 17

def checkout_version
  @version || @ref || @tag || @branch
end

#full_repoObject



33
34
35
# File 'lib/terraspace_bundler/mod.rb', line 33

def full_repo
  "#{org}/#{repo}"
end

#latest_shaObject



37
38
39
40
41
# File 'lib/terraspace_bundler/mod.rb', line 37

def latest_sha
  fetcher = Fetcher.new(self).instance
  fetcher.run
  fetcher.sha
end

#orgObject

github.com/tongueroo/pet - 2nd to last word [email protected]:tongueroo/pet - 2nd to last word without chars before :



28
29
30
31
# File 'lib/terraspace_bundler/mod.rb', line 28

def org
  s = url_words[-2] # second to last word
  s.split(':').last # in case of [email protected]:tongueroo/pet form
end

#repoObject

use url instead of source because for registry modules, the repo name is different



22
23
24
# File 'lib/terraspace_bundler/mod.rb', line 22

def repo
  url_words[-1].sub(/\.git$/,'')
end

#vcs_providerObject



43
44
45
46
47
48
49
50
51
# File 'lib/terraspace_bundler/mod.rb', line 43

def vcs_provider
  if url.include?('http')
    # "https://github.com/org/repo"  => github.com
    url.match(%r{http[s]?://(.*?)/})[1]
  else # git@
    # "[email protected]:org/repo"      => github.com
    url.match(%r{git@(.*?):})[1]
  end
end