Class: R10K::Module::Tarball

Inherits:
Base
  • Object
show all
Includes:
Util::Setopts
Defined in:
lib/r10k/module/tarball.rb

Overview

This class defines a tarball source module implementation

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS, Logging::SYSLOG_LEVELS_MAP

Instance Attribute Summary collapse

Attributes inherited from Base

#dirname, #environment, #name, #origin, #owner, #path, #spec_deletable, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

add_outputters, debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Methods inherited from Base

#accept, #delete_spec_dir, #full_path, #maybe_delete_spec_dir, #should_sync?

Constructor Details

#initialize(name, dirname, opts, environment = nil) ⇒ Tarball

Returns a new instance of Tarball.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/r10k/module/tarball.rb', line 27

def initialize(name, dirname, opts, environment=nil)
  super
  setopts(opts, {
    # Standard option interface
    :source    => :self,
    :version   => :checksum,
    :type      => ::R10K::Util::Setopts::Ignore,
    :overrides => :self,

    # Type-specific options
    :checksum => :self,
  })

  @tarball = R10K::Tarball.new(name, @source, checksum: @checksum)
end

Instance Attribute Details

#tarballObject (readonly)

Returns the value of attribute tarball.



23
24
25
# File 'lib/r10k/module/tarball.rb', line 23

def tarball
  @tarball
end

Class Method Details

.implement?(name, args) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
# File 'lib/r10k/module/tarball.rb', line 10

def self.implement?(name, args)
  args.is_a?(Hash) && args[:type].to_s == 'tarball'
rescue
  false
end

.statically_defined_version(name, args) ⇒ Object



16
17
18
# File 'lib/r10k/module/tarball.rb', line 16

def self.statically_defined_version(name, args)
  args[:version] || args[:checksum]
end

Instance Method Details

#cachedirString

Tarball caches are files, not directories. An important purpose of this method is to indicate where the cache “path” is, for locking/parallelism, so for the Tarball module type, the relevant path location is returned.

Returns:

  • (String)

    The path this module will cache its tarball source to



98
99
100
# File 'lib/r10k/module/tarball.rb', line 98

def cachedir
  tarball.cache_path
end

#propertiesHash

This method is abstract.

Return the properties of the module

Returns:

  • (Hash)


85
86
87
88
89
90
91
# File 'lib/r10k/module/tarball.rb', line 85

def properties
  {
    :expected => version,
    :actual   => ((state = status) == :insync) ? version : state,
    :type     => :tarball,
  }
end

#statusSymbol

Return the status of the currently installed module.

Returns:

  • (Symbol)


46
47
48
49
50
51
52
53
54
# File 'lib/r10k/module/tarball.rb', line 46

def status
  if not path.exist?
    :absent
  elsif not (tarball.cache_valid? && tarball.insync?(path.to_s))
    :mismatched
  else
    :insync
  end
end

#sync(opts = {}) ⇒ Boolean

Synchronize this module with the indicated state.

Parameters:

  • opts (Hash) (defaults to: {})

    Deprecated

Returns:

  • (Boolean)

    true if the module was updated, false otherwise



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/r10k/module/tarball.rb', line 59

def sync(opts={})
  tarball.get unless tarball.cache_valid?
  if should_sync?
    case status
    when :absent
      tarball.unpack(path.to_s)
    when :mismatched
      path.rmtree
      tarball.unpack(path.to_s)
    end
    maybe_delete_spec_dir
    true
  else
    false
  end
end

#versionObject

Return the desired version of this module



77
78
79
# File 'lib/r10k/module/tarball.rb', line 77

def version
  @checksum || '(present)'
end