class Omnijack::Endpoint::Metadata
A class for representing an Omnitruck metadata object
@author Jonathan Hartman <j@p4nt5.com>
Public Class Methods
Omnijack::Endpoint::new
# 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
Public Instance Methods
The machine architecture of the desired platform
@param [String, NilClass] @return [String]
# 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
The name of the desired platform
@param [String, NilClass] @return [String]
# File lib/omnijack/endpoint/metadata.rb, line 97 def platform(arg = nil) set_or_return(:platform, arg, kind_of: String, required: true) end
The version of the desired platform
@param [String, NilClass] arg @return [String]
# 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
Offer a hash representation of the metadata
@return [Hash]
# 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
The version of the project
@param [String, NilClass] arg @return [String]
# File lib/omnijack/endpoint/metadata.rb, line 72 def version(arg = nil) set_or_return(:version, arg, kind_of: String, default: 'latest') end
Private Instance Methods
Construct the full API query URL from base + endpoint + params
@return [URI::HTTP, URI::HTTPS]
# File lib/omnijack/endpoint/metadata.rb, line 133 def api_url @api_url ||= URI.parse("#{super}?#{URI.encode_www_form(query_params)}") end
Extract a filename, package version, and build from a package URL
@param [String] url @return [[String] filename, [String] version, [String] build]
# File lib/omnijack/endpoint/metadata.rb, line 179 def parse_url_data(url) filename = URI.decode(url).split('/')[-1] { filename: filename, version: filename.split('-')[-2].split('_')[-1], build: filename.split('-')[-1].split('.')[0].split('_')[0] } end
Apply special logic for the version of an OS X platform
@param [String] arg @return [String]
# File lib/omnijack/endpoint/metadata.rb, line 153 def platform_version_mac_os_x(arg) arg.match(/^[0-9]+\.[0-9]+/).to_s end
Apply special logic for the version of a Windows platform
@param [String] arg @return [String]
# File lib/omnijack/endpoint/metadata.rb, line 163 def platform_version_windows(arg) # Make a best guess and assume a server OS # See: http://msdn.microsoft.com/en-us/library/windows/ # desktop/ms724832(v=vs.85).aspx { '6.3' => '2012r2', '6.2' => '2012', '6.1' => '2008r2', '6.0' => '2008', '5.2' => '2003r2', '5.1' => 'xp', '5.0' => '2000' }[arg.match(/^[0-9]+\.[0-9]+/).to_s] end
Convert all the metadata attrs into params Omnitruck understands
@return [Hash]
# File lib/omnijack/endpoint/metadata.rb, line 142 def query_params { v: version, prerelease: prerelease, nightlies: nightlies, p: platform, pv: platform_version, m: machine_arch } end