Class: Nova::Common::Metadata::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/nova/common/metadata/data.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeData

Initialize the data class.



15
16
17
18
19
20
21
22
# 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

Instance Attribute Details

#dataHash<Symbol, Object> (readonly)

The data contained in this class.

Returns:

  • (Hash<Symbol, Object>)


12
13
14
# File 'lib/nova/common/metadata/data.rb', line 12

def data
  @data
end

Instance Method Details

#requires_option(*options) ⇒ void Also known as: requires_options, require_option

This method returns an undefined value.

The options that are required by this star.

Parameters:

  • options (Symbol)

    the option that is required.



78
79
80
# File 'lib/nova/common/metadata/data.rb', line 78

def requires_option(*options)
  data[:required_options].push(*[options].flatten)
end

#requires_platform(name, *versions) ⇒ void Also known as: require_platform, requires_platforms, require_platforms

This method returns an undefined value.

The platform version requirement. Each call to this method adds a platform that can be used, and the versions that are required for that platform. :all represents all platforms.

Parameters:

  • name (Symbol)

    the name of the platform.

  • versions (String)

    the versions of that platform this star is compatible with.

See Also:

  • Gem::Requirement


63
64
65
66
67
68
69
70
71
72
# File 'lib/nova/common/metadata/data.rb', line 63

[:ruby, :platform, :star].each do |type|
  define_method(:"requires_#{type}") do |p, *versions|
    data[:"#{type}s"].push(:name => p, :version =>
      Gem::Requirement.new(*[versions].flatten))
  end

  alias_method :"require_#{type}", :"requires_#{type}"
  alias_method :"requires_#{type}s", :"requires_#{type}"
  alias_method :"require_#{type}s", :"requires_#{type}"
end

#requires_ruby(name, *versions) ⇒ Object Also known as: require_ruby, requires_rubys, require_rubys

The ruby version requirement. Each call to this method adds a platform that can be used, and the versions that are required for that platform. :all represents all platforms.

Parameters:

  • name (Symbol)

    the name of the platform, such as :jruby or :mri.

  • versions (String)

    the versions of that platform that this star is compatible with.

See Also:

  • Gem::Requirement


63
64
65
66
67
68
69
70
71
72
# File 'lib/nova/common/metadata/data.rb', line 63

[:ruby, :platform, :star].each do |type|
  define_method(:"requires_#{type}") do |p, *versions|
    data[:"#{type}s"].push(:name => p, :version =>
      Gem::Requirement.new(*[versions].flatten))
  end

  alias_method :"require_#{type}", :"requires_#{type}"
  alias_method :"requires_#{type}s", :"requires_#{type}"
  alias_method :"require_#{type}s", :"requires_#{type}"
end

#requires_star(name, *versions) ⇒ Object Also known as: require_star, requires_stars, require_stars

Requires stars. Uses the given name as the star name.

Parameters:

  • name (Symbol)

    the name of the star.

  • versions (String)

    the versions of that star that are compatible with this star.

See Also:

  • Gem::Requirement


63
64
65
66
67
68
69
70
71
72
# File 'lib/nova/common/metadata/data.rb', line 63

[:ruby, :platform, :star].each do |type|
  define_method(:"requires_#{type}") do |p, *versions|
    data[:"#{type}s"].push(:name => p, :version =>
      Gem::Requirement.new(*[versions].flatten))
  end

  alias_method :"require_#{type}", :"requires_#{type}"
  alias_method :"requires_#{type}s", :"requires_#{type}"
  alias_method :"require_#{type}s", :"requires_#{type}"
end

#validate!(remote) ⇒ void

This method returns an undefined value.

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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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) ⇒ void

This method returns an undefined value.

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



123
124
125
126
127
128
129
130
# 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) ⇒ void

This method returns an undefined value.

Sets the version of the current star.

Parameters:

  • version (String)

    the version of the star.

See Also:

  • Gem::Version


91
92
93
# File 'lib/nova/common/metadata/data.rb', line 91

def version=(version)
  data[:version] = Gem::Version.new(version)
end