Class: Nova::Common::Metadata::Data
- Inherits:
-
Object
- Object
- Nova::Common::Metadata::Data
- 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
-
#data ⇒ Hash<Symbol, Object>
readonly
The data contained in this class.
Instance Method Summary collapse
-
#initialize ⇒ Data
constructor
Initialize the data class.
-
#requires_option(*options) ⇒ void
(also: #requires_options, #require_option)
The options that are required by this star.
-
#requires_platform(name, *versions) ⇒ void
(also: #require_platform, #requires_platforms, #require_platforms)
The platform version requirement.
-
#requires_ruby(name, *versions) ⇒ Object
(also: #require_ruby, #requires_rubys, #require_rubys)
The ruby version requirement.
-
#requires_star(name, *versions) ⇒ Object
(also: #require_star, #requires_stars, #require_stars)
Requires stars.
-
#validate!(remote) ⇒ void
Validates the current platform, to make sure that the running ruby version and the platform name and version match those required by this star.
-
#validate_options!(options) ⇒ void
Validates the given options, making sure that the options contain the required options for the star.
-
#version=(version) ⇒ void
Sets the version of the current star.
Constructor Details
#initialize ⇒ Data
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
#data ⇒ Hash<Symbol, Object> (readonly)
The data contained in this class.
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.
78 79 80 |
# File 'lib/nova/common/metadata/data.rb', line 78 def requires_option(*) data[:required_options].push(*[].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.
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.
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.
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 () keys = .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.
91 92 93 |
# File 'lib/nova/common/metadata/data.rb', line 91 def version=(version) data[:version] = Gem::Version.new(version) end |