Class: TerraspaceBundler::Mod::Props

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
TB::Util::Logging, Concerns::NotationConcern
Defined in:
lib/terraspace_bundler/mod/props.rb,
lib/terraspace_bundler/mod/props/typer.rb,
lib/terraspace_bundler/mod/props/extension.rb

Defined Under Namespace

Modules: Extension Classes: Typer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::NotationConcern

#clean_notation, #ref, #remove_host, #remove_notations, #remove_ref_notation, #remove_subfolder_notation, #subfolder

Constructor Details

#initialize(params = {}) ⇒ Props

Returns a new instance of Props.



12
13
14
15
16
# File 'lib/terraspace_bundler/mod/props.rb', line 12

def initialize(params={})
  @params = params
  @options = params[:options]
  @source, @version = @options[:source], @options[:version]
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#buildObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/terraspace_bundler/mod/props.rb', line 22

def build
  unless @source
    logger.error "ERROR: The source option must be set for the #{name} mod in the Terrafile".color(:red)
    exit 1
  end
  o = @options.merge(
    name: name,
    type: type,
    url: url,
  )
  o[:subfolder] ||= subfolder(@source)
  o[:ref] ||= ref(@source)
  o
end

#clone_with(url) ⇒ Object

apply clone_with option if set



53
54
55
56
57
58
59
60
61
# File 'lib/terraspace_bundler/mod/props.rb', line 53

def clone_with(url)
  with = @options[:clone_with] || TB.config.clone_with
  return url unless with
  if with == 'https'
    url.sub(/.*@(.*):/,'https://\1/')
  else # git@
    url.sub(%r{http[s]?://(.*?)/},'git@\1:')
  end
end

#git_source_urlObject

git_source_url is normalized

See: stackoverflow.com/questions/6167905/git-clone-through-ssh

ssh://[email protected]/absolute/path/to/repo.git/ - just a forward slash for absolute path on server
[email protected]:relative/path/to/repo.git/ - just a colon (it mustn't have the ssh:// for relative path on server (relative to home dir of username on server machine)

When colon is separator for relative path do not want ssh prepended

git clone ec2-user@localhost:repo

When slash is separator for absolute path want ssh prepended

git clone ssh://ec2-user@localhost/path/to/repo => valid URI


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/terraspace_bundler/mod/props.rb', line 83

def git_source_url
  if @source.include?('http') || @source.include?(':')
    # Examples:
    #   mod "pet1", source: "https://github.com/tongueroo/pet"
    #   mod "pet2", source: "[email protected]:tongueroo/pet"
    #   mod "pet3", source: "[email protected]:tongueroo/pet"
    #   mod "pet4", source: "[email protected]:tongueroo/pet"
    #   mod "example3", source: "git::https://example.com/example-module.git"
    #
    # sub to allow for generic git repo notiation
    source = @source.sub('git::','')
    if source.include?('ssh://')
      if source.count(':') == 1
        return source
      else
        return source.sub('ssh://', '')
      end
    end
    source
  else
    # Examples:
    #   mod "pet", source: "tongueroo/pet"
    # Or:
    #   org "tongueroo"
    #   mod "pet", source: "pet"
    org_source = @source.include?('/') ? @source : "#{TB.config.org}/#{@source}" # adds inferred org
    "#{TB.config.base_clone_url}#{org_source}"
  end
end

#http_source_urlObject



63
64
65
66
# File 'lib/terraspace_bundler/mod/props.rb', line 63

def http_source_url
  source = Http::Source.new(@params)
  source.url
end

#nameObject



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

def name
  remove_notations(@params[:args].first)
end

#registryObject



118
119
120
# File 'lib/terraspace_bundler/mod/props.rb', line 118

def registry
  Registry.new(@source, @version)
end

#typerObject



113
114
115
# File 'lib/terraspace_bundler/mod/props.rb', line 113

def typer
  Typer.new(self)
end

#urlObject

url is normalized



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/terraspace_bundler/mod/props.rb', line 38

def url
  url = case type
        when 'registry'
          registry.github_url
        when 'local'
          source
        when 'http'
          http_source_url
        else # git
          git_source_url
        end
  remove_notations(clone_with(url))
end