class Nova::Common::Metadata::Data

The data from the definition of the metadata in the star. This is what the block is run in an instance of.

Attributes

data[R]

The data contained in this class.

@return [Hash<Symbol, Object>]

Public Class Methods

new() click to toggle source

Initialize the data class.

# File lib/nova/common/metadata/data.rb, line 15
def initialize
  @data = {
    :rubys => [],
    :platforms => [],
    :stars => [],
    :required_options => [],
    :version => Gem::Version.new("0.0.0") }
end

Public Instance Methods

require_option(*options)
Alias for: requires_option
require_options(*options)
Alias for: requires_options
requires_option(*options) click to toggle source

The options that are required by this star.

@param options [Symbol] the option that is required. @return [void]

# File lib/nova/common/metadata/data.rb, line 78
def requires_option(*options)
  data[:required_options].push(*[options].flatten)
end
Also aliased as: requires_options, require_option
requires_options(*options)
Also aliased as: require_options
Alias for: requires_option
validate!(remote) click to toggle source

Validates the current platform, to make sure that the running ruby version and the platform name and version match those required by this star.

@return [void]

# File lib/nova/common/metadata/data.rb, line 100
def validate!(remote)
  check_against :ruby do |ruby|
    if [:all, :any].include? ruby[:name]
      ruby[:version].satisfied_by?(
        Gem::Version.new(RUBY_VERSION))
    else
      ruby[:name] == RUBY_ENGINE.downcase.intern &&
        ruby[:version] == ruby_version
    end
  end

  version = Gem::Version.new remote.platform.version || "0.0.0"

  check_against :platform do |platform|
    remote.platforms.include?(platform[:name]) &&
      platform[:version] == version
  end
end
validate_options!(options) click to toggle source

Validates the given options, making sure that the options contain the required options for the star.

@return [void]

# File lib/nova/common/metadata/data.rb, line 123
def validate_options!(options)
  keys = options.keys

  unless (data[:required_options].map(&:to_s) - keys).empty?
    raise InvalidOptionsError, "Missing options " +
      "#{(data[:required_options] - keys).join(', ')}"
  end
end
version=(version) click to toggle source

Sets the version of the current star.

@see Gem::Version @param version [String] the version of the star. @return [void]

# File lib/nova/common/metadata/data.rb, line 91
def version=(version)
  data[:version] = Gem::Version.new(version)
end

Private Instance Methods

check_against(what, &block) click to toggle source

Checks the given type against the block. Injects the type’s array with false, and calls the block, trying to see if any element in the type’s array makes the block return true. If none of them do, it raises an error, unless there’s no element in the type’s array.

@param what [Symbol] the type. Normally :ruby or

+:platform+.

@yield [Hash] the object to check. @raise [NoPlatformError] if none of the yields give true. @return [void]

# File lib/nova/common/metadata/data.rb, line 145
def check_against(what, &block)
  result = data[:"#{what}s"].inject(false) do |v, obj|
    v || block.call(obj)
  end

  unless result || data[:"#{what}s"].empty?
    raise NoPlatformError, "Could not match any version " +
    "of #{what}s."
  end
end
ruby_version() click to toggle source

Returns the most relevant ruby version there is.

@return [Gem::Version]

# File lib/nova/common/metadata/data.rb, line 159
def ruby_version
  Gem::Version.new case RUBY_ENGINE
  when "jruby"
    JRUBY_VERSION
  else
    RUBY_VERSION
  end
end