Class: Indexer::Requirement
- Defined in:
- lib/indexer/components/requirement.rb
Overview
Requirement class.
QUESTION: Does Requirement really need to handle multiple version constraints? Currently this only supports one version constraint.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#engines ⇒ Array
(also: #engine)
Applies only for specified Ruby engines.
-
#groups ⇒ Array
(also: #group)
The groups to which the requirement belongs.
-
#name ⇒ Object
Returns the value of attribute name.
-
#platforms ⇒ Object
(also: #platform)
Returns the value of attribute platforms.
-
#repository ⇒ Object
(also: #repo)
The public repository resource in which the requirement source code can be found.
-
#sources ⇒ Object
Places from which the requirement can be obtained.
-
#version ⇒ Version::Constraint
The requirement’s version constraint.
Class Method Summary collapse
-
.parse(data) ⇒ Object
Parse ‘data` into a Requirement instance.
Instance Method Summary collapse
-
#development=(boolean) ⇒ Object
Set the requirement’s development flag.
-
#development? ⇒ Boolean
Returns true if the requirement is a development requirement.
-
#external=(boolean) ⇒ Object
Set external.
-
#external? ⇒ Boolean
Is the requirment external? An external requirement is one that is only available outside the expected packaging system.
-
#optional=(boolean) ⇒ Object
Set optional.
-
#optional? ⇒ Boolean
Is the requirment optional? An optional requirement is recommended but not strictly necessary.
-
#runtime? ⇒ Boolean
Return ‘true` if requirement is a runtime requirement.
-
#to_h ⇒ Object
Convert to canonical hash.
Methods inherited from Model
#[], #[]=, attr_reader, attr_writer, #key?, #merge!, #method_missing, #to_yaml
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Indexer::Model
Instance Attribute Details
#engines ⇒ Array Also known as: engine
Applies only for specified Ruby engines. Each entry can be the ‘RUBY_ENGINE` value and optionally a version constraint on `RUBY_VERSION`.
243 244 245 |
# File 'lib/indexer/components/requirement.rb', line 243 def engines @engines end |
#groups ⇒ Array Also known as: group
The groups to which the requirement belongs.
179 180 181 |
# File 'lib/indexer/components/requirement.rb', line 179 def groups @groups end |
#name ⇒ Object
Returns the value of attribute name.
121 122 123 |
# File 'lib/indexer/components/requirement.rb', line 121 def name @name end |
#platforms ⇒ Object Also known as: platform
Returns the value of attribute platforms.
278 279 280 |
# File 'lib/indexer/components/requirement.rb', line 278 def platforms @platforms end |
#repository ⇒ Object Also known as: repo
The public repository resource in which the requirement source code can be found.
298 299 300 |
# File 'lib/indexer/components/requirement.rb', line 298 def repository @repository end |
#sources ⇒ Object
Places from which the requirement can be obtained. Generally a source should be a URI, but there is no strict requirement. It can be as simple as a name, e.g. ‘rubygems` or as specific as a URL to a downloadable `.zip` package.
320 321 322 |
# File 'lib/indexer/components/requirement.rb', line 320 def sources @sources end |
#version ⇒ Version::Constraint
The requirement’s version constraint.
134 135 136 |
# File 'lib/indexer/components/requirement.rb', line 134 def version @version end |
Class Method Details
.parse(data) ⇒ Object
Parse ‘data` into a Requirement instance.
TODO: What about respond_to?(:to_str) for String, etc.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/indexer/components/requirement.rb', line 15 def self.parse(data) case data when String parse_string(data) when Array parse_array(data) when Hash parse_hash(data) else raise(ValidationError, "requirement") end end |
Instance Method Details
#development=(boolean) ⇒ Object
Set the requirement’s development flag.
162 163 164 |
# File 'lib/indexer/components/requirement.rb', line 162 def development=(boolean) @data[:development] = !!boolean end |
#development? ⇒ Boolean
Returns true if the requirement is a development requirement.
153 154 155 |
# File 'lib/indexer/components/requirement.rb', line 153 def development? @data[:development] end |
#external=(boolean) ⇒ Object
Set external.
232 233 234 |
# File 'lib/indexer/components/requirement.rb', line 232 def external=(boolean) @data[:external] = !!boolean end |
#external? ⇒ Boolean
Is the requirment external? An external requirement is one that is only available outside the expected packaging system. For a Ruby application, for example, this would be library not available via rubygems.org, such as a C library that is only avaialble via an operating system’s package manager or via a direct download using the “make; make install” compile and installation procedure.
223 224 225 |
# File 'lib/indexer/components/requirement.rb', line 223 def external? @data[:external] end |
#optional=(boolean) ⇒ Object
Set optional.
210 211 212 |
# File 'lib/indexer/components/requirement.rb', line 210 def optional=(boolean) @data[:optional] = !!boolean end |
#optional? ⇒ Boolean
Is the requirment optional? An optional requirement is recommended but not strictly necessary.
201 202 203 |
# File 'lib/indexer/components/requirement.rb', line 201 def optional? @data[:optional] end |
#runtime? ⇒ Boolean
Return ‘true` if requirement is a runtime requirement.
170 171 172 |
# File 'lib/indexer/components/requirement.rb', line 170 def runtime? ! @data[:development] end |
#to_h ⇒ Object
Convert to canonical hash.
332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/indexer/components/requirement.rb', line 332 def to_h h = super h['version'] = version.to_s if version h['repository'] = repository.to_h if repository h.delete('groups') if h['groups'] && h['groups'].empty? h.delete('engines') if h['engines'] && h['engines'].empty? h.delete('platforms') if h['platforms'] && h['platforms'].empty? h.delete('sources') if h['sources'] && h['sources'].empty? h end |