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

#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_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