Module: PoiseLanguages::Static::Mixin::ClassMethods

Included in:
PoiseLanguages::Static::Mixin
Defined in:
lib/poise_languages/static/mixin.rb

Overview

Since:

  • 1.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#static_machinesObject

Since:

  • 1.1.0



62
63
64
# File 'lib/poise_languages/static/mixin.rb', line 62

def static_machines
  @static_machines
end

#static_nameObject

Since:

  • 1.1.0



60
61
62
# File 'lib/poise_languages/static/mixin.rb', line 60

def static_name
  @static_name
end

#static_retriesObject

Since:

  • 1.1.0



65
66
67
# File 'lib/poise_languages/static/mixin.rb', line 65

def static_retries
  @static_retries
end

#static_strip_componentsObject

Since:

  • 1.1.0



64
65
66
# File 'lib/poise_languages/static/mixin.rb', line 64

def static_strip_components
  @static_strip_components
end

#static_urlObject

Since:

  • 1.1.0



63
64
65
# File 'lib/poise_languages/static/mixin.rb', line 63

def static_url
  @static_url
end

#static_versionsObject

Since:

  • 1.1.0



61
62
63
# File 'lib/poise_languages/static/mixin.rb', line 61

def static_versions
  @static_versions
end

Instance Method Details

#default_inversion_options(node, resource) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set some default inversion provider options. Package name can’t get a default value here because that would complicate the handling of system_package_candidates.

Since:

  • 1.1.0



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/poise_languages/static/mixin.rb', line 78

def default_inversion_options(node, resource)
  super.merge({
    # Path to install the package. Defaults to /opt/name-version.
    path: nil,
    # Number of times to retry failed downloads.
    retries: static_retries,
    # Full version number for use in interpolation.
    static_version: static_version(node, resource),
    # Value to pass to tar --strip-components.
    strip_components: static_strip_components,
    # URL template to download from.
    url: static_url,
  })
end

#included(klass) ⇒ Object

Since:

  • 1.1.0



129
130
131
132
# File 'lib/poise_languages/static/mixin.rb', line 129

def included(klass)
  super
  klass.extend ClassMethods
end

#provides_auto?(node, resource) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 1.1.0



67
68
69
70
71
# File 'lib/poise_languages/static/mixin.rb', line 67

def provides_auto?(node, resource)
  # Check that the version starts with our project name and the machine
  # we are on is supported.
  resource.version.to_s =~ /^#{static_name}(-|$)/ && static_machines.include?(static_machine_label_wrapper(node, resource))
end

#static_machine_label(node, _resource = nil) ⇒ Object

Since:

  • 1.1.0



114
115
116
# File 'lib/poise_languages/static/mixin.rb', line 114

def static_machine_label(node, _resource=nil)
  "#{node['kernel']['name'].downcase}-#{node['kernel']['machine']}"
end

#static_machine_label_wrapper(node, resource) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wrapper for #static_machine_label because I need to add an argument. This preserves backwards compat.

Since:

  • 1.1.0



122
123
124
125
126
127
# File 'lib/poise_languages/static/mixin.rb', line 122

def static_machine_label_wrapper(node, resource)
  args = [node]
  arity = method(:static_machine_label).arity
  args << resource if arity > 1 || arity < 0
  static_machine_label(*args)
end

#static_options(name: nil, versions: [], machines: %w{linux-i686 linux-x86_64}, url: nil, strip_components: 1, retries: 5) ⇒ Object

Raises:

Since:

  • 1.1.0



93
94
95
96
97
98
99
100
101
# File 'lib/poise_languages/static/mixin.rb', line 93

def static_options(name: nil, versions: [], machines: %w{linux-i686 linux-x86_64}, url: nil, strip_components: 1, retries: 5)
  raise PoiseLanguages::Error.new("Static archive URL is required, on #{self}") unless url
  self.static_name = name || provides.to_s
  self.static_versions = versions
  self.static_machines = Set.new(machines)
  self.static_url = url
  self.static_strip_components = strip_components
  self.static_retries = retries
end

#static_version(node, resource) ⇒ Object

Since:

  • 1.1.0



103
104
105
106
107
108
109
110
111
112
# File 'lib/poise_languages/static/mixin.rb', line 103

def static_version(node, resource)
  raw_version = resource.version.to_s.gsub(/^#{static_name}(-|$)/, '')
  if static_versions.include?(raw_version)
    raw_version
  else
    # Prefix match or just use the given version number if not found.
    # This allow mild future proofing in some cases.
    static_versions.find {|v| v.start_with?(raw_version) } || raw_version
  end
end