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. - .parse_array(array) ⇒ Object private
- .parse_hash(data) ⇒ Object private
- .parse_string(string) ⇒ Object private
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.
-
#initialize(name, specifics = {}) ⇒ Requirement
constructor
private
Create new instance of Requirement.
- #initialize_attributes ⇒ Object private
-
#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, #store, #to_yaml, #validate
Constructor Details
#initialize(name, specifics = {}) ⇒ Requirement (private)
Create new instance of Requirement.
102 103 104 105 |
# File 'lib/indexer/components/requirement.rb', line 102 def initialize(name, specifics={}) specifics[:name] = name super(specifics) end |
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.
279 280 281 |
# File 'lib/indexer/components/requirement.rb', line 279 def platforms @platforms end |
#repository ⇒ Object Also known as: repo
The public repository resource in which the requirement source code can be found.
299 300 301 |
# File 'lib/indexer/components/requirement.rb', line 299 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.
321 322 323 |
# File 'lib/indexer/components/requirement.rb', line 321 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 |
.parse_array(array) ⇒ Object (private)
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/indexer/components/requirement.rb', line 81 def self.parse_array(array) name, data = *array case data when Hash groups = [] groups << (data.delete('groups') || data.delete(:groups)) groups << (data.delete('group') || data.delete(:group)) groups = groups.flatten.compact.map{ |g| g.to_s } data[:groups] = groups new(name.to_s, data) when String parse_string(name + " " + data) else raise(ValidationError, "requirement") end end |
.parse_hash(data) ⇒ Object (private)
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/indexer/components/requirement.rb', line 32 def self.parse_hash(data) name = (data.delete('name') || data.delete(:name)).to_s # make sure groups are strings groups = [] groups << (data.delete('groups') || data.delete(:groups)) groups << (data.delete('group') || data.delete(:group)) groups = groups.flatten.compact.map{ |g| g.to_s } data[:groups] = groups # new(name, data) end |
.parse_string(string) ⇒ Object (private)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/indexer/components/requirement.rb', line 46 def self.parse_string(string) case string.strip when /^(\w.*?)\s+(.*?)\s*\((.*?)\)$/ name = $1 version = $2 groups = $3 when /^(\w.*?)\s+(.*?)$/ name = $1 version = $2 groups = nil when /^(\w.*?)$/ name = $1 version = nil groups = nil else raise(ValidationError, "requirement") end version = nil if version.to_s.strip.empty? groups = groups.split(/\s*[,;]?\s+/) if groups specifics = {} specifics['version'] = version if version specifics['groups'] = groups if groups if groups && !groups.empty? && !groups.include?('runtime') specifics['development'] = true end new(name, specifics) 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 |
#initialize_attributes ⇒ Object (private)
108 109 110 111 112 113 114 115 |
# File 'lib/indexer/components/requirement.rb', line 108 def initialize_attributes @data = { :groups => [], :engines => [], :platforms => [], :sources => [] } 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.
333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/indexer/components/requirement.rb', line 333 def to_h h = super h['version'] = version.to_s if version h['repository'] = repository.to_h if repository h['engines'] = engines.map{ |e| e.to_h } 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 |