Class: Fig::PackageDescriptor
- Inherits:
-
Object
- Object
- Fig::PackageDescriptor
- Includes:
- Comparable
- Defined in:
- lib/fig/package_descriptor.rb
Overview
Parsed representation of a package specification, i.e. “name/version:config”.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#original_string ⇒ Object
readonly
Returns the value of attribute original_string.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
- .format(name, version, config, use_default_config = false) ⇒ Object
- .parse(raw_string, options = {}) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(name, version, config, options = {}) ⇒ PackageDescriptor
constructor
Options are:.
-
#to_string(use_default_config = false) ⇒ Object
Specifically not named :to_s because it doesn’t act like that should.
Constructor Details
#initialize(name, version, config, options = {}) ⇒ PackageDescriptor
Options are:
:name => { :required | :forbidden }
:version => { :required | :forbidden }
:config => { :required | :forbidden }
:original_string => the unparsed form
:require_at_least_one_component => should we have at least one of
name, version, and config
:validation_context => what the descriptor is for
:source_description => where the descriptor came from,
most likely the result of invoking
Fig::Statement.position_description().
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fig/package_descriptor.rb', line 58 def initialize(name, version, config, = {}) @name = name @version = version @config = config @original_string = [:original_string] validate_component name, 'name', :name, validate_component version, 'version', :version, validate_component config, 'config', :config, validate_name validate_across_components end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/fig/package_descriptor.rb', line 9 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/fig/package_descriptor.rb', line 9 def name @name end |
#original_string ⇒ Object (readonly)
Returns the value of attribute original_string.
9 10 11 |
# File 'lib/fig/package_descriptor.rb', line 9 def original_string @original_string end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/fig/package_descriptor.rb', line 9 def version @version end |
Class Method Details
.format(name, version, config, use_default_config = false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fig/package_descriptor.rb', line 11 def self.format(name, version, config, use_default_config = false) string = name || '' if version string += '/' string += version end if config string += ':' string += config elsif use_default_config string += ':default' end return string end |
.parse(raw_string, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fig/package_descriptor.rb', line 29 def self.parse(raw_string, = {}) = {} .merge!() [:original_string] = raw_string [:require_at_least_one_component] = true # Additional checks in validate_component() will take care of the looseness # of the regexes. These just need to ensure that the entire string gets # assigned to one component or another. return self.new( raw_string =~ %r< \A ( [^:/]+ ) >x ? $1 : nil, raw_string =~ %r< \A [^/]* / ( [^:]+ ) >x ? $1 : nil, raw_string =~ %r< \A [^:]* : ( .+ ) \z >x ? $1 : nil, ) end |
Instance Method Details
#<=>(other) ⇒ Object
78 79 80 |
# File 'lib/fig/package_descriptor.rb', line 78 def <=>(other) return to_string() <=> other.to_string() end |
#to_string(use_default_config = false) ⇒ Object
Specifically not named :to_s because it doesn’t act like that should.
72 73 74 75 76 |
# File 'lib/fig/package_descriptor.rb', line 72 def to_string(use_default_config = false) return Fig::PackageDescriptor.format( @name, @version, @config, use_default_config ) end |