Class: Omnijack::Endpoint::Metadata

Inherits:
Omnijack::Endpoint show all
Includes:
Chef::Mixin::ParamsValidate, Config
Defined in:
lib/omnijack/endpoint/metadata.rb

Overview

A class for representing an Omnitruck metadata object

Author:

Constant Summary

Constants inherited from Omnijack

VERSION

Instance Attribute Summary

Attributes inherited from Omnijack

#args, #name

Instance Method Summary collapse

Methods inherited from Omnijack::Endpoint

#[], #base_url, #method_missing

Constructor Details

#initialize(name, args) ⇒ Metadata

Returns a new instance of Metadata.



32
33
34
35
36
37
38
39
40
41
# File 'lib/omnijack/endpoint/metadata.rb', line 32

def initialize(name, args)
  super
  [:platform, :platform_version, :machine_arch].each do |i|
    send(i, args[i])
    args.delete(i)
  end
  args.each { |k, v| send(k, v) unless v.nil? } unless args.nil?
  version(to_h[:version])
  to_h
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Omnijack::Endpoint

Instance Method Details

#mTrueClass, FalseClass

Whether to enable prerelease and/or nightly packages

Parameters:

  • arg (TrueClass, FalseClass, NilClass)

Returns:

  • (TrueClass, FalseClass)


82
83
84
85
86
87
88
89
# File 'lib/omnijack/endpoint/metadata.rb', line 82

[:prerelease, :nightlies].each do |m|
  define_method(m) do |arg = nil|
    set_or_return(m,
                  arg,
                  kind_of: [TrueClass, FalseClass],
                  default: false)
  end
end

#machine_arch(arg = nil) ⇒ String

The machine architecture of the desired platform

Parameters:

  • (String, NilClass)

Returns:

  • (String)


122
123
124
# File 'lib/omnijack/endpoint/metadata.rb', line 122

def machine_arch(arg = nil)
  set_or_return(:machine_arch, arg, kind_of: String, required: true)
end

#platform(arg = nil) ⇒ String

The name of the desired platform

Parameters:

  • (String, NilClass)

Returns:

  • (String)


97
98
99
# File 'lib/omnijack/endpoint/metadata.rb', line 97

def platform(arg = nil)
  set_or_return(:platform, arg, kind_of: String, required: true)
end

#platform_version(arg = nil) ⇒ String

The version of the desired platform

Parameters:

  • arg (String, NilClass) (defaults to: nil)

Returns:

  • (String)


107
108
109
110
111
112
113
114
# File 'lib/omnijack/endpoint/metadata.rb', line 107

def platform_version(arg = nil)
  !arg.nil? && arg = case platform
                     when 'mac_os_x' then platform_version_mac_os_x(arg)
                     when 'windows' then platform_version_windows(arg)
                     else arg
                     end
  set_or_return(:platform_version, arg, kind_of: String, required: true)
end

#to_hHash

Offer a hash representation of the metadata

Returns:

  • (Hash)


55
56
57
58
59
60
61
62
63
64
# File 'lib/omnijack/endpoint/metadata.rb', line 55

def to_h
  raw_data.split("\n").each_with_object({}) do |line, hsh|
    key, val = line.split.entries
    key = key.to_sym
    val = true if val == 'true'
    val = false if val == 'false'
    hsh[key] = val
    key == :url && hsh.merge!(parse_url_data(val))
  end
end

#version(arg = nil) ⇒ String

The version of the project

Parameters:

  • arg (String, NilClass) (defaults to: nil)

Returns:

  • (String)


72
73
74
# File 'lib/omnijack/endpoint/metadata.rb', line 72

def version(arg = nil)
  set_or_return(:version, arg, kind_of: String, default: 'latest')
end